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