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

Unified Diff: chrome/browser/extensions/activity_log/activity_log.cc

Issue 18430004: Sets correct ActivityLog enabled status to the first renderer process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
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 4233e12ac192dbb6c77bb553907a690b6bbcda0f..e9246209312eb6871a446a21a552a9070ba1e6b4 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"
@@ -47,59 +49,10 @@ std::string MakeArgList(const base::ListValue* args) {
return call_signature;
}
-// This is a hack for AL callers who don't have access to a profile object
-// when deciding whether or not to do the work required for logging. The state
-// is accessed through the static ActivityLog::IsLogEnabledOnAnyProfile()
-// method. It returns true if --enable-extension-activity-logging is set on the
-// command line OR *ANY* profile has the activity log whitelisted extension
-// installed.
-class LogIsEnabled {
- public:
- LogIsEnabled() : any_profile_enabled_(false) {
- ComputeIsFlagEnabled();
- }
-
- void ComputeIsFlagEnabled() {
- base::AutoLock auto_lock(lock_);
- cmd_line_enabled_ = CommandLine::ForCurrentProcess()->
- HasSwitch(switches::kEnableExtensionActivityLogging);
- }
-
- static LogIsEnabled* GetInstance() {
- return Singleton<LogIsEnabled>::get();
- }
-
- bool IsEnabled() {
- base::AutoLock auto_lock(lock_);
- return cmd_line_enabled_ || any_profile_enabled_;
- }
-
- void SetProfileEnabled(bool any_profile_enabled) {
- base::AutoLock auto_lock(lock_);
- any_profile_enabled_ = any_profile_enabled;
- }
-
- private:
- base::Lock lock_;
- bool any_profile_enabled_;
- bool cmd_line_enabled_;
-};
-
} // namespace
namespace extensions {
-// static
-bool ActivityLog::IsLogEnabledOnAnyProfile() {
- return LogIsEnabled::GetInstance()->IsEnabled();
-}
-
-// static
-void ActivityLog::RecomputeLoggingIsEnabled(bool profile_enabled) {
- LogIsEnabled::GetInstance()->ComputeIsFlagEnabled();
- LogIsEnabled::GetInstance()->SetProfileEnabled(profile_enabled);
-}
-
// ActivityLogFactory
ActivityLogFactory* ActivityLogFactory::GetInstance() {
@@ -163,16 +116,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),
+ watchdog_extension_active_(false) {
// This controls whether logging statements are printed, which policy is set,
// etc.
testing_mode_ = CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExtensionActivityLogTesting);
+ // Check if the watchdog extension is previously installed and active.
+ watchdog_extension_active_ =
+ profile_->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive);
+
// 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 +137,23 @@ 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;
felt 2013/07/23 06:37:34 If we return here, observers is never set to anyth
pmarch 2013/07/29 17:36:47 I think you are right, we should not return here.
}
+ enabled_ = CommandLine::ForCurrentProcess()->
+ HasSwitch(switches::kEnableExtensionActivityLogging)
+ || watchdog_extension_active_;
observers_ = new ObserverListThreadSafe<Observer>;
+
+ ExtensionSystem::Get(profile_)->ready().Post(
+ FROM_HERE,
+ base::Bind(&ActivityLog::InitInstallTracker, base::Unretained(this)));
+ ChooseDefaultPolicy();
}
-void ActivityLog::Init() {
- DCHECK(has_threads_);
- DCHECK(!initialized_);
- const Extension* whitelisted_extension = ExtensionSystem::Get(profile_)->
- extension_service()->GetExtensionById(kActivityLogExtensionId, false);
- if (whitelisted_extension) {
- enabled_ = true;
- LogIsEnabled::GetInstance()->SetProfileEnabled(true);
- }
+void ActivityLog::InitInstallTracker() {
tracker_ = InstallTrackerFactory::GetForProfile(profile_);
tracker_->AddObserver(this);
- ChooseDefaultPolicy();
- initialized_ = true;
}
void ActivityLog::ChooseDefaultPolicy() {
@@ -222,22 +174,34 @@ 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;
- LogIsEnabled::GetInstance()->SetProfileEnabled(true);
+ if (has_threads_)
+ enabled_ = true;
felt 2013/07/23 06:37:34 Can you switch this to: if (!has_threads_) return;
pmarch 2013/07/29 17:36:47 I do not think it is the right thing to do. If has
felt 2013/07/29 19:29:42 Ah, OK, you're right -- the semantics have changed
+ if (!watchdog_extension_active_) {
+ watchdog_extension_active_ = true;
+ profile_->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, 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 (watchdog_extension_active_) {
+ watchdog_extension_active_ = false;
+ profile_->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive,
+ false);
+ }
}
// static
@@ -512,4 +476,13 @@ void ActivityLog::OnScriptsExecuted(
}
}
+// static
+void ActivityLog::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(
+ prefs::kWatchdogExtensionActive,
+ false,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
felt 2013/07/23 06:37:34 Does this mean it will sync across browsers? Since
pmarch 2013/07/29 17:36:47 I will make it Non-syncable.
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698