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

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

Issue 23729005: Enable Activity Logging by default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added definition of 'active' Created 7 years, 3 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // observer: the activityLogPrivate API. 47 // observer: the activityLogPrivate API.
48 class Observer { 48 class Observer {
49 public: 49 public:
50 virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0; 50 virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0;
51 }; 51 };
52 52
53 // ActivityLog is a singleton, so don't instantiate it with the constructor; 53 // ActivityLog is a singleton, so don't instantiate it with the constructor;
54 // use GetInstance instead. 54 // use GetInstance instead.
55 static ActivityLog* GetInstance(Profile* profile); 55 static ActivityLog* GetInstance(Profile* profile);
56 56
57 // Specifies if AL was enabled at least for one profile. We use this method to
58 // check if AL possibly enabled when a profile is not available, e.g., when
59 // executing on thread other than UI.
60 static bool IsLogEnabledOnAnyProfile();
61
62 // Provides up-to-date information about whether the AL is enabled for a
63 // profile. The AL is enabled if the user has installed the whitelisted
64 // AL extension *or* set the --enable-extension-activity-logging flag.
65 bool IsLogEnabled();
66
67 // Add/remove observer: the activityLogPrivate API only listens when the 57 // Add/remove observer: the activityLogPrivate API only listens when the
68 // ActivityLog extension is registered for an event. 58 // ActivityLog extension is registered for an event.
69 void AddObserver(Observer* observer); 59 void AddObserver(Observer* observer);
70 void RemoveObserver(Observer* observer); 60 void RemoveObserver(Observer* observer);
71 61
72 // Logs an extension action: passes it to any installed policy to be logged 62 // Logs an extension action: passes it to any installed policy to be logged
73 // to the database, to any observers, and logs to the console if in testing 63 // to the database, to any observers, and logs to the console if in testing
74 // mode. 64 // mode.
75 void LogAction(scoped_refptr<Action> action); 65 void LogAction(scoped_refptr<Action> action);
76 66
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 virtual void RemoveURL(const GURL& url); 120 virtual void RemoveURL(const GURL& url);
131 121
132 private: 122 private:
133 friend class ActivityLogFactory; 123 friend class ActivityLogFactory;
134 friend class ActivityLogTest; 124 friend class ActivityLogTest;
135 friend class RenderViewActivityLogTest; 125 friend class RenderViewActivityLogTest;
136 126
137 explicit ActivityLog(Profile* profile); 127 explicit ActivityLog(Profile* profile);
138 virtual ~ActivityLog(); 128 virtual ~ActivityLog();
139 129
130 // Specifies if the Watchdog app is active (installed & enabled).
131 // If so, we need to log to the database and stream to the API.
132 bool IsWatchdogAppActive();
133 // If we're in a browser test, we need to pretend that the watchdog app is
134 // active.
135 void SetWatchdogAppActive(bool active);
136
137 // Specifies if we need to record actions to the db. If so, we need to log to
138 // the database. This is true if the Watchdog app is active *or* the
139 // --enable-extension-activity-logging flag is set.
140 bool IsDatabaseEnabled();
141
140 // Delayed initialization of Install Tracker which waits until after the 142 // Delayed initialization of Install Tracker which waits until after the
141 // ExtensionSystem/ExtensionService are done with their own setup. 143 // ExtensionSystem/ExtensionService are done with their own setup.
142 void InitInstallTracker(); 144 void InitInstallTracker();
143 145
144 // TabHelper::ScriptExecutionObserver implementation. 146 // TabHelper::ScriptExecutionObserver implementation.
145 // Fires when a ContentScript is executed. 147 // Fires when a ContentScript is executed.
146 virtual void OnScriptsExecuted( 148 virtual void OnScriptsExecuted(
147 const content::WebContents* web_contents, 149 const content::WebContents* web_contents,
148 const ExecutingScriptsMap& extension_ids, 150 const ExecutingScriptsMap& extension_ids,
149 int32 page_id, 151 int32 page_id,
150 const GURL& on_url) OVERRIDE; 152 const GURL& on_url) OVERRIDE;
151 153
152 // At the moment, ActivityLog will use only one policy for summarization. 154 // At the moment, ActivityLog will use only one policy for summarization.
153 // 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.
156 // Changing policies at runtime is not recommended, and likely only should be
157 // done for unit tests.
154 void ChooseDefaultPolicy(); 158 void ChooseDefaultPolicy();
155 void SetDefaultPolicy(ActivityLogPolicy::PolicyType policy_type); 159 void SetDefaultPolicy(ActivityLogPolicy::PolicyType policy_type);
156 160
157 typedef ObserverListThreadSafe<Observer> ObserverList; 161 typedef ObserverListThreadSafe<Observer> ObserverList;
158 scoped_refptr<ObserverList> observers_; 162 scoped_refptr<ObserverList> observers_;
159 163
160 // The policy object takes care of data summarization, compression, and 164 // The policy object takes care of data summarization, compression, and
161 // logging. The policy object is owned by the ActivityLog, but this cannot 165 // logging. The policy object is owned by the ActivityLog, but this cannot
162 // be a scoped_ptr since some cleanup work must happen on the database 166 // be a scoped_ptr since some cleanup work must happen on the database
163 // thread. Calling policy_->Close() will free the object; see the comments 167 // thread. Calling policy_->Close() will free the object; see the comments
164 // on the ActivityDatabase class for full details. 168 // on the ActivityDatabase class for full details.
165 ActivityLogPolicy* policy_; 169 ActivityLogPolicy* policy_;
166 170
167 // TODO(dbabic,felt) change this into a list of policy types later. 171 // TODO(dbabic,felt) change this into a list of policy types later.
168 ActivityLogPolicy::PolicyType policy_type_; 172 ActivityLogPolicy::PolicyType policy_type_;
169 173
170 Profile* profile_; 174 Profile* profile_;
171 bool enabled_; // Whether logging is currently enabled. 175 bool db_enabled_; // Whether logging to disk is currently enabled.
172 bool policy_chosen_; // Whether we've already set the default policy. 176 // testing_mode_ controls which policy is selected.
173 // testing_mode_ controls whether to log API call arguments. By default, we 177 // * By default, we choose a policy that doesn't log most arguments to avoid
174 // don't log most arguments to avoid saving too much data. In testing mode, 178 // saving too much data. We also elide some arguments for privacy reasons.
175 // argument collection is enabled. We also whitelist some arguments for 179 // * In testing mode, we choose a policy that logs all arguments.
176 // collection regardless of whether this bool is true. 180 // testing_mode_ also causes us to print to the console.
177 // When testing_mode_ is enabled, we also print to the console.
178 bool testing_mode_; 181 bool testing_mode_;
179 // We need the DB, FILE, and IO threads to operate. In some cases (tests), 182 // We need the DB, FILE, and IO threads to write to the database.
180 // these threads might not exist, so we avoid dispatching anything to the 183 // In some cases (tests), these threads might not exist, so we avoid
181 // ActivityDatabase to prevent things from exploding. 184 // dispatching anything to the policies/database to prevent things from
185 // exploding.
182 bool has_threads_; 186 bool has_threads_;
183 187
184 // Used to track whether the whitelisted extension is installed. If it's 188 // Used to track whether the whitelisted extension is installed. If it's
185 // added or removed, enabled_ may change. 189 // added or removed, enabled_ may change.
186 InstallTracker* tracker_; 190 InstallTracker* tracker_;
187 191
188 // Set if the watchdog extension is present and active. Maintained by 192 // Set if the watchdog app is installed and enabled. Maintained by
189 // kWatchdogExtensionActive pref variable. 193 // kWatchdogExtensionActive pref variable.
190 bool watchdog_extension_active_; 194 bool watchdog_app_active_;
191 195
192 // Specifies if AL was enabled at least for one profile. 196 FRIEND_TEST_ALL_PREFIXES(ActivityLogApiTest, TriggerEvent);
193 static bool enabled_on_any_profile_; 197 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, AppAndCommandLine);
194 198 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, CommandLineSwitch);
199 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, NoSwitch);
200 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, PrefSwitch);
201 FRIEND_TEST_ALL_PREFIXES(ActivityLogEnabledTest, WatchdogSwitch);
195 DISALLOW_COPY_AND_ASSIGN(ActivityLog); 202 DISALLOW_COPY_AND_ASSIGN(ActivityLog);
196 }; 203 };
197 204
198 // Each profile has different extensions, so we keep a different database for 205 // Each profile has different extensions, so we keep a different database for
199 // each profile. 206 // each profile.
200 class ActivityLogFactory : public BrowserContextKeyedServiceFactory { 207 class ActivityLogFactory : public BrowserContextKeyedServiceFactory {
201 public: 208 public:
202 static ActivityLog* GetForProfile(Profile* profile) { 209 static ActivityLog* GetForProfile(Profile* profile) {
203 return static_cast<ActivityLog*>( 210 return static_cast<ActivityLog*>(
204 GetInstance()->GetServiceForBrowserContext(profile, true)); 211 GetInstance()->GetServiceForBrowserContext(profile, true));
(...skipping 12 matching lines...) Expand all
217 virtual content::BrowserContext* GetBrowserContextToUse( 224 virtual content::BrowserContext* GetBrowserContextToUse(
218 content::BrowserContext* context) const OVERRIDE; 225 content::BrowserContext* context) const OVERRIDE;
219 226
220 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); 227 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory);
221 }; 228 };
222 229
223 230
224 } // namespace extensions 231 } // namespace extensions
225 232
226 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ 233 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698