diff options
author | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 18:51:35 +0000 |
---|---|---|
committer | rickcam@chromium.org <rickcam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-07 18:51:35 +0000 |
commit | c7b7800afbf7aadb5c9f99c95209237cdf869678 (patch) | |
tree | e741fdc86b0da94136eceb3dafc60db63cd930bd /chrome/browser | |
parent | 53fb3cb54e0eff74e74743d0dafd8ca7dd8c5271 (diff) | |
download | chromium_src-c7b7800afbf7aadb5c9f99c95209237cdf869678.zip chromium_src-c7b7800afbf7aadb5c9f99c95209237cdf869678.tar.gz chromium_src-c7b7800afbf7aadb5c9f99c95209237cdf869678.tar.bz2 |
ConvertLabsToSwitches earlier in startup sequence to fix Background Webapps
BUG=58213
TEST=none
If I enable the "Background WebApps" lab and restart, when the BackgroundModeManager checks whether the kEnableBackgroundMode switch is set, CommandLine::HasSwitch returns false because about_labs::ConvertLabsToSwitches has not yet been called.
BrowserMain first calls CreateProfile then later calls about_labs::ConvertLabsToSwitches. However, since CreateProfile initializes the BackgroundModeManager, things break down. Here's the comment preceding the BackgroundModeManager initialization in the ProfileImpl constructor:
// Initialize the BackgroundModeManager - this has to be done here before
// InitExtensions() is called because it relies on receiving notifications
// when extensions are loaded. BackgroundModeManager is not needed under
// ChromeOS because Chrome is always running (no need for special keep-alive
// or launch-on-startup support).
Hence:
* Change about_labs::ConvertLabsToSwitches to accept a PrefService* rather than a Profile*
* Change the ProfileImpl constructor (called by CreateProfile) to call about_labs::ConvertLabsToSwitches immediately after it's call to GetPrefs.
Review URL: http://codereview.chromium.org/3544013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_main.cc | 4 | ||||
-rw-r--r-- | chrome/browser/dom_ui/labs_ui.cc | 8 | ||||
-rw-r--r-- | chrome/browser/labs.cc | 17 | ||||
-rw-r--r-- | chrome/browser/labs.h | 10 | ||||
-rw-r--r-- | chrome/browser/profile_impl.cc | 4 |
5 files changed, 24 insertions, 19 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index d32eda4..85d2c76 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1202,6 +1202,7 @@ int BrowserMain(const MainFunctionParams& parameters) { SetBrowserX11ErrorHandlers(); #endif + // Modifies the current command line based on active labs. Profile* profile = CreateProfile(parameters, user_data_dir); if (!profile) return ResultCodes::NORMAL_EXIT; @@ -1211,9 +1212,6 @@ int BrowserMain(const MainFunctionParams& parameters) { PrefService* user_prefs = profile->GetPrefs(); DCHECK(user_prefs); - // Convert active labs into switches. Modifies the current command line. - about_labs::ConvertLabsToSwitches(profile, CommandLine::ForCurrentProcess()); - // Tests should be able to tune login manager before showing it. // Thus only show login manager in normal (non-testing) mode. if (!parameters.ui_task) { diff --git a/chrome/browser/dom_ui/labs_ui.cc b/chrome/browser/dom_ui/labs_ui.cc index 3e02112..14a60b9 100644 --- a/chrome/browser/dom_ui/labs_ui.cc +++ b/chrome/browser/dom_ui/labs_ui.cc @@ -16,6 +16,7 @@ #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/labs.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profile.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -135,7 +136,8 @@ void LabsDOMHandler::RegisterMessages() { void LabsDOMHandler::HandleRequestLabsExperiments(const ListValue* args) { DictionaryValue results; results.Set("labsExperiments", - about_labs::GetLabsExperimentsData(dom_ui_->GetProfile())); + about_labs::GetLabsExperimentsData( + dom_ui_->GetProfile()->GetPrefs())); results.SetBoolean("needsRestart", about_labs::IsRestartNeededToCommitChanges()); dom_ui_->CallJavascriptFunction(L"returnLabsExperiments", results); @@ -153,7 +155,9 @@ void LabsDOMHandler::HandleEnableLabsExperimentMessage(const ListValue* args) { return; about_labs::SetExperimentEnabled( - dom_ui_->GetProfile(), experiment_internal_name, enable_str == "true"); + dom_ui_->GetProfile()->GetPrefs(), + experiment_internal_name, + enable_str == "true"); } void LabsDOMHandler::HandleRestartBrowser(const ListValue* args) { diff --git a/chrome/browser/labs.cc b/chrome/browser/labs.cc index d723f30..dcbecda 100644 --- a/chrome/browser/labs.cc +++ b/chrome/browser/labs.cc @@ -13,7 +13,6 @@ #include "base/command_line.h" #include "base/values.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "grit/generated_resources.h" @@ -133,7 +132,7 @@ const Experiment kExperiments[] = { } }; -// Extracts the list of enabled lab experiments from a profile and stores them +// Extracts the list of enabled lab experiments from preferences and stores them // in a set. void GetEnabledLabs(const PrefService* prefs, std::set<std::string>* result) { const ListValue* enabled_experiments = prefs->GetList( @@ -218,12 +217,12 @@ bool IsEnabled() { #endif } -void ConvertLabsToSwitches(Profile* profile, CommandLine* command_line) { +void ConvertLabsToSwitches(PrefService* prefs, CommandLine* command_line) { if (!IsEnabled()) return; std::set<std::string> enabled_experiments; - GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments); + GetSanitizedEnabledLabs(prefs, &enabled_experiments); std::map<std::string, const Experiment*> experiments; for (size_t i = 0; i < arraysize(kExperiments); ++i) @@ -243,9 +242,9 @@ void ConvertLabsToSwitches(Profile* profile, CommandLine* command_line) { } } -ListValue* GetLabsExperimentsData(Profile* profile) { +ListValue* GetLabsExperimentsData(PrefService* prefs) { std::set<std::string> enabled_experiments; - GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments); + GetSanitizedEnabledLabs(prefs, &enabled_experiments); int current_platform = GetCurrentPlatform(); @@ -277,18 +276,18 @@ bool IsRestartNeededToCommitChanges() { } void SetExperimentEnabled( - Profile* profile, const std::string& internal_name, bool enable) { + PrefService* prefs, const std::string& internal_name, bool enable) { needs_restart_ = true; std::set<std::string> enabled_experiments; - GetSanitizedEnabledLabs(profile->GetPrefs(), &enabled_experiments); + GetSanitizedEnabledLabs(prefs, &enabled_experiments); if (enable) enabled_experiments.insert(internal_name); else enabled_experiments.erase(internal_name); - SetEnabledLabs(profile->GetPrefs(), enabled_experiments); + SetEnabledLabs(prefs, enabled_experiments); } } // namespace Labs diff --git a/chrome/browser/labs.h b/chrome/browser/labs.h index 0c61b95..7a13b1b 100644 --- a/chrome/browser/labs.h +++ b/chrome/browser/labs.h @@ -10,7 +10,7 @@ class CommandLine; class ListValue; -class Profile; +class PrefService; // Can't be called "labs", that collides with the C function |labs()|. namespace about_labs { @@ -18,19 +18,19 @@ namespace about_labs { // Returns if Labs is enabled (it isn't on the stable channel). bool IsEnabled(); -// Reads the Labs pref from |profile| and adds the commandline flags belonging +// Reads the Labs |prefs| and adds the commandline flags belonging // to the active experiments to |command_line|. -void ConvertLabsToSwitches(Profile* profile, CommandLine* command_line); +void ConvertLabsToSwitches(PrefService* prefs, CommandLine* command_line); // Get a list of all available experiments. The caller owns the result. -ListValue* GetLabsExperimentsData(Profile* profile); +ListValue* GetLabsExperimentsData(PrefService* prefs); // Returns true if one of the experiment flags has been flipped since startup. bool IsRestartNeededToCommitChanges(); // Enables or disables the experiment with id |internal_name|. void SetExperimentEnabled( - Profile* profile, const std::string& internal_name, bool enable); + PrefService* prefs, const std::string& internal_name, bool enable); } // namespace Labs diff --git a/chrome/browser/profile_impl.cc b/chrome/browser/profile_impl.cc index acbf6f5..b89057d 100644 --- a/chrome/browser/profile_impl.cc +++ b/chrome/browser/profile_impl.cc @@ -43,6 +43,7 @@ #include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/host_zoom_map.h" #include "chrome/browser/in_process_webkit/webkit_context.h" +#include "chrome/browser/labs.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/net/net_pref_observer.h" @@ -272,6 +273,9 @@ ProfileImpl::ProfileImpl(const FilePath& path) pref_change_registrar_.Add(prefs::kEnableSpellCheck, this); pref_change_registrar_.Add(prefs::kEnableAutoSpellCorrect, this); + // Convert active labs into switches. Modifies the current command line. + about_labs::ConvertLabsToSwitches(prefs, CommandLine::ForCurrentProcess()); + #if defined(OS_MACOSX) // If the profile directory doesn't already have a cache directory and it // is under ~/Library/Application Support, use a suitable cache directory |