Main benefits of NetLog inner classes extraction:
- Greater code organization.
- Promotion of files being "include-what-you-use" clean. Less files now need
to include "net_log.h"; these files are no longer susceptible to having their
includes hidden by the many inner includes of "net_log.h".
- All touched files are also now forward-clean re: NetLog,
NetLogCaptureMode and the new, extracted classes.
Here is the new structuring:
- NetLogSource (net_log_source.h/.cc)
- NetLogEntry, NetLogEntryData (net_log_entry.h/.cc)
- NetLogWithSource (net_log_with_source.h/.cc)
***Did not extract NetLog::ThreadSafeObserver into its own class since
NetLog::ThreadSafeObserver and NetLog are interrelated enough to keep
NetLog::ThreadSafeObserver as an inner class.
Further Notes:
1) On top of scripting, all files were checked manually, ensuring:
- Forwards/including added only when appropriate. No extras added.
- "net_log.h" include removals done correctly. No "net_log.h"-hiding
to occur as a result of new changes.
2) Just as any .cc file will not do the include/forward if the paired .h file
already has the include/forward, *_unittests.cc, *_browsertest.cc and
*_test.cc files exhibit the same behavior when they have a paired .h file.
3) Override methods' types do not add to logic for inserting forwards, since it
is guaranteed that the base class has the forward.
- Saw this done in codebase several times, so making sure to
follow the same rule.
4) A big change was the mass adjustment for the include-hiding of
NetLogCaptureMode by net_log.h includes. Now the NetLogCaptureMode class is
being properly forwarded/included in all files changed by the original
NetLog inner classes extraction work.
5) Many NetLog/NetLogWithSource includes/forwards were added across codebase.
All instances of files seeing their NetLog/NetLogWithSource include/forward
being hidden by their own includes should now be gone. This is to promote
greater flexibility in future changes upon the codebase.
BUG=473710
[email protected],[email protected]
[email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Review-Url: https://codereview.chromium.org/2333923004
Cr-Commit-Position: refs/heads/master@{#422691}
diff --git a/net/log/net_log_entry.cc b/net/log/net_log_entry.cc
new file mode 100644
index 0000000..1258139
--- /dev/null
+++ b/net/log/net_log_entry.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/log/net_log_entry.h"
+
+#include <utility>
+
+#include "base/callback.h"
+#include "base/values.h"
+#include "net/log/net_log.h"
+
+namespace net {
+
+std::unique_ptr<base::Value> NetLogEntry::ToValue() const {
+ std::unique_ptr<base::DictionaryValue> entry_dict(
+ new base::DictionaryValue());
+
+ entry_dict->SetString("time", NetLog::TickCountToString(data_->time));
+
+ // Set the entry source.
+ std::unique_ptr<base::DictionaryValue> source_dict(
+ new base::DictionaryValue());
+ source_dict->SetInteger("id", data_->source.id);
+ source_dict->SetInteger("type", static_cast<int>(data_->source.type));
+ entry_dict->Set("source", std::move(source_dict));
+
+ // Set the event info.
+ entry_dict->SetInteger("type", static_cast<int>(data_->type));
+ entry_dict->SetInteger("phase", static_cast<int>(data_->phase));
+
+ // Set the event-specific parameters.
+ if (data_->parameters_callback) {
+ std::unique_ptr<base::Value> value(
+ data_->parameters_callback->Run(capture_mode_));
+ if (value)
+ entry_dict->Set("params", std::move(value));
+ }
+
+ return std::move(entry_dict);
+}
+
+std::unique_ptr<base::Value> NetLogEntry::ParametersToValue() const {
+ if (data_->parameters_callback)
+ return data_->parameters_callback->Run(capture_mode_);
+ return nullptr;
+}
+
+NetLogEntryData::NetLogEntryData(
+ NetLogEventType type,
+ NetLogSource source,
+ NetLogEventPhase phase,
+ base::TimeTicks time,
+ const NetLogParametersCallback* parameters_callback)
+ : type(type),
+ source(source),
+ phase(phase),
+ time(time),
+ parameters_callback(parameters_callback) {}
+
+NetLogEntryData::~NetLogEntryData() {}
+
+NetLogEntry::NetLogEntry(const NetLogEntryData* data,
+ NetLogCaptureMode capture_mode)
+ : data_(data), capture_mode_(capture_mode) {}
+
+NetLogEntry::~NetLogEntry() {}
+
+} // namespace net