Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <set> | 5 #include <set> |
| 6 #include <vector> | 6 #include <vector> |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "chrome/browser/extensions/activity_log/activity_log.h" | 12 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 13 #include "chrome/browser/extensions/activity_log/api_actions.h" | 13 #include "chrome/browser/extensions/activity_log/api_actions.h" |
| 14 #include "chrome/browser/extensions/activity_log/blocked_actions.h" | 14 #include "chrome/browser/extensions/activity_log/blocked_actions.h" |
| 15 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h" | 15 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h" |
| 16 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" | 16 #include "chrome/browser/extensions/api/activity_log_private/activity_log_privat e_api.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_system_factory.h" | 19 #include "chrome/browser/extensions/extension_system_factory.h" |
| 20 #include "chrome/browser/extensions/install_tracker_factory.h" | 20 #include "chrome/browser/extensions/install_tracker_factory.h" |
| 21 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 21 #include "chrome/browser/prerender/prerender_manager.h" | 22 #include "chrome/browser/prerender/prerender_manager.h" |
| 22 #include "chrome/browser/prerender/prerender_manager_factory.h" | 23 #include "chrome/browser/prerender/prerender_manager_factory.h" |
| 23 #include "chrome/browser/profiles/incognito_helpers.h" | 24 #include "chrome/browser/profiles/incognito_helpers.h" |
| 24 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 28 #include "chrome/common/pref_names.h" | |
| 27 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | 29 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" |
| 28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 29 #include "third_party/re2/re2/re2.h" | 31 #include "third_party/re2/re2/re2.h" |
| 30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // Concatenate arguments. | 36 // Concatenate arguments. |
| 35 std::string MakeArgList(const base::ListValue* args) { | 37 std::string MakeArgList(const base::ListValue* args) { |
| 36 std::string call_signature; | 38 std::string call_signature; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 policy_type_ = policy_type; | 158 policy_type_ = policy_type; |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 | 161 |
| 160 // Use GetInstance instead of directly creating an ActivityLog. | 162 // Use GetInstance instead of directly creating an ActivityLog. |
| 161 ActivityLog::ActivityLog(Profile* profile) | 163 ActivityLog::ActivityLog(Profile* profile) |
| 162 : policy_(NULL), | 164 : policy_(NULL), |
| 163 policy_type_(ActivityLogPolicy::POLICY_INVALID), | 165 policy_type_(ActivityLogPolicy::POLICY_INVALID), |
| 164 profile_(profile), | 166 profile_(profile), |
| 165 enabled_(false), | 167 enabled_(false), |
| 166 initialized_(false), | |
| 167 policy_chosen_(false), | 168 policy_chosen_(false), |
| 168 testing_mode_(false), | 169 testing_mode_(false), |
| 169 has_threads_(true), | 170 tracker_(NULL), |
| 170 tracker_(NULL) { | 171 activity_log_extension_enabled_(false) { |
| 171 // This controls whether logging statements are printed, which policy is set, | 172 // This controls whether logging statements are printed, which policy is set, |
| 172 // etc. | 173 // etc. |
| 173 testing_mode_ = CommandLine::ForCurrentProcess()->HasSwitch( | 174 testing_mode_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 174 switches::kEnableExtensionActivityLogTesting); | 175 switches::kEnableExtensionActivityLogTesting); |
| 175 | 176 |
| 177 activity_log_extension_enabled_ = | |
|
felt
2013/07/18 20:42:03
Can you also add a comment here documenting what t
pmarch
2013/07/18 21:37:14
Done.
| |
| 178 profile_->GetPrefs()->GetBoolean(prefs::kActivityLogExtensionEnabled); | |
| 179 | |
| 176 // Check that the right threads exist. If not, we shouldn't try to do things | 180 // Check that the right threads exist. If not, we shouldn't try to do things |
| 177 // that require them. | 181 // that require them. |
| 178 if (!BrowserThread::IsMessageLoopValid(BrowserThread::DB) || | 182 if (!BrowserThread::IsMessageLoopValid(BrowserThread::DB) || |
| 179 !BrowserThread::IsMessageLoopValid(BrowserThread::FILE) || | 183 !BrowserThread::IsMessageLoopValid(BrowserThread::FILE) || |
| 180 !BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 184 !BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { |
| 181 LOG(ERROR) << "Missing threads, disabling Activity Logging!"; | 185 LOG(ERROR) << "Missing threads, disabling Activity Logging!"; |
| 182 has_threads_ = false; | 186 return; |
|
felt
2013/07/18 20:42:03
What if the extension is installed later, causing
pmarch
2013/07/18 21:37:14
nice catch, thanks
| |
| 183 } else { | |
| 184 enabled_ = IsLogEnabledOnAnyProfile(); | |
| 185 ExtensionSystem::Get(profile_)->ready().Post( | |
| 186 FROM_HERE, base::Bind(&ActivityLog::Init, base::Unretained(this))); | |
| 187 } | 187 } |
| 188 | 188 |
| 189 enabled_ = IsLogEnabledOnAnyProfile(); | |
|
felt
2013/07/18 20:42:03
And another comment here specifying that this is c
pmarch
2013/07/18 21:37:14
Done.
| |
| 189 observers_ = new ObserverListThreadSafe<Observer>; | 190 observers_ = new ObserverListThreadSafe<Observer>; |
| 190 } | |
| 191 | 191 |
| 192 void ActivityLog::Init() { | 192 if (activity_log_extension_enabled_) { |
| 193 DCHECK(has_threads_); | |
| 194 DCHECK(!initialized_); | |
| 195 const Extension* whitelisted_extension = ExtensionSystem::Get(profile_)-> | |
| 196 extension_service()->GetExtensionById(kActivityLogExtensionId, false); | |
| 197 if (whitelisted_extension) { | |
| 198 enabled_ = true; | 193 enabled_ = true; |
| 199 LogIsEnabled::GetInstance()->SetProfileEnabled(true); | 194 LogIsEnabled::GetInstance()->SetProfileEnabled(true); |
| 200 } | 195 } |
| 196 ExtensionSystem::Get(profile_)->ready().Post( | |
| 197 FROM_HERE, | |
| 198 base::Bind(&ActivityLog::InitInstallTracker, base::Unretained(this))); | |
| 199 ChooseDefaultPolicy(); | |
| 200 } | |
| 201 | |
| 202 void ActivityLog::InitInstallTracker() { | |
| 201 tracker_ = InstallTrackerFactory::GetForProfile(profile_); | 203 tracker_ = InstallTrackerFactory::GetForProfile(profile_); |
| 202 tracker_->AddObserver(this); | 204 tracker_->AddObserver(this); |
| 203 ChooseDefaultPolicy(); | |
| 204 initialized_ = true; | |
| 205 } | 205 } |
| 206 | 206 |
| 207 void ActivityLog::ChooseDefaultPolicy() { | 207 void ActivityLog::ChooseDefaultPolicy() { |
| 208 if (policy_chosen_ || !enabled_) return; | 208 if (policy_chosen_ || !enabled_) return; |
| 209 if (testing_mode_) | 209 if (testing_mode_) |
| 210 SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); | 210 SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); |
| 211 else | 211 else |
| 212 SetDefaultPolicy(ActivityLogPolicy::POLICY_NOARGS); | 212 SetDefaultPolicy(ActivityLogPolicy::POLICY_NOARGS); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void ActivityLog::Shutdown() { | 215 void ActivityLog::Shutdown() { |
| 216 if (tracker_) tracker_->RemoveObserver(this); | 216 if (tracker_) tracker_->RemoveObserver(this); |
| 217 } | 217 } |
| 218 | 218 |
| 219 ActivityLog::~ActivityLog() { | 219 ActivityLog::~ActivityLog() { |
| 220 if (policy_) | 220 if (policy_) |
| 221 policy_->Close(); | 221 policy_->Close(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool ActivityLog::IsLogEnabled() { | 224 bool ActivityLog::IsLogEnabled() { |
| 225 if (!has_threads_ || !initialized_) return false; | |
| 226 return enabled_; | 225 return enabled_; |
| 227 } | 226 } |
| 228 | 227 |
| 229 void ActivityLog::OnExtensionLoaded(const Extension* extension) { | 228 void ActivityLog::OnExtensionLoaded(const Extension* extension) { |
| 230 if (extension->id() != kActivityLogExtensionId) return; | 229 if (extension->id() != kActivityLogExtensionId) return; |
| 231 enabled_ = true; | 230 enabled_ = true; |
| 231 if (!activity_log_extension_enabled_) { | |
| 232 activity_log_extension_enabled_ = true; | |
| 233 profile_->GetPrefs()->SetBoolean(prefs::kActivityLogExtensionEnabled, true); | |
| 234 } | |
| 232 LogIsEnabled::GetInstance()->SetProfileEnabled(true); | 235 LogIsEnabled::GetInstance()->SetProfileEnabled(true); |
| 233 ChooseDefaultPolicy(); | 236 ChooseDefaultPolicy(); |
| 234 } | 237 } |
| 235 | 238 |
| 236 void ActivityLog::OnExtensionUnloaded(const Extension* extension) { | 239 void ActivityLog::OnExtensionUnloaded(const Extension* extension) { |
| 237 if (extension->id() != kActivityLogExtensionId) return; | 240 if (extension->id() != kActivityLogExtensionId) return; |
| 238 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 241 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 239 switches::kEnableExtensionActivityLogging)) | 242 switches::kEnableExtensionActivityLogging)) |
| 240 enabled_ = false; | 243 enabled_ = false; |
| 244 if (activity_log_extension_enabled_) { | |
| 245 activity_log_extension_enabled_ = false; | |
| 246 profile_->GetPrefs()->SetBoolean(prefs::kActivityLogExtensionEnabled, | |
| 247 false); | |
| 248 } | |
| 241 } | 249 } |
| 242 | 250 |
| 243 // static | 251 // static |
| 244 ActivityLog* ActivityLog::GetInstance(Profile* profile) { | 252 ActivityLog* ActivityLog::GetInstance(Profile* profile) { |
| 245 return ActivityLogFactory::GetForProfile(profile); | 253 return ActivityLogFactory::GetForProfile(profile); |
| 246 } | 254 } |
| 247 | 255 |
| 248 void ActivityLog::AddObserver(ActivityLog::Observer* observer) { | 256 void ActivityLog::AddObserver(ActivityLog::Observer* observer) { |
| 249 observers_->AddObserver(observer); | 257 observers_->AddObserver(observer); |
| 250 } | 258 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 on_url, | 512 on_url, |
| 505 web_contents->GetTitle(), | 513 web_contents->GetTitle(), |
| 506 std::string(), // no api call here | 514 std::string(), // no api call here |
| 507 script_names.get(), | 515 script_names.get(), |
| 508 DomActionType::INSERTED, | 516 DomActionType::INSERTED, |
| 509 extra); | 517 extra); |
| 510 } | 518 } |
| 511 } | 519 } |
| 512 } | 520 } |
| 513 | 521 |
| 522 // static | |
| 523 void ActivityLog::RegisterProfilePrefs( | |
| 524 user_prefs::PrefRegistrySyncable* registry) { | |
| 525 registry->RegisterBooleanPref( | |
| 526 prefs::kActivityLogExtensionEnabled, | |
| 527 false, | |
| 528 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | |
| 529 } | |
| 530 | |
| 514 } // namespace extensions | 531 } // namespace extensions |
| OLD | NEW |