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 // This extension API provides access to the Activity Log, which is a | 5 // This extension API provides access to the Activity Log, which is a |
6 // monitoring framework for extension behavior. Only specific Google-produced | 6 // monitoring framework for extension behavior. Only specific Google-produced |
7 // extensions should have access to it. | 7 // extensions should have access to it. |
8 | 8 |
9 #ifndef CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_
API_H_ | 9 #ifndef CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_
API_H_ |
10 #define CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_
API_H_ | 10 #define CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_
API_H_ |
11 | 11 |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 13 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
14 #include "chrome/browser/extensions/activity_log/activity_log.h" | 14 #include "chrome/browser/extensions/activity_log/activity_log.h" |
15 #include "chrome/browser/extensions/chrome_extension_function.h" | 15 #include "chrome/browser/extensions/chrome_extension_function.h" |
16 #include "extensions/browser/browser_context_keyed_api_factory.h" | 16 #include "extensions/browser/browser_context_keyed_api_factory.h" |
17 #include "extensions/browser/event_router.h" | 17 #include "extensions/browser/event_router.h" |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 | 20 |
21 class ActivityLog; | 21 class ActivityLog; |
22 | 22 |
23 // Handles interactions between the Activity Log API and implementation. | 23 // Handles interactions between the Activity Log API and implementation. |
24 class ActivityLogAPI : public BrowserContextKeyedAPI, | 24 class ActivityLogAPI : public BrowserContextKeyedAPI, |
25 public extensions::ActivityLog::Observer, | 25 public extensions::ActivityLog::Observer, |
26 public EventRouter::Observer { | 26 public EventRouter::Observer { |
27 public: | 27 public: |
28 explicit ActivityLogAPI(content::BrowserContext* context); | 28 explicit ActivityLogAPI(content::BrowserContext* context); |
29 virtual ~ActivityLogAPI(); | 29 ~ActivityLogAPI() override; |
30 | 30 |
31 // BrowserContextKeyedAPI implementation. | 31 // BrowserContextKeyedAPI implementation. |
32 static BrowserContextKeyedAPIFactory<ActivityLogAPI>* GetFactoryInstance(); | 32 static BrowserContextKeyedAPIFactory<ActivityLogAPI>* GetFactoryInstance(); |
33 | 33 |
34 virtual void Shutdown() override; | 34 void Shutdown() override; |
35 | 35 |
36 // Lookup whether the extension ID is whitelisted. | 36 // Lookup whether the extension ID is whitelisted. |
37 static bool IsExtensionWhitelisted(const std::string& extension_id); | 37 static bool IsExtensionWhitelisted(const std::string& extension_id); |
38 | 38 |
39 private: | 39 private: |
40 friend class BrowserContextKeyedAPIFactory<ActivityLogAPI>; | 40 friend class BrowserContextKeyedAPIFactory<ActivityLogAPI>; |
41 static const char* service_name() { return "ActivityLogPrivateAPI"; } | 41 static const char* service_name() { return "ActivityLogPrivateAPI"; } |
42 | 42 |
43 // ActivityLog::Observer | 43 // ActivityLog::Observer |
44 // We pass this along to activityLogPrivate.onExtensionActivity. | 44 // We pass this along to activityLogPrivate.onExtensionActivity. |
45 virtual void OnExtensionActivity(scoped_refptr<Action> activity) override; | 45 void OnExtensionActivity(scoped_refptr<Action> activity) override; |
46 | 46 |
47 // EventRouter::Observer | 47 // EventRouter::Observer |
48 // We only keep track of OnExtensionActivity if we have any listeners. | 48 // We only keep track of OnExtensionActivity if we have any listeners. |
49 virtual void OnListenerAdded(const EventListenerInfo& details) override; | 49 void OnListenerAdded(const EventListenerInfo& details) override; |
50 virtual void OnListenerRemoved(const EventListenerInfo& details) override; | 50 void OnListenerRemoved(const EventListenerInfo& details) override; |
51 | 51 |
52 content::BrowserContext* browser_context_; | 52 content::BrowserContext* browser_context_; |
53 ActivityLog* activity_log_; | 53 ActivityLog* activity_log_; |
54 bool initialized_; | 54 bool initialized_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(ActivityLogAPI); | 56 DISALLOW_COPY_AND_ASSIGN(ActivityLogAPI); |
57 }; | 57 }; |
58 | 58 |
59 template <> | 59 template <> |
60 void | 60 void |
61 BrowserContextKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies(); | 61 BrowserContextKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies(); |
62 | 62 |
63 // The implementation of activityLogPrivate.getExtensionActivities | 63 // The implementation of activityLogPrivate.getExtensionActivities |
64 class ActivityLogPrivateGetExtensionActivitiesFunction | 64 class ActivityLogPrivateGetExtensionActivitiesFunction |
65 : public ChromeAsyncExtensionFunction { | 65 : public ChromeAsyncExtensionFunction { |
66 public: | 66 public: |
67 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities", | 67 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities", |
68 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES) | 68 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES) |
69 | 69 |
70 protected: | 70 protected: |
71 virtual ~ActivityLogPrivateGetExtensionActivitiesFunction() {} | 71 ~ActivityLogPrivateGetExtensionActivitiesFunction() override {} |
72 | 72 |
73 // ExtensionFunction: | 73 // ExtensionFunction: |
74 virtual bool RunAsync() override; | 74 bool RunAsync() override; |
75 | 75 |
76 private: | 76 private: |
77 void OnLookupCompleted( | 77 void OnLookupCompleted( |
78 scoped_ptr<std::vector<scoped_refptr<Action> > > activities); | 78 scoped_ptr<std::vector<scoped_refptr<Action> > > activities); |
79 }; | 79 }; |
80 | 80 |
81 // The implementation of activityLogPrivate.deleteActivities | 81 // The implementation of activityLogPrivate.deleteActivities |
82 class ActivityLogPrivateDeleteActivitiesFunction | 82 class ActivityLogPrivateDeleteActivitiesFunction |
83 : public ChromeAsyncExtensionFunction { | 83 : public ChromeAsyncExtensionFunction { |
84 public: | 84 public: |
85 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteActivities", | 85 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteActivities", |
86 ACTIVITYLOGPRIVATE_DELETEACTIVITIES) | 86 ACTIVITYLOGPRIVATE_DELETEACTIVITIES) |
87 | 87 |
88 protected: | 88 protected: |
89 virtual ~ActivityLogPrivateDeleteActivitiesFunction() {} | 89 ~ActivityLogPrivateDeleteActivitiesFunction() override {} |
90 | 90 |
91 // ExtensionFunction: | 91 // ExtensionFunction: |
92 virtual bool RunAsync() override; | 92 bool RunAsync() override; |
93 }; | 93 }; |
94 | 94 |
95 // The implementation of activityLogPrivate.deleteDatabase | 95 // The implementation of activityLogPrivate.deleteDatabase |
96 class ActivityLogPrivateDeleteDatabaseFunction | 96 class ActivityLogPrivateDeleteDatabaseFunction |
97 : public ChromeAsyncExtensionFunction { | 97 : public ChromeAsyncExtensionFunction { |
98 public: | 98 public: |
99 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteDatabase", | 99 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteDatabase", |
100 ACTIVITYLOGPRIVATE_DELETEDATABASE) | 100 ACTIVITYLOGPRIVATE_DELETEDATABASE) |
101 | 101 |
102 protected: | 102 protected: |
103 virtual ~ActivityLogPrivateDeleteDatabaseFunction() {} | 103 ~ActivityLogPrivateDeleteDatabaseFunction() override {} |
104 | 104 |
105 // ExtensionFunction: | 105 // ExtensionFunction: |
106 virtual bool RunAsync() override; | 106 bool RunAsync() override; |
107 }; | 107 }; |
108 | 108 |
109 // The implementation of activityLogPrivate.deleteUrls | 109 // The implementation of activityLogPrivate.deleteUrls |
110 class ActivityLogPrivateDeleteUrlsFunction | 110 class ActivityLogPrivateDeleteUrlsFunction |
111 : public ChromeAsyncExtensionFunction { | 111 : public ChromeAsyncExtensionFunction { |
112 public: | 112 public: |
113 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteUrls", | 113 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteUrls", |
114 ACTIVITYLOGPRIVATE_DELETEURLS) | 114 ACTIVITYLOGPRIVATE_DELETEURLS) |
115 | 115 |
116 protected: | 116 protected: |
117 virtual ~ActivityLogPrivateDeleteUrlsFunction() {} | 117 ~ActivityLogPrivateDeleteUrlsFunction() override {} |
118 | 118 |
119 // ExtensionFunction: | 119 // ExtensionFunction: |
120 virtual bool RunAsync() override; | 120 bool RunAsync() override; |
121 }; | 121 }; |
122 | 122 |
123 } // namespace extensions | 123 } // namespace extensions |
124 | 124 |
125 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVA
TE_API_H_ | 125 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVA
TE_API_H_ |
OLD | NEW |