| 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/api/profile_keyed_api_factory.h" | |
| 16 #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" |
| 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 ProfileKeyedAPI, | 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 virtual ~ActivityLogAPI(); |
| 30 | 30 |
| 31 // ProfileKeyedAPI implementation. | 31 // BrowserContextKeyedAPI implementation. |
| 32 static ProfileKeyedAPIFactory<ActivityLogAPI>* GetFactoryInstance(); | 32 static BrowserContextKeyedAPIFactory<ActivityLogAPI>* GetFactoryInstance(); |
| 33 | 33 |
| 34 virtual void Shutdown() OVERRIDE; | 34 virtual 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 ProfileKeyedAPIFactory<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 virtual 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 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 50 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; | 50 virtual 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 ProfileKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies(); | 60 void |
| 61 BrowserContextKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies(); |
| 61 | 62 |
| 62 // The implementation of activityLogPrivate.getExtensionActivities | 63 // The implementation of activityLogPrivate.getExtensionActivities |
| 63 class ActivityLogPrivateGetExtensionActivitiesFunction | 64 class ActivityLogPrivateGetExtensionActivitiesFunction |
| 64 : public ChromeAsyncExtensionFunction { | 65 : public ChromeAsyncExtensionFunction { |
| 65 public: | 66 public: |
| 66 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities", | 67 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities", |
| 67 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES) | 68 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES) |
| 68 | 69 |
| 69 protected: | 70 protected: |
| 70 virtual ~ActivityLogPrivateGetExtensionActivitiesFunction() {} | 71 virtual ~ActivityLogPrivateGetExtensionActivitiesFunction() {} |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 protected: | 116 protected: |
| 116 virtual ~ActivityLogPrivateDeleteUrlsFunction() {} | 117 virtual ~ActivityLogPrivateDeleteUrlsFunction() {} |
| 117 | 118 |
| 118 // ExtensionFunction: | 119 // ExtensionFunction: |
| 119 virtual bool RunImpl() OVERRIDE; | 120 virtual bool RunImpl() OVERRIDE; |
| 120 }; | 121 }; |
| 121 | 122 |
| 122 } // namespace extensions | 123 } // namespace extensions |
| 123 | 124 |
| 124 #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 |