Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2092)

Unified Diff: net/base/capturing_net_log.h

Issue 16137008: Refactor net::NetLog to provide implementation of observer pattern, not just the interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/capturing_net_log.h
diff --git a/net/base/capturing_net_log.h b/net/base/capturing_net_log.h
index d3586d1d44f51642f92af0a424c564193607303e..154e5f4baab173ee90c7dca02cbe3ec212279d48 100644
--- a/net/base/capturing_net_log.h
+++ b/net/base/capturing_net_log.h
@@ -23,16 +23,16 @@ class DictionaryValue;
namespace net {
-// CapturingNetLog is an implementation of NetLog that saves messages to a
-// bounded buffer. It is intended for testing only, and is part of the
-// net_test_support project.
-class CapturingNetLog : public NetLog {
+// CapturingNetLogObserver is an implementation of NetLog::ThreadSafeObserver
+// that saves messages to a bounded buffer. It is intended for testing only,
+// and is part of the net_test_support project.
+class CapturingNetLogObserver : public NetLog::ThreadSafeObserver {
public:
struct CapturedEntry {
- CapturedEntry(EventType type,
+ CapturedEntry(NetLog::EventType type,
const base::TimeTicks& time,
- Source source,
- EventPhase phase,
+ NetLog::Source source,
+ NetLog::EventPhase phase,
scoped_ptr<base::DictionaryValue> params);
// Copy constructor needed to store in a std::vector because of the
// scoped_ptr.
@@ -58,18 +58,18 @@ class CapturingNetLog : public NetLog {
// parameters.
std::string GetParamsJson() const;
- EventType type;
+ NetLog::EventType type;
base::TimeTicks time;
- Source source;
- EventPhase phase;
+ NetLog::Source source;
+ NetLog::EventPhase phase;
scoped_ptr<base::DictionaryValue> params;
};
// Ordered set of entries that were logged.
typedef std::vector<CapturedEntry> CapturedEntryList;
- CapturingNetLog();
- virtual ~CapturingNetLog();
+ CapturingNetLogObserver();
+ virtual ~CapturingNetLogObserver();
// Returns the list of all entries in the log.
void GetEntries(CapturedEntryList* entry_list) const;
@@ -83,34 +83,45 @@ class CapturingNetLog : public NetLog {
void Clear();
- void SetLogLevel(NetLog::LogLevel log_level);
-
- // NetLog implementation:
- virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
- virtual uint32 NextID() OVERRIDE;
- virtual LogLevel GetLogLevel() const OVERRIDE;
- virtual void AddThreadSafeObserver(ThreadSafeObserver* observer,
- LogLevel log_level) OVERRIDE;
- virtual void SetObserverLogLevel(ThreadSafeObserver* observer,
- LogLevel log_level) OVERRIDE;
- virtual void RemoveThreadSafeObserver(ThreadSafeObserver* observer) OVERRIDE;
-
private:
+ // NetLog::ThreadSafeObserver implementation:
+ virtual void OnAddEntry(const NetLog::Entry& entry) OVERRIDE;
+
// Needs to be "mutable" so can use it in GetEntries().
mutable base::Lock lock_;
- // Last assigned source ID. Incremented to get the next one.
- base::subtle::Atomic32 last_id_;
-
CapturedEntryList captured_entries_;
- NetLog::LogLevel log_level_;
+ DISALLOW_COPY_AND_ASSIGN(CapturingNetLogObserver);
+};
- DISALLOW_COPY_AND_ASSIGN(CapturingNetLog);
+// CapturingNetLog is a NetLog which instantiates CapturingNetLogObserver.
+// This is provided for compatilbility with old unittests.
mmenke 2013/06/03 14:27:09 I'd say this is more a convenience wrapper, like C
kouhei (in TOK) 2013/06/04 15:41:44 As some unittests require accessing the observer d
mmenke 2013/06/04 16:55:47 The unit tests don't need to directly access them
kouhei (in TOK) 2013/06/04 22:19:30 Sorry I misunderstood the last comment. I mixed it
+class CapturingNetLog : public NetLog {
+ public:
+ typedef CapturingNetLogObserver::CapturedEntry CapturedEntry;
+ typedef CapturingNetLogObserver::CapturedEntryList CapturedEntryList;
+
+ CapturingNetLog();
+ virtual ~CapturingNetLog();
+
+ void SetLogLevel(NetLog::LogLevel log_level);
+
+ CapturingNetLogObserver& observer() { return capturing_net_log_observer_; }
+ const CapturingNetLogObserver& observer() const {
+ return capturing_net_log_observer_;
+ }
+
+ // below methods are forwarded to capturing_net_log_observer_
mmenke 2013/06/03 14:27:09 Nit: Capitalize + period.
kouhei (in TOK) 2013/06/04 15:41:44 Done.
+ void GetEntries(CapturingNetLogObserver::CapturedEntryList* entry_list) const;
+ size_t GetSize() const;
+
+ private:
+ CapturingNetLogObserver capturing_net_log_observer_;
};
// Helper class that exposes a similar API as BoundNetLog, but uses a
-// CapturingNetLog rather than the more generic NetLog.
+// CapturingNetLogObserver rather than the more generic NetLog.
//
// CapturingBoundNetLog can easily be converted to a BoundNetLog using the
// bound() method.
@@ -120,27 +131,27 @@ class CapturingBoundNetLog {
~CapturingBoundNetLog();
// The returned BoundNetLog is only valid while |this| is alive.
- BoundNetLog bound() const { return net_log_; }
+ BoundNetLog bound() const { return bound_net_log_; }
// Fills |entry_list| with all entries in the log.
- void GetEntries(CapturingNetLog::CapturedEntryList* entry_list) const;
+ void GetEntries(CapturingNetLogObserver::CapturedEntryList* entry_list) const;
// Fills |entry_list| with all entries in the log from the specified Source.
void GetEntriesForSource(
NetLog::Source source,
- CapturingNetLog::CapturedEntryList* entry_list) const;
+ CapturingNetLogObserver::CapturedEntryList* entry_list) const;
// Returns number of entries in the log.
size_t GetSize() const;
void Clear();
- // Sets the log level of the underlying CapturingNetLog.
+ // Sets the log level of the underlying CapturingNetLogObserver.
void SetLogLevel(NetLog::LogLevel log_level);
private:
- CapturingNetLog capturing_net_log_;
- const BoundNetLog net_log_;
+ CapturingNetLog net_log_;
+ const BoundNetLog bound_net_log_;
DISALLOW_COPY_AND_ASSIGN(CapturingBoundNetLog);
};

Powered by Google App Engine
This is Rietveld 408576698