Chromium Code Reviews| Index: chrome/browser/extensions/activity_log/activity_log.cc | 
| diff --git a/chrome/browser/extensions/activity_log/activity_log.cc b/chrome/browser/extensions/activity_log/activity_log.cc | 
| index 7eac24f596c1e10fd2aff8f89cfc5872aae5b042..bc8c38be1a7ad28d3fc79ef6ac9cd9cfe1a3d386 100644 | 
| --- a/chrome/browser/extensions/activity_log/activity_log.cc | 
| +++ b/chrome/browser/extensions/activity_log/activity_log.cc | 
| @@ -18,12 +18,14 @@ | 
| #include "chrome/browser/extensions/extension_system.h" | 
| #include "chrome/browser/extensions/extension_system_factory.h" | 
| #include "chrome/browser/extensions/install_tracker_factory.h" | 
| +#include "chrome/browser/prefs/pref_service_syncable.h" | 
| #include "chrome/browser/prerender/prerender_manager.h" | 
| #include "chrome/browser/prerender/prerender_manager_factory.h" | 
| #include "chrome/browser/profiles/incognito_helpers.h" | 
| #include "chrome/common/chrome_constants.h" | 
| #include "chrome/common/chrome_switches.h" | 
| #include "chrome/common/extensions/extension.h" | 
| +#include "chrome/common/pref_names.h" | 
| #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" | 
| #include "content/public/browser/web_contents.h" | 
| #include "third_party/re2/re2/re2.h" | 
| @@ -163,16 +165,20 @@ ActivityLog::ActivityLog(Profile* profile) | 
| policy_type_(ActivityLogPolicy::POLICY_INVALID), | 
| profile_(profile), | 
| enabled_(false), | 
| - initialized_(false), | 
| policy_chosen_(false), | 
| testing_mode_(false), | 
| has_threads_(true), | 
| - tracker_(NULL) { | 
| + tracker_(NULL), | 
| + activity_log_extension_active_(false) { | 
| 
 
felt
2013/07/18 22:11:37
nit: can you also replace "activity_log" with "wat
 
pmarch
2013/07/19 02:41:54
Done.
 
 | 
| // This controls whether logging statements are printed, which policy is set, | 
| // etc. | 
| testing_mode_ = CommandLine::ForCurrentProcess()->HasSwitch( | 
| switches::kEnableExtensionActivityLogTesting); | 
| + // Check if the activity log extension is previously installed and active. | 
| + activity_log_extension_active_ = | 
| + profile_->GetPrefs()->GetBoolean(prefs::kActivityLogExtensionActive); | 
| + | 
| // Check that the right threads exist. If not, we shouldn't try to do things | 
| // that require them. | 
| if (!BrowserThread::IsMessageLoopValid(BrowserThread::DB) || | 
| @@ -180,28 +186,27 @@ ActivityLog::ActivityLog(Profile* profile) | 
| !BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { | 
| LOG(ERROR) << "Missing threads, disabling Activity Logging!"; | 
| has_threads_ = false; | 
| - } else { | 
| - enabled_ = IsLogEnabledOnAnyProfile(); | 
| - ExtensionSystem::Get(profile_)->ready().Post( | 
| - FROM_HERE, base::Bind(&ActivityLog::Init, base::Unretained(this))); | 
| + return; | 
| } | 
| + // Check if we have the --enable-extension-activity-logging flag, or the | 
| + // activity logger is enabled on any profile. | 
| + enabled_ = IsLogEnabledOnAnyProfile(); | 
| observers_ = new ObserverListThreadSafe<Observer>; | 
| -} | 
| -void ActivityLog::Init() { | 
| - DCHECK(has_threads_); | 
| - DCHECK(!initialized_); | 
| - const Extension* whitelisted_extension = ExtensionSystem::Get(profile_)-> | 
| - extension_service()->GetExtensionById(kActivityLogExtensionId, false); | 
| - if (whitelisted_extension) { | 
| + if (activity_log_extension_active_) { | 
| enabled_ = true; | 
| LogIsEnabled::GetInstance()->SetProfileEnabled(true); | 
| } | 
| + ExtensionSystem::Get(profile_)->ready().Post( | 
| + FROM_HERE, | 
| + base::Bind(&ActivityLog::InitInstallTracker, base::Unretained(this))); | 
| + ChooseDefaultPolicy(); | 
| +} | 
| + | 
| +void ActivityLog::InitInstallTracker() { | 
| tracker_ = InstallTrackerFactory::GetForProfile(profile_); | 
| tracker_->AddObserver(this); | 
| - ChooseDefaultPolicy(); | 
| - initialized_ = true; | 
| } | 
| void ActivityLog::ChooseDefaultPolicy() { | 
| @@ -222,22 +227,35 @@ ActivityLog::~ActivityLog() { | 
| } | 
| bool ActivityLog::IsLogEnabled() { | 
| - if (!has_threads_ || !initialized_) return false; | 
| + // Make sure we are not enabled when there are no threads. | 
| + DCHECK(has_threads_ || !enabled_); | 
| return enabled_; | 
| } | 
| void ActivityLog::OnExtensionLoaded(const Extension* extension) { | 
| if (extension->id() != kActivityLogExtensionId) return; | 
| - enabled_ = true; | 
| + if (has_threads_) | 
| + enabled_ = true; | 
| + if (!activity_log_extension_active_) { | 
| + activity_log_extension_active_ = true; | 
| + profile_->GetPrefs()->SetBoolean(prefs::kActivityLogExtensionActive, true); | 
| + } | 
| LogIsEnabled::GetInstance()->SetProfileEnabled(true); | 
| ChooseDefaultPolicy(); | 
| } | 
| void ActivityLog::OnExtensionUnloaded(const Extension* extension) { | 
| if (extension->id() != kActivityLogExtensionId) return; | 
| + // Make sure we are not enabled when there are no threads. | 
| + DCHECK(has_threads_ || !enabled_); | 
| if (!CommandLine::ForCurrentProcess()->HasSwitch( | 
| switches::kEnableExtensionActivityLogging)) | 
| enabled_ = false; | 
| + if (activity_log_extension_active_) { | 
| + activity_log_extension_active_ = false; | 
| + profile_->GetPrefs()->SetBoolean(prefs::kActivityLogExtensionActive, | 
| + false); | 
| + } | 
| } | 
| // static | 
| @@ -511,4 +529,13 @@ void ActivityLog::OnScriptsExecuted( | 
| } | 
| } | 
| +// static | 
| +void ActivityLog::RegisterProfilePrefs( | 
| + user_prefs::PrefRegistrySyncable* registry) { | 
| + registry->RegisterBooleanPref( | 
| + prefs::kActivityLogExtensionActive, | 
| + false, | 
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 
| +} | 
| + | 
| } // namespace extensions |