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

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

Issue 2372223003: [Extensions] Fix incorrect counting prefs in activity log (Closed)
Patch Set: nit Created 4 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/extensions/activity_log/activity_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 21 matching lines...) Expand all
32 class BrowserContext; 32 class BrowserContext;
33 } 33 }
34 34
35 namespace user_prefs { 35 namespace user_prefs {
36 class PrefRegistrySyncable; 36 class PrefRegistrySyncable;
37 } 37 }
38 38
39 namespace extensions { 39 namespace extensions {
40 class Extension; 40 class Extension;
41 class ExtensionRegistry; 41 class ExtensionRegistry;
42 class ExtensionSystem;
42 43
43 // A utility for tracing interesting activity for each extension. 44 // A utility for tracing interesting activity for each extension.
44 // It writes to an ActivityDatabase on a separate thread to record the activity. 45 // It writes to an ActivityDatabase on a separate thread to record the activity.
45 // Each profile has different extensions, so we keep a different database for 46 // Each profile has different extensions, so we keep a different database for
46 // each profile. 47 // each profile.
47 // 48 //
48 class ActivityLog : public BrowserContextKeyedAPI, 49 class ActivityLog : public BrowserContextKeyedAPI,
49 public ScriptExecutionObserver, 50 public ScriptExecutionObserver,
50 public ExtensionRegistryObserver, 51 public ExtensionRegistryObserver,
51 public content::NotificationObserver { 52 public content::NotificationObserver {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 // Specifies if the Watchdog app is active (installed & enabled). 135 // Specifies if the Watchdog app is active (installed & enabled).
135 // If so, we need to log to the database and stream to the API. 136 // If so, we need to log to the database and stream to the API.
136 bool IsWatchdogAppActive(); 137 bool IsWatchdogAppActive();
137 138
138 // Specifies if we need to record actions to the db. If so, we need to log to 139 // Specifies if we need to record actions to the db. If so, we need to log to
139 // the database. This is true if the Watchdog app is active *or* the 140 // the database. This is true if the Watchdog app is active *or* the
140 // --enable-extension-activity-logging flag is set. 141 // --enable-extension-activity-logging flag is set.
141 bool IsDatabaseEnabled(); 142 bool IsDatabaseEnabled();
142 143
144 // Updates cached_consumer_count_ to be active_consumers_ and stores the value
145 // in prefs.
146 void UpdateCachedConsumerCount();
147
143 // ScriptExecutionObserver implementation. 148 // ScriptExecutionObserver implementation.
144 // Fires when a ContentScript is executed. 149 // Fires when a ContentScript is executed.
145 void OnScriptsExecuted(const content::WebContents* web_contents, 150 void OnScriptsExecuted(const content::WebContents* web_contents,
146 const ExecutingScriptsMap& extension_ids, 151 const ExecutingScriptsMap& extension_ids,
147 const GURL& on_url) override; 152 const GURL& on_url) override;
148 153
149 // At the moment, ActivityLog will use only one policy for summarization. 154 // At the moment, ActivityLog will use only one policy for summarization.
150 // These methods are used to choose and set the most appropriate policy. 155 // These methods are used to choose and set the most appropriate policy.
151 // Changing policies at runtime is not recommended, and likely only should be 156 // Changing policies at runtime is not recommended, and likely only should be
152 // done for unit tests. 157 // done for unit tests.
153 void ChooseDatabasePolicy(); 158 void ChooseDatabasePolicy();
154 void SetDatabasePolicy(ActivityLogPolicy::PolicyType policy_type); 159 void SetDatabasePolicy(ActivityLogPolicy::PolicyType policy_type);
155 160
156 // Checks the current |is_active_| state and modifies it if appropriate. 161 // Checks the current |is_active_| state and modifies it if appropriate.
157 void CheckActive(); 162 // If |use_cached| is true, then this checks the cached_consumer_count_ for
163 // whether or not a consumer is active. Otherwise, checks active_consumers_.
164 void CheckActive(bool use_cached);
158 165
159 // content::NotificationObserver: 166 // content::NotificationObserver:
160 void Observe(int type, 167 void Observe(int type,
161 const content::NotificationSource& source, 168 const content::NotificationSource& source,
162 const content::NotificationDetails& details) override; 169 const content::NotificationDetails& details) override;
163 170
171 // Called once the ExtensionSystem is ready.
172 void OnExtensionSystemReady();
173
164 // BrowserContextKeyedAPI implementation. 174 // BrowserContextKeyedAPI implementation.
165 static const char* service_name() { return "ActivityLog"; } 175 static const char* service_name() { return "ActivityLog"; }
166 static const bool kServiceRedirectedInIncognito = true; 176 static const bool kServiceRedirectedInIncognito = true;
167 static const bool kServiceIsCreatedWithBrowserContext = false; 177 static const bool kServiceIsCreatedWithBrowserContext = false;
168 178
169 typedef base::ObserverListThreadSafe<Observer> ObserverList; 179 typedef base::ObserverListThreadSafe<Observer> ObserverList;
170 scoped_refptr<ObserverList> observers_; 180 scoped_refptr<ObserverList> observers_;
171 181
172 // Policy objects are owned by the ActivityLog, but cannot be scoped_ptrs 182 // Policy objects are owned by the ActivityLog, but cannot be scoped_ptrs
173 // since they may need to do some cleanup work on the database thread. 183 // since they may need to do some cleanup work on the database thread.
174 // Calling policy->Close() will free the object; see the comments on the 184 // Calling policy->Close() will free the object; see the comments on the
175 // ActivityDatabase class for full details. 185 // ActivityDatabase class for full details.
176 186
177 // The database policy object takes care of recording & looking up data: 187 // The database policy object takes care of recording & looking up data:
178 // data summarization, compression, and logging. There should only be a 188 // data summarization, compression, and logging. There should only be a
179 // database_policy_ if the Watchdog app is installed or flag is set. 189 // database_policy_ if the Watchdog app is installed or flag is set.
180 ActivityLogDatabasePolicy* database_policy_; 190 ActivityLogDatabasePolicy* database_policy_;
181 ActivityLogPolicy::PolicyType database_policy_type_; 191 ActivityLogPolicy::PolicyType database_policy_type_;
182 192
183 Profile* profile_; 193 Profile* profile_;
194
195 ExtensionSystem* extension_system_;
196
184 bool db_enabled_; // Whether logging to disk is currently enabled. 197 bool db_enabled_; // Whether logging to disk is currently enabled.
185 // testing_mode_ controls which policy is selected. 198 // testing_mode_ controls which policy is selected.
186 // * By default, we choose a policy that doesn't log most arguments to avoid 199 // * By default, we choose a policy that doesn't log most arguments to avoid
187 // saving too much data. We also elide some arguments for privacy reasons. 200 // saving too much data. We also elide some arguments for privacy reasons.
188 // * In testing mode, we choose a policy that logs all arguments. 201 // * In testing mode, we choose a policy that logs all arguments.
189 // testing_mode_ also causes us to print to the console. 202 // testing_mode_ also causes us to print to the console.
190 bool testing_mode_; 203 bool testing_mode_;
191 // We need the DB, FILE, and IO threads to write to the database. 204 // We need the DB, FILE, and IO threads to write to the database.
192 // In some cases (tests), these threads might not exist, so we avoid 205 // In some cases (tests), these threads might not exist, so we avoid
193 // dispatching anything to the policies/database to prevent things from 206 // dispatching anything to the policies/database to prevent things from
194 // exploding. 207 // exploding.
195 bool has_threads_; 208 bool has_threads_;
196 209
197 // Used to track whether the whitelisted extension is installed. If it's 210 // Used to track whether the whitelisted extension is installed. If it's
198 // added or removed, enabled_ may change. 211 // added or removed, enabled_ may change.
199 ScopedObserver<extensions::ExtensionRegistry, 212 ScopedObserver<extensions::ExtensionRegistry,
200 extensions::ExtensionRegistryObserver> 213 extensions::ExtensionRegistryObserver>
201 extension_registry_observer_; 214 extension_registry_observer_;
202 215
203 // Set if the watchdog app is installed and enabled. Maintained by 216 // The number of active consumers of the activity log.
204 // kWatchdogExtensionActive pref variable. Since there are multiple valid 217 int active_consumers_;
205 // extension IDs, this needs to be an int to count how many are installed. 218
206 int watchdog_apps_active_; 219 // The cached number of consumers of the activity log. Maintained by the
220 // kWatchdogExtensionActive pref variable, and updated on startup. We cache
221 // the result so that we can record extension actions that happen before
222 // all extensions have finished loading.
223 int cached_consumer_count_;
207 224
208 // True if the activity log is currently active, meaning that the user has 225 // True if the activity log is currently active, meaning that the user has
209 // either added the commandline switch or has loaded a compatible extension. 226 // either added the commandline switch or has loaded a compatible extension.
210 // While inactive, the activity log will not store any actions for performance 227 // While inactive, the activity log will not store any actions for performance
211 // reasons. 228 // reasons.
212 bool is_active_; 229 bool is_active_;
213 230
214 content::NotificationRegistrar registrar_; 231 content::NotificationRegistrar registrar_;
215 232
233 base::WeakPtrFactory<ActivityLog> weak_factory_;
234
216 FRIEND_TEST_ALL_PREFIXES(ActivityLogApiTest, TriggerEvent); 235 FRIEND_TEST_ALL_PREFIXES(ActivityLogApiTest, TriggerEvent);
217 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, AppAndCommandLine); 236 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, AppAndCommandLine);
218 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, CommandLineSwitch); 237 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, CommandLineSwitch);
219 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, NoSwitch); 238 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, NoSwitch);
220 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, PrefSwitch); 239 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, PrefSwitch);
221 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, WatchdogSwitch); 240 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, WatchdogSwitch);
222 DISALLOW_COPY_AND_ASSIGN(ActivityLog); 241 DISALLOW_COPY_AND_ASSIGN(ActivityLog);
223 }; 242 };
224 243
225 template <> 244 template <>
226 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies(); 245 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies();
227 246
228 } // namespace extensions 247 } // namespace extensions
229 248
230 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ 249 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/activity_log/activity_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698