From 42c94c7c60a6edac354da55f3c00166e68904629 Mon Sep 17 00:00:00 2001 From: "pmarch@chromium.org" Date: Wed, 14 Aug 2013 01:18:44 +0000 Subject: Sets correct ActivityLog enabled status to the first renderer process BUG=247908 Review URL: https://chromiumcodereview.appspot.com/18430004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217425 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chrome_content_browser_client.cc | 9 +- .../extensions/activity_log/activity_log.cc | 126 ++++++-------- .../browser/extensions/activity_log/activity_log.h | 48 +++--- .../activity_log/activity_log_enabled_unittest.cc | 190 +++++++++++++++++++++ .../activity_log/activity_log_unittest.cc | 17 -- chrome/browser/prefs/browser_prefs.cc | 2 + chrome/chrome_tests_unit.gypi | 1 + chrome/common/pref_names.cc | 6 + chrome/common/pref_names.h | 2 + 9 files changed, 284 insertions(+), 117 deletions(-) create mode 100644 chrome/browser/extensions/activity_log/activity_log_enabled_unittest.cc (limited to 'chrome') diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 7823264..f4b2411 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -781,13 +781,6 @@ content::WebContentsViewDelegate* return chrome::CreateWebContentsViewDelegate(web_contents); } -// Check if the extension activity log is enabled for the profile. -static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) { - // crbug.com/247908 - This should be IsLogEnabled except for an issue - // in chrome_frame_net_tests - return extensions::ActivityLog::IsLogEnabledOnAnyProfile(); -} - void ChromeContentBrowserClient::GuestWebContentsCreated( WebContents* guest_web_contents, WebContents* opener_web_contents, @@ -910,7 +903,7 @@ void ChromeContentBrowserClient::RenderProcessHostCreated( profile->IsOffTheRecord())); host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled( - IsExtensionActivityLogEnabledForProfile(profile))); + extensions::ActivityLog::GetInstance(profile)->IsLogEnabled())); SendExtensionWebRequestStatusToHost(host); diff --git a/chrome/browser/extensions/activity_log/activity_log.cc b/chrome/browser/extensions/activity_log/activity_log.cc index bc973e7..d80eedc 100644 --- a/chrome/browser/extensions/activity_log/activity_log.cc +++ b/chrome/browser/extensions/activity_log/activity_log.cc @@ -22,6 +22,7 @@ #include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/extension_tab_util.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" @@ -29,6 +30,7 @@ #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" @@ -54,44 +56,6 @@ 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::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_; -}; - // Gets the URL for a given tab ID. Helper method for LookupTabId. Returns // true if able to perform the lookup. The URL is stored to *url, and // *is_incognito is set to indicate whether the URL is for an incognito tab. @@ -183,17 +147,6 @@ void LookupTabIds(scoped_refptr action, Profile* profile) { 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() { @@ -257,16 +210,22 @@ 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); + + observers_ = new ObserverListThreadSafe; + // Check that the right threads exist. If not, we shouldn't try to do things // that require them. if (!BrowserThread::IsMessageLoopValid(BrowserThread::DB) || @@ -274,28 +233,24 @@ 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))); } - observers_ = new ObserverListThreadSafe; + enabled_ = has_threads_ + && (CommandLine::ForCurrentProcess()-> + HasSwitch(switches::kEnableExtensionActivityLogging) + || watchdog_extension_active_); + + if (enabled_) enabled_on_any_profile_ = true; + + 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() { @@ -315,23 +270,45 @@ ActivityLog::~ActivityLog() { policy_->Close(); } +// static +bool ActivityLog::enabled_on_any_profile_ = false; + +// static +bool ActivityLog::IsLogEnabledOnAnyProfile() { + return enabled_on_any_profile_; +} + 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; + enabled_on_any_profile_ = true; + } + 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 @@ -427,4 +404,13 @@ void ActivityLog::OnScriptsExecuted( } } +// static +void ActivityLog::RegisterProfilePrefs( + user_prefs::PrefRegistrySyncable* registry) { + registry->RegisterBooleanPref( + prefs::kWatchdogExtensionActive, + false, + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); +} + } // namespace extensions diff --git a/chrome/browser/extensions/activity_log/activity_log.h b/chrome/browser/extensions/activity_log/activity_log.h index 4f75d29..93f61e3 100644 --- a/chrome/browser/extensions/activity_log/activity_log.h +++ b/chrome/browser/extensions/activity_log/activity_log.h @@ -29,6 +29,10 @@ class Profile; using content::BrowserThread; +namespace user_prefs { +class PrefRegistrySyncable; +} + namespace extensions { class Extension; class ActivityLogPolicy; @@ -50,16 +54,16 @@ class ActivityLog : public BrowserContextKeyedService, // use GetInstance instead. static ActivityLog* GetInstance(Profile* profile); + // Specifies if AL was enabled at least for one profile. We use this method to + // check if AL possibly enabled when a profile is not available, e.g., when + // executing on thread other than UI. + static bool IsLogEnabledOnAnyProfile(); + // Provides up-to-date information about whether the AL is enabled for a // profile. The AL is enabled if the user has installed the whitelisted // AL extension *or* set the --enable-extension-activity-logging flag. bool IsLogEnabled(); - // If you want to know whether the log is enabled but DON'T have a profile - // object yet, use this method. However, it's preferable for the caller to - // use IsLogEnabled when possible. - static bool IsLogEnabledOnAnyProfile(); - // Add/remove observer: the activityLogPrivate API only listens when the // ActivityLog extension is registered for an event. void AddObserver(Observer* observer); @@ -83,14 +87,10 @@ class ActivityLog : public BrowserContextKeyedService, // Extension::InstallObserver // We keep track of whether the whitelisted extension is installed; if it is, // we want to recompute whether to have logging enabled. - virtual void OnExtensionInstalled( - const extensions::Extension* extension) OVERRIDE {} - virtual void OnExtensionLoaded( - const extensions::Extension* extension) OVERRIDE; - virtual void OnExtensionUnloaded( - const extensions::Extension* extension) OVERRIDE; - virtual void OnExtensionUninstalled( - const extensions::Extension* extension) OVERRIDE {} + virtual void OnExtensionInstalled(const Extension* extension) OVERRIDE {} + virtual void OnExtensionLoaded(const Extension* extension) OVERRIDE; + virtual void OnExtensionUnloaded(const Extension* extension) OVERRIDE; + virtual void OnExtensionUninstalled(const Extension* extension) OVERRIDE {} // We also have to list the following from InstallObserver. virtual void OnBeginExtensionInstall(const std::string& extension_id, const std::string& extension_name, @@ -108,6 +108,8 @@ class ActivityLog : public BrowserContextKeyedService, // BrowserContextKeyedService virtual void Shutdown() OVERRIDE; + static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); + private: friend class ActivityLogFactory; friend class ActivityLogTest; @@ -116,9 +118,9 @@ class ActivityLog : public BrowserContextKeyedService, explicit ActivityLog(Profile* profile); virtual ~ActivityLog(); - // Some setup needs to wait until after the ExtensionSystem/ExtensionService - // are done with their own setup. - void Init(); + // Delayed initialization of Install Tracker which waits until after the + // ExtensionSystem/ExtensionService are done with their own setup. + void InitInstallTracker(); // TabHelper::ScriptExecutionObserver implementation. // Fires when a ContentScript is executed. @@ -128,10 +130,6 @@ class ActivityLog : public BrowserContextKeyedService, int32 page_id, const GURL& on_url) OVERRIDE; - // For unit tests only. Does not call Init again! - // Sets whether logging should be enabled for the whole current profile. - static void RecomputeLoggingIsEnabled(bool profile_enabled); - // At the moment, ActivityLog will use only one policy for summarization. // These methods are used to choose and set the most appropriate policy. void ChooseDefaultPolicy(); @@ -145,14 +143,13 @@ class ActivityLog : public BrowserContextKeyedService, // be a scoped_ptr since some cleanup work must happen on the database // thread. Calling policy_->Close() will free the object; see the comments // on the ActivityDatabase class for full details. - extensions::ActivityLogPolicy* policy_; + ActivityLogPolicy* policy_; // TODO(dbabic,felt) change this into a list of policy types later. ActivityLogPolicy::PolicyType policy_type_; Profile* profile_; bool enabled_; // Whether logging is currently enabled. - bool initialized_; // Whether Init() has already been called. bool policy_chosen_; // Whether we've already set the default policy. // testing_mode_ controls whether to log API call arguments. By default, we // don't log most arguments to avoid saving too much data. In testing mode, @@ -169,6 +166,13 @@ class ActivityLog : public BrowserContextKeyedService, // added or removed, enabled_ may change. InstallTracker* tracker_; + // Set if the watchdog extension is present and active. Maintained by + // kWatchdogExtensionActive pref variable. + bool watchdog_extension_active_; + + // Specifies if AL was enabled at least for one profile. + static bool enabled_on_any_profile_; + DISALLOW_COPY_AND_ASSIGN(ActivityLog); }; diff --git a/chrome/browser/extensions/activity_log/activity_log_enabled_unittest.cc b/chrome/browser/extensions/activity_log/activity_log_enabled_unittest.cc new file mode 100644 index 0000000..808618b --- /dev/null +++ b/chrome/browser/extensions/activity_log/activity_log_enabled_unittest.cc @@ -0,0 +1,190 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/command_line.h" +#include "base/run_loop.h" +#include "chrome/browser/extensions/activity_log/activity_log.h" +#include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/test_extension_system.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/extensions/extension_builder.h" +#include "chrome/common/pref_names.h" +#include "chrome/test/base/chrome_render_view_host_test_harness.h" +#include "chrome/test/base/testing_profile.h" + +#if defined OS_CHROMEOS +#include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" +#include "chrome/browser/chromeos/settings/device_settings_service.h" +#endif + +namespace extensions { + +class ActivityLogEnabledTest : public ChromeRenderViewHostTestHarness { + protected: + virtual void SetUp() OVERRIDE { + ChromeRenderViewHostTestHarness::SetUp(); +#if defined OS_CHROMEOS + test_user_manager_.reset(new chromeos::ScopedTestUserManager()); +#endif + } + + virtual void TearDown() OVERRIDE { +#if defined OS_CHROMEOS + test_user_manager_.reset(); +#endif + ChromeRenderViewHostTestHarness::TearDown(); + } + +#if defined OS_CHROMEOS + chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; + chromeos::ScopedTestCrosSettings test_cros_settings_; + scoped_ptr test_user_manager_; +#endif +}; + +TEST_F(ActivityLogEnabledTest, NoSwitch) { + scoped_ptr profile( + static_cast(CreateBrowserContext())); + EXPECT_FALSE( + profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + + ActivityLog* activity_log = ActivityLog::GetInstance(profile.get()); + + EXPECT_FALSE( + profile->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE(activity_log->IsLogEnabled()); + EXPECT_FALSE(activity_log->IsLogEnabledOnAnyProfile()); +} + +TEST_F(ActivityLogEnabledTest, CommandLineSwitch) { + scoped_ptr profile1( + static_cast(CreateBrowserContext())); + scoped_ptr profile2( + static_cast(CreateBrowserContext())); + + CommandLine command_line(CommandLine::NO_PROGRAM); + CommandLine saved_cmdline_ = *CommandLine::ForCurrentProcess(); + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExtensionActivityLogging); + ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); + *CommandLine::ForCurrentProcess() = saved_cmdline_; + ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); + + EXPECT_FALSE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_TRUE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); +} + +TEST_F(ActivityLogEnabledTest, PrefSwitch) { + scoped_ptr profile1( + static_cast(CreateBrowserContext())); + scoped_ptr profile2( + static_cast(CreateBrowserContext())); + + EXPECT_FALSE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + + profile1->GetPrefs()->SetBoolean(prefs::kWatchdogExtensionActive, true); + ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); + ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); + + EXPECT_TRUE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_TRUE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); +} + +TEST_F(ActivityLogEnabledTest, WatchdogSwitch) { + CommandLine command_line(CommandLine::NO_PROGRAM); + scoped_ptr profile1( + static_cast(CreateBrowserContext())); + scoped_ptr profile2( + static_cast(CreateBrowserContext())); + // Extension service is destroyed by the profile. + ExtensionService* extension_service1 = + static_cast( + ExtensionSystem::Get(profile1.get()))->CreateExtensionService( + &command_line, base::FilePath(), false); + static_cast( + ExtensionSystem::Get(profile1.get()))->SetReady(); + + ActivityLog* activity_log1 = ActivityLog::GetInstance(profile1.get()); + ActivityLog* activity_log2 = ActivityLog::GetInstance(profile2.get()); + + // Allow Activity Log to install extension tracker. + base::RunLoop().RunUntilIdle(); + + EXPECT_FALSE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + + scoped_refptr extension = + ExtensionBuilder() + .SetManifest(DictionaryBuilder() + .Set("name", "Watchdog Extension ") + .Set("version", "1.0.0") + .Set("manifest_version", 2)) + .SetID(kActivityLogExtensionId) + .Build(); + extension_service1->AddExtension(extension.get()); + + EXPECT_TRUE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_TRUE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); + + extension_service1->DisableExtension(kActivityLogExtensionId, + Extension::DISABLE_USER_ACTION); + + EXPECT_FALSE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); + + extension_service1->EnableExtension(kActivityLogExtensionId); + + EXPECT_TRUE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_TRUE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); + + extension_service1->UninstallExtension(kActivityLogExtensionId, false, NULL); + + EXPECT_FALSE( + profile1->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE( + profile2->GetPrefs()->GetBoolean(prefs::kWatchdogExtensionActive)); + EXPECT_FALSE(activity_log1->IsLogEnabled()); + EXPECT_FALSE(activity_log2->IsLogEnabled()); + EXPECT_TRUE(activity_log1->IsLogEnabledOnAnyProfile()); + EXPECT_TRUE(activity_log2->IsLogEnabledOnAnyProfile()); +} + +} // namespace extensions diff --git a/chrome/browser/extensions/activity_log/activity_log_unittest.cc b/chrome/browser/extensions/activity_log/activity_log_unittest.cc index 25c9cea..30ade1f 100644 --- a/chrome/browser/extensions/activity_log/activity_log_unittest.cc +++ b/chrome/browser/extensions/activity_log/activity_log_unittest.cc @@ -39,24 +39,19 @@ namespace extensions { class ActivityLogTest : public ChromeRenderViewHostTestHarness { protected: - ActivityLogTest() : saved_cmdline_(CommandLine::NO_PROGRAM) {} - virtual void SetUp() OVERRIDE { ChromeRenderViewHostTestHarness::SetUp(); #if defined OS_CHROMEOS test_user_manager_.reset(new chromeos::ScopedTestUserManager()); #endif CommandLine command_line(CommandLine::NO_PROGRAM); - saved_cmdline_ = *CommandLine::ForCurrentProcess(); CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableExtensionActivityLogging); CommandLine::ForCurrentProcess()->AppendSwitch( switches::kEnableExtensionActivityLogTesting); - ActivityLog::RecomputeLoggingIsEnabled(true); // Logging now enabled. extension_service_ = static_cast( ExtensionSystem::Get(profile()))->CreateExtensionService (&command_line, base::FilePath(), false); - ActivityLog::GetInstance(profile())->Init(); base::RunLoop().RunUntilIdle(); } @@ -65,9 +60,6 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { test_user_manager_.reset(); #endif base::RunLoop().RunUntilIdle(); - // Restore the original command line and undo the affects of SetUp(). - *CommandLine::ForCurrentProcess() = saved_cmdline_; - ActivityLog::RecomputeLoggingIsEnabled(false); // Logging now disabled. ChromeRenderViewHostTestHarness::TearDown(); } @@ -96,11 +88,6 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { } ExtensionService* extension_service_; - // Used to preserve a copy of the original command line. - // The test framework will do this itself as well. However, by then, - // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in - // TearDown(). - CommandLine saved_cmdline_; #if defined OS_CHROMEOS chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; @@ -109,10 +96,6 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness { #endif }; -TEST_F(ActivityLogTest, Enabled) { - ASSERT_TRUE(ActivityLog::IsLogEnabledOnAnyProfile()); -} - TEST_F(ActivityLogTest, Construct) { ActivityLog* activity_log = ActivityLog::GetInstance(profile()); ASSERT_TRUE(activity_log->IsLogEnabled()); diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 12365c3..d0428eb 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -21,6 +21,7 @@ #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/devtools/devtools_window.h" #include "chrome/browser/download/download_prefs.h" +#include "chrome/browser/extensions/activity_log/activity_log.h" #include "chrome/browser/extensions/api/commands/command_service.h" #include "chrome/browser/extensions/api/tabs/tabs_api.h" #include "chrome/browser/extensions/extension_prefs.h" @@ -326,6 +327,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { SessionStartupPref::RegisterProfilePrefs(registry); TemplateURLPrepopulateData::RegisterProfilePrefs(registry); TranslatePrefs::RegisterProfilePrefs(registry); + extensions::ActivityLog::RegisterProfilePrefs(registry); #if defined(ENABLE_AUTOFILL_DIALOG) autofill::AutofillDialogController::RegisterProfilePrefs(registry); diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 87bc21d6..e75c455 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -766,6 +766,7 @@ 'browser/enumerate_modules_model_unittest_win.cc', 'browser/extensions/active_tab_unittest.cc', 'browser/extensions/activity_log/activity_database_unittest.cc', + 'browser/extensions/activity_log/activity_log_enabled_unittest.cc', 'browser/extensions/activity_log/activity_log_unittest.cc', 'browser/extensions/activity_log/activity_log_policy_unittest.cc', 'browser/extensions/activity_log/counting_policy_unittest.cc', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 65b4c93..0fefea4 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -2544,4 +2544,10 @@ const char kDRMSalt[] = "settings.privacy.drm_salt"; // A boolean pref that enables the (private) pepper GetDeviceID() call. const char kEnableDRM[] = "settings.privacy.drm_enabled"; +// A boolean per-profile pref that signals if the watchdog extension is +// installed and active. We need to know if the watchdog extension active for +// ActivityLog initialization before the extension system is initialized. +const char kWatchdogExtensionActive[] = + "profile.extensions.activity_log.watchdog_extension_active"; + } // namespace prefs diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index d1bfbe7..3d7dbb8 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -934,6 +934,8 @@ extern const char kModuleConflictBubbleShown[]; extern const char kDRMSalt[]; extern const char kEnableDRM[]; +extern const char kWatchdogExtensionActive[]; + } // namespace prefs #endif // CHROME_COMMON_PREF_NAMES_H_ -- cgit v1.1