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 "chrome/browser/extensions/api/log_private/filter_handler.h" | 12 #include "chrome/browser/extensions/api/log_private/filter_handler.h" |
12 #include "chrome/browser/extensions/api/log_private/log_parser.h" | 13 #include "chrome/browser/extensions/api/log_private/log_parser.h" |
13 #include "chrome/browser/extensions/chrome_extension_function.h" | 14 #include "chrome/browser/extensions/chrome_extension_function.h" |
14 #include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" | 15 #include "chrome/browser/feedback/system_logs/about_system_logs_fetcher.h" |
15 #include "chrome/common/extensions/api/log_private.h" | 16 #include "chrome/common/extensions/api/log_private.h" |
16 #include "content/public/browser/notification_observer.h" | |
17 #include "content/public/browser/notification_registrar.h" | |
18 #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" |
19 #include "net/base/net_log.h" | 19 #include "net/base/net_log.h" |
20 | 20 |
21 class Profile; | |
22 | |
23 namespace content { | 21 namespace content { |
24 class BrowserContext; | 22 class BrowserContext; |
25 } | 23 } |
26 | 24 |
27 namespace extensions { | 25 namespace extensions { |
| 26 class ExtensionRegistry; |
28 | 27 |
29 class LogPrivateAPI : public BrowserContextKeyedAPI, | 28 class LogPrivateAPI : public BrowserContextKeyedAPI, |
30 public content::NotificationObserver, | 29 public ExtensionRegistryObserver, |
31 public net::NetLog::ThreadSafeObserver { | 30 public net::NetLog::ThreadSafeObserver { |
32 public: | 31 public: |
33 // Convenience method to get the LogPrivateAPI for a profile. | 32 // Convenience method to get the LogPrivateAPI for a profile. |
34 static LogPrivateAPI* Get(content::BrowserContext* context); | 33 static LogPrivateAPI* Get(content::BrowserContext* context); |
35 | 34 |
36 explicit LogPrivateAPI(content::BrowserContext* context); | 35 explicit LogPrivateAPI(content::BrowserContext* context); |
37 virtual ~LogPrivateAPI(); | 36 virtual ~LogPrivateAPI(); |
38 | 37 |
39 void StartNetInternalsWatch(const std::string& extension_id); | 38 void StartNetInternalsWatch(const std::string& extension_id); |
40 void StopNetInternalsWatch(const std::string& extension_id); | 39 void StopNetInternalsWatch(const std::string& extension_id); |
41 | 40 |
42 // BrowserContextKeyedAPI implementation. | 41 // BrowserContextKeyedAPI implementation. |
43 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); | 42 static BrowserContextKeyedAPIFactory<LogPrivateAPI>* GetFactoryInstance(); |
44 | 43 |
45 // content::NotificationObserver implementation. | |
46 virtual void Observe(int type, | |
47 const content::NotificationSource& source, | |
48 const content::NotificationDetails& details) OVERRIDE; | |
49 | |
50 private: | 44 private: |
51 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; | 45 friend class BrowserContextKeyedAPIFactory<LogPrivateAPI>; |
52 | 46 |
| 47 // ExtensionRegistryObserver implementation. |
| 48 virtual void OnExtensionUnloaded( |
| 49 content::BrowserContext* browser_context, |
| 50 const Extension* extension, |
| 51 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 52 |
53 // ChromeNetLog::ThreadSafeObserver implementation: | 53 // ChromeNetLog::ThreadSafeObserver implementation: |
54 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; | 54 virtual void OnAddEntry(const net::NetLog::Entry& entry) OVERRIDE; |
55 | 55 |
56 void PostPendingEntries(); | 56 void PostPendingEntries(); |
57 void AddEntriesOnUI(scoped_ptr<base::ListValue> value); | 57 void AddEntriesOnUI(scoped_ptr<base::ListValue> value); |
58 | 58 |
59 void MaybeStartNetInternalLogging(); | 59 void MaybeStartNetInternalLogging(); |
60 void MaybeStopNetInternalLogging(); | 60 void MaybeStopNetInternalLogging(); |
61 void StopNetInternalLogging(); | 61 void StopNetInternalLogging(); |
62 | 62 |
63 // BrowserContextKeyedAPI implementation. | 63 // BrowserContextKeyedAPI implementation. |
64 static const char* service_name() { | 64 static const char* service_name() { |
65 return "LogPrivateAPI"; | 65 return "LogPrivateAPI"; |
66 } | 66 } |
67 static const bool kServiceIsNULLWhileTesting = true; | 67 static const bool kServiceIsNULLWhileTesting = true; |
68 static const bool kServiceRedirectedInIncognito = true; | 68 static const bool kServiceRedirectedInIncognito = true; |
69 | 69 |
70 Profile* const profile_; | 70 content::BrowserContext* const browser_context_; |
71 bool logging_net_internals_; | 71 bool logging_net_internals_; |
72 content::NotificationRegistrar registrar_; | |
73 std::set<std::string> net_internal_watches_; | 72 std::set<std::string> net_internal_watches_; |
74 scoped_ptr<base::ListValue> pending_entries_; | 73 scoped_ptr<base::ListValue> pending_entries_; |
| 74 |
| 75 // Listen to extension unloaded notifications. |
| 76 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 77 extension_registry_observer_; |
75 }; | 78 }; |
76 | 79 |
77 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { | 80 class LogPrivateGetHistoricalFunction : public AsyncExtensionFunction { |
78 public: | 81 public: |
79 LogPrivateGetHistoricalFunction(); | 82 LogPrivateGetHistoricalFunction(); |
80 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical", | 83 DECLARE_EXTENSION_FUNCTION("logPrivate.getHistorical", |
81 LOGPRIVATE_GETHISTORICAL); | 84 LOGPRIVATE_GETHISTORICAL); |
82 | 85 |
83 protected: | 86 protected: |
84 virtual ~LogPrivateGetHistoricalFunction(); | 87 virtual ~LogPrivateGetHistoricalFunction(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 virtual ~LogPrivateStopNetInternalsWatchFunction(); | 121 virtual ~LogPrivateStopNetInternalsWatchFunction(); |
119 virtual bool RunImpl() OVERRIDE; | 122 virtual bool RunImpl() OVERRIDE; |
120 | 123 |
121 private: | 124 private: |
122 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); | 125 DISALLOW_COPY_AND_ASSIGN(LogPrivateStopNetInternalsWatchFunction); |
123 }; | 126 }; |
124 | 127 |
125 } // namespace extensions | 128 } // namespace extensions |
126 | 129 |
127 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ | 130 #endif // CHROME_BROWSER_EXTENSIONS_API_LOG_PRIVATE_LOG_PRIVATE_API_H_ |
OLD | NEW |