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/activity_log_private/activity_log_private_api.h" 16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 17 #include "chrome/browser/extensions/event_router.h" 18 #include "chrome/browser/extensions/extension_function.h" 19 20 namespace extensions { 21 22 class ActivityLog; 23 24 // The ID of the trusted/whitelisted ActivityLog extension. 25 extern const char kActivityLogExtensionId[]; 26 extern const char kActivityLogTestExtensionId[]; 27 extern const char kNewActivityEventName[]; 28 29 // Handles interactions between the Activity Log API and implementation. 30 class ActivityLogAPI : public ProfileKeyedAPI, 31 public extensions::ActivityLog::Observer, 32 public EventRouter::Observer { 33 public: 34 explicit ActivityLogAPI(Profile* profile); 35 virtual ~ActivityLogAPI(); 36 37 // ProfileKeyedAPI implementation. 38 static ProfileKeyedAPIFactory<ActivityLogAPI>* GetFactoryInstance(); 39 40 virtual void Shutdown() OVERRIDE; 41 42 // Lookup whether the extension ID is whitelisted. 43 static bool IsExtensionWhitelisted(const std::string& extension_id); 44 45 private: 46 friend class ProfileKeyedAPIFactory<ActivityLogAPI>; 47 static const char* service_name() { return "ActivityLogPrivateAPI"; } 48 49 // ActivityLog::Observer 50 // We pass this along to activityLogPrivate.onExtensionActivity. 51 virtual void OnExtensionActivity(scoped_refptr<Action> activity) OVERRIDE; 52 53 // EventRouter::Observer 54 // We only keep track of OnExtensionActivity if we have any listeners. 55 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 56 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; 57 58 Profile* profile_; 59 ActivityLog* activity_log_; 60 bool initialized_; 61 62 DISALLOW_COPY_AND_ASSIGN(ActivityLogAPI); 63 }; 64 65 template<> 66 void ProfileKeyedAPIFactory<ActivityLogAPI>::DeclareFactoryDependencies(); 67 68 // The implementation of activityLogPrivate.getExtensionActivities 69 class ActivityLogPrivateGetExtensionActivitiesFunction 70 : public AsyncExtensionFunction { 71 public: 72 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities", 73 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES) 74 75 protected: 76 virtual ~ActivityLogPrivateGetExtensionActivitiesFunction() {} 77 78 // ExtensionFunction: 79 virtual bool RunImpl() OVERRIDE; 80 }; 81 82 } // namespace extensions 83 84 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_API_H_ 85