diff options
Diffstat (limited to 'net/tools/gdig')
-rw-r--r-- | net/tools/gdig/file_net_log.cc | 40 | ||||
-rw-r--r-- | net/tools/gdig/file_net_log.h | 26 | ||||
-rw-r--r-- | net/tools/gdig/gdig.cc | 13 |
3 files changed, 25 insertions, 54 deletions
diff --git a/net/tools/gdig/file_net_log.cc b/net/tools/gdig/file_net_log.cc index 51cf78d..7c755c8 100644 --- a/net/tools/gdig/file_net_log.cc +++ b/net/tools/gdig/file_net_log.cc @@ -12,24 +12,20 @@ namespace net { -FileNetLog::FileNetLog(FILE* destination, LogLevel level) - : log_level_(level), - destination_(destination) { +FileNetLogObserver::FileNetLogObserver(FILE* destination) + : destination_(destination) { DCHECK(destination != NULL); - // Without calling GetNext() once here, the first GetNext will return 0 - // that is not a valid id. - sequence_number_.GetNext(); } -FileNetLog::~FileNetLog() { +FileNetLogObserver::~FileNetLogObserver() { } -void FileNetLog::OnAddEntry(const net::NetLog::Entry& entry) { +void FileNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { // Only BoundNetLogs without a NetLog should have an invalid source. DCHECK(entry.source().IsValid()); - const char* source = SourceTypeToString(entry.source().type); - const char* type = EventTypeToString(entry.type()); + const char* source = NetLog::SourceTypeToString(entry.source().type); + const char* type = NetLog::EventTypeToString(entry.type()); scoped_ptr<Value> param_value(entry.ParametersToValue()); std::string params; @@ -49,28 +45,4 @@ void FileNetLog::OnAddEntry(const net::NetLog::Entry& entry) { entry.source().id, source, type, params.c_str()); } -uint32 FileNetLog::NextID() { - return sequence_number_.GetNext(); -} - -NetLog::LogLevel FileNetLog::GetLogLevel() const { - return log_level_; -} - -void FileNetLog::AddThreadSafeObserver( - NetLog::ThreadSafeObserver* observer, - NetLog::LogLevel log_level) { - NOTIMPLEMENTED() << "Not currently used by gdig."; -} - -void FileNetLog::SetObserverLogLevel(ThreadSafeObserver* observer, - LogLevel log_level) { - NOTIMPLEMENTED() << "Not currently used by gdig."; -} - -void FileNetLog::RemoveThreadSafeObserver( - NetLog::ThreadSafeObserver* observer) { - NOTIMPLEMENTED() << "Not currently used by gdig."; -} - } // namespace net diff --git a/net/tools/gdig/file_net_log.h b/net/tools/gdig/file_net_log.h index cb80380..1ad78f1 100644 --- a/net/tools/gdig/file_net_log.h +++ b/net/tools/gdig/file_net_log.h @@ -7,7 +7,6 @@ #include <string> -#include "base/atomic_sequence_num.h" #include "base/basictypes.h" #include "base/synchronization/lock.h" #include "base/time.h" @@ -15,27 +14,18 @@ namespace net { -// FileNetLog is a simple implementation of NetLog that prints out all -// the events received into the stream passed to the constructor. -class FileNetLog : public NetLog { +// FileNetLogObserver is a simple implementation of NetLog::ThreadSafeObserver +// that prints out all the events received into the stream passed +// to the constructor. +class FileNetLogObserver : public NetLog::ThreadSafeObserver { public: - explicit FileNetLog(FILE* destination, LogLevel level); - virtual ~FileNetLog(); + explicit FileNetLogObserver(FILE* destination); + virtual ~FileNetLogObserver(); - private: - // NetLog implementation: + // NetLog::ThreadSafeObserver 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; - - base::AtomicSequenceNumber sequence_number_; - const NetLog::LogLevel log_level_; + private: FILE* const destination_; base::Lock lock_; diff --git a/net/tools/gdig/gdig.cc b/net/tools/gdig/gdig.cc index 1640408..7cbb9a4 100644 --- a/net/tools/gdig/gdig.cc +++ b/net/tools/gdig/gdig.cc @@ -182,6 +182,7 @@ bool LoadReplayLog(const base::FilePath& file_path, ReplayLog* replay_log) { class GDig { public: GDig(); + ~GDig(); enum Result { RESULT_NO_RESOLVE = -3, @@ -219,7 +220,8 @@ class GDig { base::CancelableClosure timeout_closure_; scoped_ptr<DnsConfigService> dns_config_service_; - scoped_ptr<FileNetLog> log_; + scoped_ptr<FileNetLogObserver> log_observer_; + scoped_ptr<NetLog> log_; scoped_ptr<HostResolver> resolver_; }; @@ -232,6 +234,11 @@ GDig::GDig() active_resolves_(0) { } +GDig::~GDig() { + if (log_) + log_->RemoveThreadSafeObserver(log_observer_.get()); +} + GDig::Result GDig::Main(int argc, const char* argv[]) { if (!ParseCommandLine(argc, argv)) { fprintf(stderr, @@ -299,7 +306,9 @@ bool GDig::ParseCommandLine(int argc, const char* argv[]) { return false; } } - log_.reset(new FileNetLog(stderr, level)); + log_.reset(new NetLog); + log_observer_.reset(new FileNetLogObserver(stderr)); + log_->AddThreadSafeObserver(log_observer_.get(), level); } print_config_ = parsed_command_line.HasSwitch("print_config"); |