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

Side by Side Diff: chrome/browser/extensions/api/log_private/log_private_api.h

Issue 329853010: Additional methods for chrome.logPrivate API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 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 unified diff | Download patch
OLDNEW
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/api/api_resource.h"
18 #include "extensions/browser/api/api_resource_manager.h"
17 #include "extensions/browser/browser_context_keyed_api_factory.h" 19 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 #include "extensions/browser/extension_registry_observer.h" 20 #include "extensions/browser/extension_registry_observer.h"
19 #include "net/base/net_log.h" 21 #include "net/base/net_log.h"
22 #include "net/base/net_log_logger.h"
23
24 class IOThread;
20 25
21 namespace content { 26 namespace content {
22 class BrowserContext; 27 class BrowserContext;
23 } 28 }
24 29
25 namespace extensions { 30 namespace extensions {
26 class ExtensionRegistry; 31 class ExtensionRegistry;
27 32
33 // Tracked log files.
34 class FileResource : public ApiResource {
35 public:
36 FileResource(const std::string& owner_extension_id,
37 const base::FilePath& path);
38 virtual ~FileResource();
39
40 // ApiResource overrides.
41 virtual bool IsPersistent() const OVERRIDE;
42
43 static const char kSequenceToken[];
44 static const base::SequencedWorkerPool::WorkerShutdown kShutdownBehavior =
45 base::SequencedWorkerPool::BLOCK_SHUTDOWN;
46
47 private:
48 base::FilePath path_;
49
50 DISALLOW_COPY_AND_ASSIGN(FileResource);
51 };
52
28 class LogPrivateAPI : public BrowserContextKeyedAPI, 53 class LogPrivateAPI : public BrowserContextKeyedAPI,
29 public ExtensionRegistryObserver, 54 public ExtensionRegistryObserver,
30 public net::NetLog::ThreadSafeObserver { 55 public net::NetLog::ThreadSafeObserver {
31 public: 56 public:
32 // Convenience method to get the LogPrivateAPI for a profile. 57 // Convenience method to get the LogPrivateAPI for a profile.
33 static LogPrivateAPI* Get(content::BrowserContext* context); 58 static LogPrivateAPI* Get(content::BrowserContext* context);
34 59
35 explicit LogPrivateAPI(content::BrowserContext* context); 60 explicit LogPrivateAPI(content::BrowserContext* context);
36 virtual ~LogPrivateAPI(); 61 virtual ~LogPrivateAPI();
37 62
38 void StartNetInternalsWatch(const std::string& extension_id); 63 void StartNetInternalsWatch(const std::string& extension_id,
39 void StopNetInternalsWatch(const std::string& extension_id); 64 api::log_private::EventSink event_sink,
65 const base::Closure& closure);
66 void StopNetInternalsWatch(const std::string& extension_id,
67 const base::Closure& closure);
68 void StopAllWatches(const std::string& extension_id,
69 const base::Closure& closure);
70 void RegisterTempFile(const std::string& owner_extension_id,
71 const base::FilePath& file_path);
40 72
41 // BrowserContextKeyedAPI implementation. 73 // BrowserContextKeyedAPI implementation.
42 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); 74 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance();
43 75
44 private: 76 private:
45 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; 77 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>;
46 78
79 void Initialize();
47 // ExtensionRegistryObserver implementation. 80 // ExtensionRegistryObserver implementation.
48 virtual void OnExtensionUnloaded( 81 virtual void OnExtensionUnloaded(
49 content::BrowserContext* browser_context, 82 content::BrowserContext* browser_context,
50 const Extension* extension, 83 const Extension* extension,
51 UnloadedExtensionInfo::Reason reason) OVERRIDE; 84 UnloadedExtensionInfo::Reason reason) OVERRIDE;
52 85
53 // ChromeNetLog::ThreadSafeObserver implementation: 86 // ChromeNetLog::ThreadSafeObserver implementation:
54 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; 87 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE;
55 88
56 void PostPendingEntries(); 89 void PostPendingEntries();
57 void AddEntriesOnUI(scoped_ptr<base::ListValue> value); 90 void AddEntriesOnUI(scoped_ptr<base::ListValue> value);
58 91
59 void MaybeStartNetInternalLogging(); 92 // Initializes a new instance of net::NetLogLogger and passes it back via
60 void MaybeStopNetInternalLogging(); 93 // |net_logger| param.
94 void InitializeNetLogger(const std::string& owner_extension_id,
95 net::NetLogLogger** net_logger);
96
97 // Starts observing network events with a new |net_logger| instance.
98 void StartObservingNetEvents(IOThread* io_thread,
99 net::NetLogLogger** net_logger);
100 void MaybeStartNetInternalLogging(const std::string& caller_extension_id,
101 IOThread* io_thread,
102 api::log_private::EventSink event_sink);
103 void MaybeStopNetInternalLogging(const base::Closure& closure);
61 void StopNetInternalLogging(); 104 void StopNetInternalLogging();
62 105
63 // BrowserContextKeyedAPI implementation. 106 // BrowserContextKeyedAPI implementation.
64 static const char* service_name() { 107 static const char* service_name() {
65 return "LogPrivateAPI"; 108 return "LogPrivateAPI";
66 } 109 }
67 static const bool kServiceIsNULLWhileTesting = true; 110 static const bool kServiceIsNULLWhileTesting = true;
68 static const bool kServiceRedirectedInIncognito = true; 111 static const bool kServiceRedirectedInIncognito = true;
69 112
70 content::BrowserContext* const browser_context_; 113 content::BrowserContext* const browser_context_;
71 bool logging_net_internals_; 114 bool logging_net_internals_;
115 api::log_private::EventSink event_sink_;
72 std::set<std::string> net_internal_watches_; 116 std::set<std::string> net_internal_watches_;
73 scoped_ptr<base::ListValue> pending_entries_; 117 scoped_ptr<base::ListValue> pending_entries_;
74 118 scoped_ptr<net::NetLogLogger> net_log_logger_;
75 // Listen to extension unloaded notifications. 119 // Listen to extension unloaded notifications.
76 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 120 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
77 extension_registry_observer_; 121 extension_registry_observer_;
122 ApiResourceManager<FileResource, WorkerPoolThreadTraits<FileResource> >
123 log_file_resources_;
124 bool initialized_;
125
126 DISALLOW_COPY_AND_ASSIGN(LogPrivateAPI);
78 }; 127 };
79 128
80 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { 129 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction {
81 public: 130 public:
82 LogPrivateGetHistoricalFunction(); 131 LogPrivateGetHistoricalFunction();
83 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical", 132 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical",
84 LOGPRIVATE_GETHISTORICAL); 133 LOGPRIVATE_GETHISTORICAL);
85 134
86 protected: 135 protected:
87 virtual ~LogPrivateGetHistoricalFunction(); 136 virtual ~LogPrivateGetHistoricalFunction();
88 virtual bool RunAsync() OVERRIDE; 137 virtual bool RunAsync() OVERRIDE;
89 138
90 private: 139 private:
91 void OnSystemLogsLoaded(scoped_ptr<system_logs::SystemLogsResponse> sys_info); 140 void OnSystemLogsLoaded(scoped_ptr<system_logs::SystemLogsResponse> sys_info);
92 141
93 scoped_ptr<FilterHandler> filter_handler_; 142 scoped_ptr<FilterHandler> filter_handler_;
94 143
95 DISALLOW_COPY_AND_ASSIGN(LogPrivateGetHistoricalFunction); 144 DISALLOW_COPY_AND_ASSIGN(LogPrivateGetHistoricalFunction);
96 }; 145 };
97 146
98 class LogPrivateStartNetInternalsWatchFunction 147 class LogPrivateStartEventRecorderFunction : public AsyncExtensionFunction {
99 : public ChromeSyncExtensionFunction {
100 public: 148 public:
101 LogPrivateStartNetInternalsWatchFunction(); 149 LogPrivateStartEventRecorderFunction();
102 DECLARE_EXTENSION_FUNCTION("logPrivate.startNetInternalsWatch", 150 DECLARE_EXTENSION_FUNCTION("logPrivate.startEventRecorder",
103 LOGPRIVATE_STARTNETINTERNALSWATCH); 151 LOGPRIVATE_STARTEVENTRECODER);
104 152
105 protected: 153 protected:
106 virtual ~LogPrivateStartNetInternalsWatchFunction(); 154 virtual ~LogPrivateStartEventRecorderFunction();
107 virtual bool RunSync() OVERRIDE; 155 virtual bool RunAsync() OVERRIDE;
108 156
109 private: 157 private:
110 DISALLOW_COPY_AND_ASSIGN(LogPrivateStartNetInternalsWatchFunction); 158 void OnEventRecorderStarted();
159
160 DISALLOW_COPY_AND_ASSIGN(LogPrivateStartEventRecorderFunction);
111 }; 161 };
112 162
113 class LogPrivateStopNetInternalsWatchFunction 163 class LogPrivateStopEventRecorderFunction : public AsyncExtensionFunction {
114 : public ChromeSyncExtensionFunction {
115 public: 164 public:
116 LogPrivateStopNetInternalsWatchFunction(); 165 LogPrivateStopEventRecorderFunction();
117 DECLARE_EXTENSION_FUNCTION("logPrivate.stopNetInternalsWatch", 166 DECLARE_EXTENSION_FUNCTION("logPrivate.stopEventRecorder",
118 LOGPRIVATE_STOPNETINTERNALSWATCH); 167 LOGPRIVATE_STOPEVENTRECODER);
119 168
120 protected: 169 protected:
121 virtual ~LogPrivateStopNetInternalsWatchFunction(); 170 virtual ~LogPrivateStopEventRecorderFunction();
122 virtual bool RunSync() OVERRIDE; 171
172 // AsyncExtensionFunction overrides.
173 virtual bool RunAsync() OVERRIDE;
123 174
124 private: 175 private:
125 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); 176 void OnEventRecorderStopped();
177
178 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopEventRecorderFunction);
179 };
180
181 class LogPrivateDumpLogsFunction : public AsyncExtensionFunction {
182 public:
183 LogPrivateDumpLogsFunction();
184 DECLARE_EXTENSION_FUNCTION("logPrivate.dumpLogs", LOGPRIVATE_DUMPLOGS);
185
186 protected:
187 virtual ~LogPrivateDumpLogsFunction();
188
189 // AsyncExtensionFunction overrides.
190 virtual bool RunAsync() OVERRIDE;
191
192 private:
193 // Callback for DebugLogWriter::StoreLogs() call.
194 void OnStoreLogsCompleted(const base::FilePath& log_path, bool succeeded);
195 // Callback for LogPrivateAPI::StopAllWatches() call.
196 void OnStopAllWatches();
197 DISALLOW_COPY_AND_ASSIGN(LogPrivateDumpLogsFunction);
126 }; 198 };
127 199
128 } // namespace extensions 200 } // namespace extensions
129 201
130 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ 202 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698