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.
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.
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_
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/chrome_extension_function.h"
16 #include "extensions/browser/browser_context_keyed_api_factory.h"
17 #include "extensions/browser/event_router.h"
19 namespace extensions
{
23 // Handles interactions between the Activity Log API and implementation.
24 class ActivityLogAPI
: public BrowserContextKeyedAPI
,
25 public extensions::ActivityLog::Observer
,
26 public EventRouter::Observer
{
28 explicit ActivityLogAPI(content::BrowserContext
* context
);
29 ~ActivityLogAPI() override
;
31 // BrowserContextKeyedAPI implementation.
32 static BrowserContextKeyedAPIFactory
<ActivityLogAPI
>* GetFactoryInstance();
34 void Shutdown() override
;
36 // Lookup whether the extension ID is whitelisted.
37 static bool IsExtensionWhitelisted(const std::string
& extension_id
);
40 friend class BrowserContextKeyedAPIFactory
<ActivityLogAPI
>;
41 static const char* service_name() { return "ActivityLogPrivateAPI"; }
43 // ActivityLog::Observer
44 // We pass this along to activityLogPrivate.onExtensionActivity.
45 void OnExtensionActivity(scoped_refptr
<Action
> activity
) override
;
47 // EventRouter::Observer
48 // We only keep track of OnExtensionActivity if we have any listeners.
49 void OnListenerAdded(const EventListenerInfo
& details
) override
;
50 void OnListenerRemoved(const EventListenerInfo
& details
) override
;
52 content::BrowserContext
* browser_context_
;
53 ActivityLog
* activity_log_
;
56 DISALLOW_COPY_AND_ASSIGN(ActivityLogAPI
);
61 BrowserContextKeyedAPIFactory
<ActivityLogAPI
>::DeclareFactoryDependencies();
63 // The implementation of activityLogPrivate.getExtensionActivities
64 class ActivityLogPrivateGetExtensionActivitiesFunction
65 : public ChromeAsyncExtensionFunction
{
67 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.getExtensionActivities",
68 ACTIVITYLOGPRIVATE_GETEXTENSIONACTIVITIES
)
71 ~ActivityLogPrivateGetExtensionActivitiesFunction() override
{}
74 bool RunAsync() override
;
77 void OnLookupCompleted(
78 scoped_ptr
<std::vector
<scoped_refptr
<Action
> > > activities
);
81 // The implementation of activityLogPrivate.deleteActivities
82 class ActivityLogPrivateDeleteActivitiesFunction
83 : public ChromeAsyncExtensionFunction
{
85 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteActivities",
86 ACTIVITYLOGPRIVATE_DELETEACTIVITIES
)
89 ~ActivityLogPrivateDeleteActivitiesFunction() override
{}
92 bool RunAsync() override
;
95 // The implementation of activityLogPrivate.deleteDatabase
96 class ActivityLogPrivateDeleteDatabaseFunction
97 : public ChromeAsyncExtensionFunction
{
99 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteDatabase",
100 ACTIVITYLOGPRIVATE_DELETEDATABASE
)
103 ~ActivityLogPrivateDeleteDatabaseFunction() override
{}
105 // ExtensionFunction:
106 bool RunAsync() override
;
109 // The implementation of activityLogPrivate.deleteUrls
110 class ActivityLogPrivateDeleteUrlsFunction
111 : public ChromeAsyncExtensionFunction
{
113 DECLARE_EXTENSION_FUNCTION("activityLogPrivate.deleteUrls",
114 ACTIVITYLOGPRIVATE_DELETEURLS
)
117 ~ActivityLogPrivateDeleteUrlsFunction() override
{}
119 // ExtensionFunction:
120 bool RunAsync() override
;
123 } // namespace extensions
125 #endif // CHROME_BROWSER_EXTENSIONS_API_ACTIVITY_LOG_PRIVATE_ACTIVITY_LOG_PRIVATE_API_H_