Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "chrome/browser/extensions/api/log_private/filter_handler.h" | 12 #include "chrome/browser/extensions/api/log_private/filter_handler.h" |
| 13 #include "chrome/browser/extensions/api/log_private/log_parser.h" | 13 #include "chrome/browser/extensions/api/log_private/log_parser.h" |
| 14 #include "chrome/browser/extensions/chrome_extension_function.h" | 14 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 15 #include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" | 15 #include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" |
| 16 #include "chrome/common/extensions/api/log_private.h" | 16 #include "chrome/common/extensions/api/log_private.h" |
| 17 #include "extensions/browser/browser_context_keyed_api_factory.h" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 18 #include "extensions/browser/extension_registry_observer.h" | 18 #include "extensions/browser/extension_registry_observer.h" |
| 19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
| 20 #include "net/base/net_log_logger.h" | |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class BrowserContext; | 23 class BrowserContext; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace extensions { | 26 namespace extensions { |
| 26 class ExtensionRegistry; | 27 class ExtensionRegistry; |
| 27 | 28 |
| 28 class LogPrivateAPI : public BrowserContextKeyedAPI, | 29 class LogPrivateAPI : public BrowserContextKeyedAPI, |
| 29 public ExtensionRegistryObserver, | 30 public ExtensionRegistryObserver, |
| 30 public net::NetLog::ThreadSafeObserver { | 31 public net::NetLog::ThreadSafeObserver { |
| 31 public: | 32 public: |
| 33 typedef enum { | |
|
Zachary Kuznia
2014/06/25 00:05:53
Is there a reason to typedef this, instead of usin
zel
2014/06/27 19:31:01
Done.
| |
| 34 REPORT_EVENTS_TO_EXTENSION, | |
| 35 RECORD_EVENTS_TO_FILE, | |
| 36 } CapturedEventsSink; | |
| 37 | |
| 32 // Convenience method to get the LogPrivateAPI for a profile. | 38 // Convenience method to get the LogPrivateAPI for a profile. |
| 33 static LogPrivateAPI* Get(content::BrowserContext* context); | 39 static LogPrivateAPI* Get(content::BrowserContext* context); |
| 34 | 40 |
| 35 explicit LogPrivateAPI(content::BrowserContext* context); | 41 explicit LogPrivateAPI(content::BrowserContext* context); |
| 36 virtual ~LogPrivateAPI(); | 42 virtual ~LogPrivateAPI(); |
| 37 | 43 |
| 38 void StartNetInternalsWatch(const std::string& extension_id); | 44 void StartNetInternalsWatch(const std::string& extension_id, |
| 39 void StopNetInternalsWatch(const std::string& extension_id); | 45 CapturedEventsSink event_sink); |
| 46 void StopNetInternalsWatch(const std::string& extension_id, | |
| 47 const base::Closure& closure); | |
| 48 void StopAllWatches(const std::string& extension_id, | |
| 49 const base::Closure& closure); | |
| 40 | 50 |
| 41 // BrowserContextKeyedAPI implementation. | 51 // BrowserContextKeyedAPI implementation. |
| 42 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); | 52 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); |
| 43 | 53 |
| 44 private: | 54 private: |
| 45 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; | 55 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; |
| 46 | 56 |
| 47 // ExtensionRegistryObserver implementation. | 57 // ExtensionRegistryObserver implementation. |
| 48 virtual void OnExtensionUnloaded( | 58 virtual void OnExtensionUnloaded( |
| 49 content::BrowserContext* browser_context, | 59 content::BrowserContext* browser_context, |
| 50 const Extension* extension, | 60 const Extension* extension, |
| 51 UnloadedExtensionInfo::Reason reason) OVERRIDE; | 61 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 52 | 62 |
| 53 // ChromeNetLog::ThreadSafeObserver implementation: | 63 // ChromeNetLog::ThreadSafeObserver implementation: |
| 54 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | 64 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; |
| 55 | 65 |
| 56 void PostPendingEntries(); | 66 void PostPendingEntries(); |
| 57 void AddEntriesOnUI(scoped_ptr<base::ListValue> value); | 67 void AddEntriesOnUI(scoped_ptr<base::ListValue> value); |
| 58 | 68 |
| 59 void MaybeStartNetInternalLogging(); | 69 void MaybeStartNetInternalLogging(CapturedEventsSink event_sink); |
| 60 void MaybeStopNetInternalLogging(); | 70 void MaybeStopNetInternalLogging(const base::Closure& closure); |
| 61 void StopNetInternalLogging(); | 71 void StopNetInternalLogging(); |
| 62 | 72 |
| 63 // BrowserContextKeyedAPI implementation. | 73 // BrowserContextKeyedAPI implementation. |
| 64 static const char* service_name() { | 74 static const char* service_name() { |
| 65 return "LogPrivateAPI"; | 75 return "LogPrivateAPI"; |
| 66 } | 76 } |
| 67 static const bool kServiceIsNULLWhileTesting = true; | 77 static const bool kServiceIsNULLWhileTesting = true; |
| 68 static const bool kServiceRedirectedInIncognito = true; | 78 static const bool kServiceRedirectedInIncognito = true; |
| 69 | 79 |
| 70 content::BrowserContext* const browser_context_; | 80 content::BrowserContext* const browser_context_; |
| 71 bool logging_net_internals_; | 81 bool logging_net_internals_; |
| 82 CapturedEventsSink event_sink_; | |
| 72 std::set<std::string> net_internal_watches_; | 83 std::set<std::string> net_internal_watches_; |
| 73 scoped_ptr<base::ListValue> pending_entries_; | 84 scoped_ptr<base::ListValue> pending_entries_; |
| 85 scoped_ptr<net::NetLogLogger> net_log_logger_; | |
| 74 | 86 |
| 75 // Listen to extension unloaded notifications. | 87 // Listen to extension unloaded notifications. |
| 76 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 88 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 77 extension_registry_observer_; | 89 extension_registry_observer_; |
| 78 }; | 90 }; |
| 79 | 91 |
| 80 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { | 92 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { |
| 81 public: | 93 public: |
| 82 LogPrivateGetHistoricalFunction(); | 94 LogPrivateGetHistoricalFunction(); |
| 83 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical", | 95 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical", |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 LOGPRIVATE_STOPNETINTERNALSWATCH); | 130 LOGPRIVATE_STOPNETINTERNALSWATCH); |
| 119 | 131 |
| 120 protected: | 132 protected: |
| 121 virtual ~LogPrivateStopNetInternalsWatchFunction(); | 133 virtual ~LogPrivateStopNetInternalsWatchFunction(); |
| 122 virtual bool RunSync() OVERRIDE; | 134 virtual bool RunSync() OVERRIDE; |
| 123 | 135 |
| 124 private: | 136 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); | 137 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); |
| 126 }; | 138 }; |
| 127 | 139 |
| 140 | |
| 141 class LogPrivateStartEventRecorderFunction | |
| 142 : public ChromeSyncExtensionFunction { | |
| 143 public: | |
| 144 LogPrivateStartEventRecorderFunction(); | |
| 145 DECLARE_EXTENSION_FUNCTION("logPrivate.startEventRecorder", | |
| 146 LOGPRIVATE_STARTEVENTRECODER); | |
| 147 | |
| 148 protected: | |
| 149 virtual ~LogPrivateStartEventRecorderFunction(); | |
| 150 virtual bool RunSync() OVERRIDE; | |
| 151 | |
| 152 private: | |
| 153 DISALLOW_COPY_AND_ASSIGN(LogPrivateStartEventRecorderFunction); | |
| 154 }; | |
| 155 | |
| 156 class LogPrivateStopEventRecorderFunction | |
| 157 : public ChromeSyncExtensionFunction { | |
| 158 public: | |
| 159 LogPrivateStopEventRecorderFunction(); | |
| 160 DECLARE_EXTENSION_FUNCTION("logPrivate.stopEventRecorder", | |
| 161 LOGPRIVATE_STOPEVENTRECODER); | |
| 162 | |
| 163 protected: | |
| 164 virtual ~LogPrivateStopEventRecorderFunction(); | |
| 165 virtual bool RunSync() OVERRIDE; | |
| 166 | |
| 167 private: | |
| 168 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopEventRecorderFunction); | |
| 169 }; | |
| 170 | |
| 171 class LogPrivateDumpLogsFunction | |
| 172 : public AsyncExtensionFunction { | |
| 173 public: | |
| 174 LogPrivateDumpLogsFunction(); | |
| 175 DECLARE_EXTENSION_FUNCTION("logPrivate.dumpLogs", | |
| 176 LOGPRIVATE_DUMPLOGS); | |
| 177 | |
| 178 protected: | |
| 179 virtual ~LogPrivateDumpLogsFunction(); | |
| 180 | |
| 181 // AsyncExtensionFunction overrides. | |
| 182 virtual bool RunAsync() OVERRIDE; | |
| 183 | |
| 184 private: | |
| 185 // Callback for DebugLogWriter::StoreLogs() call. | |
| 186 void OnStoreLogsCompleted(const base::FilePath& log_path, | |
| 187 bool succeeded); | |
| 188 // Callback for LogPrivateAPI::StopAllWatches() call. | |
| 189 void OnStopAllWatches(); | |
| 190 DISALLOW_COPY_AND_ASSIGN(LogPrivateDumpLogsFunction); | |
| 191 }; | |
| 192 | |
| 193 | |
| 128 } // namespace extensions | 194 } // namespace extensions |
| 129 | 195 |
| 130 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ | 196 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ |
| OLD | NEW |