Index: chrome/browser/extensions/api/log_private/log_private_api.h |
diff --git a/chrome/browser/extensions/api/log_private/log_private_api.h b/chrome/browser/extensions/api/log_private/log_private_api.h |
index 2b6648bcfdd88822b2915f3fb28a6d05e168267a..95181f9df6605414b15c33dc53c4626612772371 100644 |
--- a/chrome/browser/extensions/api/log_private/log_private_api.h |
+++ b/chrome/browser/extensions/api/log_private/log_private_api.h |
@@ -14,9 +14,14 @@ |
#include "chrome/browser/extensions/chrome_extension_function.h" |
#include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" |
#include "chrome/common/extensions/api/log_private.h" |
+#include "extensions/browser/api/api_resource.h" |
+#include "extensions/browser/api/api_resource_manager.h" |
#include "extensions/browser/browser_context_keyed_api_factory.h" |
#include "extensions/browser/extension_registry_observer.h" |
#include "net/base/net_log.h" |
+#include "net/base/net_log_logger.h" |
+ |
+class IOThread; |
namespace content { |
class BrowserContext; |
@@ -25,6 +30,26 @@ class BrowserContext; |
namespace extensions { |
class ExtensionRegistry; |
+// Tracked log files. |
+class FileResource : public ApiResource { |
+ public: |
+ FileResource(const std::string& owner_extension_id, |
+ const base::FilePath& path); |
+ virtual ~FileResource(); |
+ |
+ // ApiResource overrides. |
+ virtual bool IsPersistent() const OVERRIDE; |
+ |
+ static const char kSequenceToken[]; |
+ static const base::SequencedWorkerPool::WorkerShutdown kShutdownBehavior = |
+ base::SequencedWorkerPool::BLOCK_SHUTDOWN; |
+ |
+ private: |
+ base::FilePath path_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FileResource); |
+}; |
+ |
class LogPrivateAPI : public BrowserContextKeyedAPI, |
public ExtensionRegistryObserver, |
public net::NetLog::ThreadSafeObserver { |
@@ -35,8 +60,15 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, |
explicit LogPrivateAPI(content::BrowserContext* context); |
virtual ~LogPrivateAPI(); |
- void StartNetInternalsWatch(const std::string& extension_id); |
- void StopNetInternalsWatch(const std::string& extension_id); |
+ void StartNetInternalsWatch(const std::string& extension_id, |
+ api::log_private::EventSink event_sink, |
+ const base::Closure& closure); |
+ void StopNetInternalsWatch(const std::string& extension_id, |
+ const base::Closure& closure); |
+ void StopAllWatches(const std::string& extension_id, |
+ const base::Closure& closure); |
+ void RegisterTempFile(const std::string& owner_extension_id, |
+ const base::FilePath& file_path); |
// BrowserContextKeyedAPI implementation. |
static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); |
@@ -44,6 +76,7 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, |
private: |
friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; |
+ void Initialize(); |
// ExtensionRegistryObserver implementation. |
virtual void OnExtensionUnloaded( |
content::BrowserContext* browser_context, |
@@ -56,8 +89,18 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, |
void PostPendingEntries(); |
void AddEntriesOnUI(scoped_ptr<base::ListValue> value); |
- void MaybeStartNetInternalLogging(); |
- void MaybeStopNetInternalLogging(); |
+ // Initializes a new instance of net::NetLogLogger and passes it back via |
+ // |net_logger| param. |
+ void InitializeNetLogger(const std::string& owner_extension_id, |
+ net::NetLogLogger** net_logger); |
+ |
+ // Starts observing network events with a new |net_logger| instance. |
+ void StartObservingNetEvents(IOThread* io_thread, |
+ net::NetLogLogger** net_logger); |
+ void MaybeStartNetInternalLogging(const std::string& caller_extension_id, |
+ IOThread* io_thread, |
+ api::log_private::EventSink event_sink); |
+ void MaybeStopNetInternalLogging(const base::Closure& closure); |
void StopNetInternalLogging(); |
// BrowserContextKeyedAPI implementation. |
@@ -69,12 +112,18 @@ class LogPrivateAPI : public BrowserContextKeyedAPI, |
content::BrowserContext* const browser_context_; |
bool logging_net_internals_; |
+ api::log_private::EventSink event_sink_; |
std::set<std::string> net_internal_watches_; |
scoped_ptr<base::ListValue> pending_entries_; |
- |
+ scoped_ptr<net::NetLogLogger> net_log_logger_; |
// Listen to extension unloaded notifications. |
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
extension_registry_observer_; |
+ ApiResourceManager<FileResource, WorkerPoolThreadTraits<FileResource> > |
+ log_file_resources_; |
+ bool initialized_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LogPrivateAPI); |
}; |
class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { |
@@ -95,34 +144,57 @@ class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { |
DISALLOW_COPY_AND_ASSIGN(LogPrivateGetHistoricalFunction); |
}; |
-class LogPrivateStartNetInternalsWatchFunction |
- : public ChromeSyncExtensionFunction { |
+class LogPrivateStartEventRecorderFunction : public AsyncExtensionFunction { |
public: |
- LogPrivateStartNetInternalsWatchFunction(); |
- DECLARE_EXTENSION_FUNCTION("logPrivate.startNetInternalsWatch", |
- LOGPRIVATE_STARTNETINTERNALSWATCH); |
+ LogPrivateStartEventRecorderFunction(); |
+ DECLARE_EXTENSION_FUNCTION("logPrivate.startEventRecorder", |
+ LOGPRIVATE_STARTEVENTRECODER); |
protected: |
- virtual ~LogPrivateStartNetInternalsWatchFunction(); |
- virtual bool RunSync() OVERRIDE; |
+ virtual ~LogPrivateStartEventRecorderFunction(); |
+ virtual bool RunAsync() OVERRIDE; |
private: |
- DISALLOW_COPY_AND_ASSIGN(LogPrivateStartNetInternalsWatchFunction); |
+ void OnEventRecorderStarted(); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LogPrivateStartEventRecorderFunction); |
}; |
-class LogPrivateStopNetInternalsWatchFunction |
- : public ChromeSyncExtensionFunction { |
+class LogPrivateStopEventRecorderFunction : public AsyncExtensionFunction { |
public: |
- LogPrivateStopNetInternalsWatchFunction(); |
- DECLARE_EXTENSION_FUNCTION("logPrivate.stopNetInternalsWatch", |
- LOGPRIVATE_STOPNETINTERNALSWATCH); |
+ LogPrivateStopEventRecorderFunction(); |
+ DECLARE_EXTENSION_FUNCTION("logPrivate.stopEventRecorder", |
+ LOGPRIVATE_STOPEVENTRECODER); |
protected: |
- virtual ~LogPrivateStopNetInternalsWatchFunction(); |
- virtual bool RunSync() OVERRIDE; |
+ virtual ~LogPrivateStopEventRecorderFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunAsync() OVERRIDE; |
+ |
+ private: |
+ void OnEventRecorderStopped(); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(LogPrivateStopEventRecorderFunction); |
+}; |
+ |
+class LogPrivateDumpLogsFunction : public AsyncExtensionFunction { |
+ public: |
+ LogPrivateDumpLogsFunction(); |
+ DECLARE_EXTENSION_FUNCTION("logPrivate.dumpLogs", LOGPRIVATE_DUMPLOGS); |
+ |
+ protected: |
+ virtual ~LogPrivateDumpLogsFunction(); |
+ |
+ // AsyncExtensionFunction overrides. |
+ virtual bool RunAsync() OVERRIDE; |
private: |
- DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); |
+ // Callback for DebugLogWriter::StoreLogs() call. |
+ void OnStoreLogsCompleted(const base::FilePath& log_path, bool succeeded); |
+ // Callback for LogPrivateAPI::StopAllWatches() call. |
+ void OnStopAllWatches(); |
+ DISALLOW_COPY_AND_ASSIGN(LogPrivateDumpLogsFunction); |
}; |
} // namespace extensions |