Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log.h

Issue 18430004: Sets correct ActivityLog enabled status to the first renderer process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/extensions/tab_helper.h" 23 #include "chrome/browser/extensions/tab_helper.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/common/extensions/dom_action_types.h" 25 #include "chrome/common/extensions/dom_action_types.h"
26 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 26 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
27 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 27 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
28 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 28 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
29 29
30 class Profile; 30 class Profile;
31 using content::BrowserThread; 31 using content::BrowserThread;
32 32
33 namespace user_prefs {
34 class PrefRegistrySyncable;
35 }
36
33 namespace extensions { 37 namespace extensions {
34 class Extension; 38 class Extension;
35 class ActivityLogPolicy; 39 class ActivityLogPolicy;
36 40
37 // A utility for tracing interesting activity for each extension. 41 // A utility for tracing interesting activity for each extension.
38 // It writes to an ActivityDatabase on a separate thread to record the activity. 42 // It writes to an ActivityDatabase on a separate thread to record the activity.
39 class ActivityLog : public BrowserContextKeyedService, 43 class ActivityLog : public BrowserContextKeyedService,
40 public TabHelper::ScriptExecutionObserver, 44 public TabHelper::ScriptExecutionObserver,
41 public InstallObserver { 45 public InstallObserver {
42 public: 46 public:
43 // Observers can listen for activity events. There is probably only one 47 // Observers can listen for activity events. There is probably only one
44 // observer: the activityLogPrivate API. 48 // observer: the activityLogPrivate API.
45 class Observer { 49 class Observer {
46 public: 50 public:
47 virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0; 51 virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0;
48 }; 52 };
49 53
50 // ActivityLog is a singleton, so don't instantiate it with the constructor; 54 // ActivityLog is a singleton, so don't instantiate it with the constructor;
51 // use GetInstance instead. 55 // use GetInstance instead.
52 static ActivityLog* GetInstance(Profile* profile); 56 static ActivityLog* GetInstance(Profile* profile);
53 57
54 // Provides up-to-date information about whether the AL is enabled for a 58 // Provides up-to-date information about whether the AL is enabled for a
55 // profile. The AL is enabled if the user has installed the whitelisted 59 // profile. The AL is enabled if the user has installed the whitelisted
56 // AL extension *or* set the --enable-extension-activity-logging flag. 60 // AL extension *or* set the --enable-extension-activity-logging flag.
57 bool IsLogEnabled(); 61 bool IsLogEnabled();
58 62
59 // If you want to know whether the log is enabled but DON'T have a profile
60 // object yet, use this method. However, it's preferable for the caller to
61 // use IsLogEnabled when possible.
62 static bool IsLogEnabledOnAnyProfile();
63
64 // Add/remove observer: the activityLogPrivate API only listens when the 63 // Add/remove observer: the activityLogPrivate API only listens when the
65 // ActivityLog extension is registered for an event. 64 // ActivityLog extension is registered for an event.
66 void AddObserver(Observer* observer); 65 void AddObserver(Observer* observer);
67 void RemoveObserver(Observer* observer); 66 void RemoveObserver(Observer* observer);
68 67
69 // Log a successful API call made by an extension. 68 // Log a successful API call made by an extension.
70 // This will create an APIAction for storage in the database. 69 // This will create an APIAction for storage in the database.
71 // (Note: implemented as a wrapper for LogAPIActionInternal.) 70 // (Note: implemented as a wrapper for LogAPIActionInternal.)
72 void LogAPIAction(const std::string& extension_id, 71 void LogAPIAction(const std::string& extension_id,
73 const std::string& name, // e.g., tabs.get 72 const std::string& name, // e.g., tabs.get
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 int percent_downloaded) OVERRIDE {} 138 int percent_downloaded) OVERRIDE {}
140 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE {} 139 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE {}
141 virtual void OnAppsReordered() OVERRIDE {} 140 virtual void OnAppsReordered() OVERRIDE {}
142 virtual void OnAppInstalledToAppList( 141 virtual void OnAppInstalledToAppList(
143 const std::string& extension_id) OVERRIDE {} 142 const std::string& extension_id) OVERRIDE {}
144 virtual void OnShutdown() OVERRIDE {} 143 virtual void OnShutdown() OVERRIDE {}
145 144
146 // BrowserContextKeyedService 145 // BrowserContextKeyedService
147 virtual void Shutdown() OVERRIDE; 146 virtual void Shutdown() OVERRIDE;
148 147
148 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
149
149 private: 150 private:
150 friend class ActivityLogFactory; 151 friend class ActivityLogFactory;
151 friend class ActivityLogTest; 152 friend class ActivityLogTest;
152 friend class RenderViewActivityLogTest; 153 friend class RenderViewActivityLogTest;
153 154
154 explicit ActivityLog(Profile* profile); 155 explicit ActivityLog(Profile* profile);
155 virtual ~ActivityLog(); 156 virtual ~ActivityLog();
156 157
157 // Some setup needs to wait until after the ExtensionSystem/ExtensionService 158 // Delayed initialization of Install Tracker which waits until after the
158 // are done with their own setup. 159 // ExtensionSystem/ExtensionService are done with their own setup.
159 void Init(); 160 void InitInstallTracker();
160 161
161 // We log callbacks and API calls very similarly, so we handle them the same 162 // We log callbacks and API calls very similarly, so we handle them the same
162 // way internally. 163 // way internally.
163 void LogAPIActionInternal( 164 void LogAPIActionInternal(
164 const std::string& extension_id, 165 const std::string& extension_id,
165 const std::string& api_call, 166 const std::string& api_call,
166 base::ListValue* args, 167 base::ListValue* args,
167 const std::string& extra, 168 const std::string& extra,
168 const APIAction::Type type); 169 const APIAction::Type type);
169 170
170 // TabHelper::ScriptExecutionObserver implementation. 171 // TabHelper::ScriptExecutionObserver implementation.
171 // Fires when a ContentScript is executed. 172 // Fires when a ContentScript is executed.
172 virtual void OnScriptsExecuted( 173 virtual void OnScriptsExecuted(
173 const content::WebContents* web_contents, 174 const content::WebContents* web_contents,
174 const ExecutingScriptsMap& extension_ids, 175 const ExecutingScriptsMap& extension_ids,
175 int32 page_id, 176 int32 page_id,
176 const GURL& on_url) OVERRIDE; 177 const GURL& on_url) OVERRIDE;
177 178
178 // For unit tests only. Does not call Init again!
179 // Sets whether logging should be enabled for the whole current profile.
180 static void RecomputeLoggingIsEnabled(bool profile_enabled);
181
182 // At the moment, ActivityLog will use only one policy for summarization. 179 // At the moment, ActivityLog will use only one policy for summarization.
183 // These methods are used to choose and set the most appropriate policy. 180 // These methods are used to choose and set the most appropriate policy.
184 void ChooseDefaultPolicy(); 181 void ChooseDefaultPolicy();
185 void SetDefaultPolicy(ActivityLogPolicy::PolicyType policy_type); 182 void SetDefaultPolicy(ActivityLogPolicy::PolicyType policy_type);
186 183
187 typedef ObserverListThreadSafe<Observer> ObserverList; 184 typedef ObserverListThreadSafe<Observer> ObserverList;
188 scoped_refptr<ObserverList> observers_; 185 scoped_refptr<ObserverList> observers_;
189 186
190 // The policy object takes care of data summarization, compression, and 187 // The policy object takes care of data summarization, compression, and
191 // logging. The policy object is owned by the ActivityLog, but this cannot 188 // logging. The policy object is owned by the ActivityLog, but this cannot
192 // be a scoped_ptr since some cleanup work must happen on the database 189 // be a scoped_ptr since some cleanup work must happen on the database
193 // thread. Calling policy_->Close() will free the object; see the comments 190 // thread. Calling policy_->Close() will free the object; see the comments
194 // on the ActivityDatabase class for full details. 191 // on the ActivityDatabase class for full details.
195 extensions::ActivityLogPolicy* policy_; 192 extensions::ActivityLogPolicy* policy_;
196 193
197 // TODO(dbabic,felt) change this into a list of policy types later. 194 // TODO(dbabic,felt) change this into a list of policy types later.
198 ActivityLogPolicy::PolicyType policy_type_; 195 ActivityLogPolicy::PolicyType policy_type_;
199 196
200 Profile* profile_; 197 Profile* profile_;
201 bool enabled_; // Whether logging is currently enabled. 198 bool enabled_; // Whether logging is currently enabled.
202 bool initialized_; // Whether Init() has already been called.
203 bool policy_chosen_; // Whether we've already set the default policy. 199 bool policy_chosen_; // Whether we've already set the default policy.
204 // testing_mode_ controls whether to log API call arguments. By default, we 200 // testing_mode_ controls whether to log API call arguments. By default, we
205 // don't log most arguments to avoid saving too much data. In testing mode, 201 // don't log most arguments to avoid saving too much data. In testing mode,
206 // argument collection is enabled. We also whitelist some arguments for 202 // argument collection is enabled. We also whitelist some arguments for
207 // collection regardless of whether this bool is true. 203 // collection regardless of whether this bool is true.
208 // When testing_mode_ is enabled, we also print to the console. 204 // When testing_mode_ is enabled, we also print to the console.
209 bool testing_mode_; 205 bool testing_mode_;
210 // We need the DB, FILE, and IO threads to operate. In some cases (tests), 206 // We need the DB, FILE, and IO threads to operate. In some cases (tests),
211 // these threads might not exist, so we avoid dispatching anything to the 207 // these threads might not exist, so we avoid dispatching anything to the
212 // ActivityDatabase to prevent things from exploding. 208 // ActivityDatabase to prevent things from exploding.
213 bool has_threads_; 209 bool has_threads_;
214 210
215 // Used to track whether the whitelisted extension is installed. If it's 211 // Used to track whether the whitelisted extension is installed. If it's
216 // added or removed, enabled_ may change. 212 // added or removed, enabled_ may change.
217 InstallTracker* tracker_; 213 InstallTracker* tracker_;
218 214
215 // Set if the watchdog extension is present and active. Maintained by
216 // kWatchdogExtensionActive pref variable.
217 bool watchdog_extension_active_;
218
219 DISALLOW_COPY_AND_ASSIGN(ActivityLog); 219 DISALLOW_COPY_AND_ASSIGN(ActivityLog);
220 }; 220 };
221 221
222 // Each profile has different extensions, so we keep a different database for 222 // Each profile has different extensions, so we keep a different database for
223 // each profile. 223 // each profile.
224 class ActivityLogFactory : public BrowserContextKeyedServiceFactory { 224 class ActivityLogFactory : public BrowserContextKeyedServiceFactory {
225 public: 225 public:
226 static ActivityLog* GetForProfile(Profile* profile) { 226 static ActivityLog* GetForProfile(Profile* profile) {
227 return static_cast<ActivityLog*>( 227 return static_cast<ActivityLog*>(
228 GetInstance()->GetServiceForBrowserContext(profile, true)); 228 GetInstance()->GetServiceForBrowserContext(profile, true));
(...skipping 12 matching lines...) Expand all
241 virtual content::BrowserContext* GetBrowserContextToUse( 241 virtual content::BrowserContext* GetBrowserContextToUse(
242 content::BrowserContext* context) const OVERRIDE; 242 content::BrowserContext* context) const OVERRIDE;
243 243
244 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); 244 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory);
245 }; 245 };
246 246
247 247
248 } // namespace extensions 248 } // namespace extensions
249 249
250 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ 250 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698