| OLD | NEW |
| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/common/extensions/dom_action_types.h" | 24 #include "chrome/common/extensions/dom_action_types.h" |
| 25 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 25 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 26 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 26 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 27 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 27 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" |
| 28 | 28 |
| 29 class Profile; | 29 class Profile; |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace user_prefs { |
| 33 class PrefRegistrySyncable; |
| 34 } |
| 35 |
| 32 namespace extensions { | 36 namespace extensions { |
| 33 class Extension; | 37 class Extension; |
| 34 class ActivityLogPolicy; | 38 class ActivityLogPolicy; |
| 35 | 39 |
| 36 // A utility for tracing interesting activity for each extension. | 40 // A utility for tracing interesting activity for each extension. |
| 37 // It writes to an ActivityDatabase on a separate thread to record the activity. | 41 // It writes to an ActivityDatabase on a separate thread to record the activity. |
| 38 class ActivityLog : public BrowserContextKeyedService, | 42 class ActivityLog : public BrowserContextKeyedService, |
| 39 public TabHelper::ScriptExecutionObserver, | 43 public TabHelper::ScriptExecutionObserver, |
| 40 public InstallObserver { | 44 public InstallObserver { |
| 41 public: | 45 public: |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 int percent_downloaded) OVERRIDE {} | 142 int percent_downloaded) OVERRIDE {} |
| 139 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE {} | 143 virtual void OnInstallFailure(const std::string& extension_id) OVERRIDE {} |
| 140 virtual void OnAppsReordered() OVERRIDE {} | 144 virtual void OnAppsReordered() OVERRIDE {} |
| 141 virtual void OnAppInstalledToAppList( | 145 virtual void OnAppInstalledToAppList( |
| 142 const std::string& extension_id) OVERRIDE {} | 146 const std::string& extension_id) OVERRIDE {} |
| 143 virtual void OnShutdown() OVERRIDE {} | 147 virtual void OnShutdown() OVERRIDE {} |
| 144 | 148 |
| 145 // BrowserContextKeyedService | 149 // BrowserContextKeyedService |
| 146 virtual void Shutdown() OVERRIDE; | 150 virtual void Shutdown() OVERRIDE; |
| 147 | 151 |
| 152 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 153 |
| 148 private: | 154 private: |
| 149 friend class ActivityLogFactory; | 155 friend class ActivityLogFactory; |
| 150 friend class ActivityLogTest; | 156 friend class ActivityLogTest; |
| 151 friend class RenderViewActivityLogTest; | 157 friend class RenderViewActivityLogTest; |
| 152 | 158 |
| 153 explicit ActivityLog(Profile* profile); | 159 explicit ActivityLog(Profile* profile); |
| 154 virtual ~ActivityLog(); | 160 virtual ~ActivityLog(); |
| 155 | 161 |
| 156 // Some setup needs to wait until after the ExtensionSystem/ExtensionService | 162 // Delayed initialization of Install Tracker which waits until after the |
| 157 // are done with their own setup. | 163 // ExtensionSystem/ExtensionService are done with their own setup. |
| 158 void Init(); | 164 void InitInstallTracker(); |
| 159 | 165 |
| 160 // We log callbacks and API calls very similarly, so we handle them the same | 166 // We log callbacks and API calls very similarly, so we handle them the same |
| 161 // way internally. | 167 // way internally. |
| 162 void LogAPIActionInternal( | 168 void LogAPIActionInternal( |
| 163 const std::string& extension_id, | 169 const std::string& extension_id, |
| 164 const std::string& api_call, | 170 const std::string& api_call, |
| 165 base::ListValue* args, | 171 base::ListValue* args, |
| 166 const std::string& extra, | 172 const std::string& extra, |
| 167 const APIAction::Type type); | 173 const APIAction::Type type); |
| 168 | 174 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 191 // be a scoped_ptr since some cleanup work must happen on the database | 197 // be a scoped_ptr since some cleanup work must happen on the database |
| 192 // thread. Calling policy_->Close() will free the object; see the comments | 198 // thread. Calling policy_->Close() will free the object; see the comments |
| 193 // on the ActivityDatabase class for full details. | 199 // on the ActivityDatabase class for full details. |
| 194 extensions::ActivityLogPolicy* policy_; | 200 extensions::ActivityLogPolicy* policy_; |
| 195 | 201 |
| 196 // TODO(dbabic,felt) change this into a list of policy types later. | 202 // TODO(dbabic,felt) change this into a list of policy types later. |
| 197 ActivityLogPolicy::PolicyType policy_type_; | 203 ActivityLogPolicy::PolicyType policy_type_; |
| 198 | 204 |
| 199 Profile* profile_; | 205 Profile* profile_; |
| 200 bool enabled_; // Whether logging is currently enabled. | 206 bool enabled_; // Whether logging is currently enabled. |
| 201 bool initialized_; // Whether Init() has already been called. | |
| 202 bool policy_chosen_; // Whether we've already set the default policy. | 207 bool policy_chosen_; // Whether we've already set the default policy. |
| 203 // testing_mode_ controls whether to log API call arguments. By default, we | 208 // testing_mode_ controls whether to log API call arguments. By default, we |
| 204 // don't log most arguments to avoid saving too much data. In testing mode, | 209 // don't log most arguments to avoid saving too much data. In testing mode, |
| 205 // argument collection is enabled. We also whitelist some arguments for | 210 // argument collection is enabled. We also whitelist some arguments for |
| 206 // collection regardless of whether this bool is true. | 211 // collection regardless of whether this bool is true. |
| 207 // When testing_mode_ is enabled, we also print to the console. | 212 // When testing_mode_ is enabled, we also print to the console. |
| 208 bool testing_mode_; | 213 bool testing_mode_; |
| 209 // We need the DB, FILE, and IO threads to operate. In some cases (tests), | 214 // We need the DB, FILE, and IO threads to operate. In some cases (tests), |
| 210 // these threads might not exist, so we avoid dispatching anything to the | 215 // these threads might not exist, so we avoid dispatching anything to the |
| 211 // ActivityDatabase to prevent things from exploding. | 216 // ActivityDatabase to prevent things from exploding. |
| 212 bool has_threads_; | 217 bool has_threads_; |
| 213 | 218 |
| 214 // Used to track whether the whitelisted extension is installed. If it's | 219 // Used to track whether the whitelisted extension is installed. If it's |
| 215 // added or removed, enabled_ may change. | 220 // added or removed, enabled_ may change. |
| 216 InstallTracker* tracker_; | 221 InstallTracker* tracker_; |
| 217 | 222 |
| 223 // Set if the ActivityLog extension is present and active. Maintained by |
| 224 // kActivityLogExtensionActive pref variable. |
| 225 bool activity_log_extension_active_; |
| 226 |
| 218 DISALLOW_COPY_AND_ASSIGN(ActivityLog); | 227 DISALLOW_COPY_AND_ASSIGN(ActivityLog); |
| 219 }; | 228 }; |
| 220 | 229 |
| 221 // Each profile has different extensions, so we keep a different database for | 230 // Each profile has different extensions, so we keep a different database for |
| 222 // each profile. | 231 // each profile. |
| 223 class ActivityLogFactory : public BrowserContextKeyedServiceFactory { | 232 class ActivityLogFactory : public BrowserContextKeyedServiceFactory { |
| 224 public: | 233 public: |
| 225 static ActivityLog* GetForProfile(Profile* profile) { | 234 static ActivityLog* GetForProfile(Profile* profile) { |
| 226 return static_cast<ActivityLog*>( | 235 return static_cast<ActivityLog*>( |
| 227 GetInstance()->GetServiceForBrowserContext(profile, true)); | 236 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 240 virtual content::BrowserContext* GetBrowserContextToUse( | 249 virtual content::BrowserContext* GetBrowserContextToUse( |
| 241 content::BrowserContext* context) const OVERRIDE; | 250 content::BrowserContext* context) const OVERRIDE; |
| 242 | 251 |
| 243 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); | 252 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); |
| 244 }; | 253 }; |
| 245 | 254 |
| 246 | 255 |
| 247 } // namespace extensions | 256 } // namespace extensions |
| 248 | 257 |
| 249 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ | 258 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ |
| OLD | NEW |