diff options
author | jeanluc@google.com <jeanluc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-19 06:19:48 +0000 |
---|---|---|
committer | jeanluc@google.com <jeanluc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-19 06:19:48 +0000 |
commit | 32cba2b85543286544bf1a613fa7819e295a36a4 (patch) | |
tree | 4623f33a2acf2b816e187e24fc2362c302353530 | |
parent | f6e7b6d78a6729ab7cc8c3258d3aeb8f73210cdc (diff) | |
download | chromium_src-32cba2b85543286544bf1a613fa7819e295a36a4.zip chromium_src-32cba2b85543286544bf1a613fa7819e295a36a4.tar.gz chromium_src-32cba2b85543286544bf1a613fa7819e295a36a4.tar.bz2 |
If default search is managed, we should not asked the user to choose it at First Run. Make sure the minimum bubble is not showed if there is no default search.
This is a re-issue of CL 3565013 without the extraneous change to search_engine_list_model.mm, to be done in a forthcoming CL>
BUG=49306
TEST=Set a managed default search provider. Clear your Chromium user data directory (~/Library/Chromium, ~/.config/chromium, %localappdata%\Chromium) and the "First Run" file found next to the executable. Start Chrome. It should not ask you to choose a default search provider. Disable the default search provider via policy. Make sure the minimal bubble is not shown. Redo these tests for the GOOGLE_CHROME_BUILD to make sure that we still ask about usage stats.
Review URL: http://codereview.chromium.org/3847006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63024 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 11 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run.cc | 14 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run_mac.mm | 18 | ||||
-rw-r--r-- | chrome/browser/first_run/first_run_win.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/first_run_dialog.cc | 52 | ||||
-rw-r--r-- | chrome/browser/gtk/first_run_dialog.h | 13 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model_unittest.cc | 25 |
8 files changed, 95 insertions, 49 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 76c94fd..c26ff0f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1506,11 +1506,16 @@ int BrowserMain(const MainFunctionParams& parameters) { if (FirstRun::InSearchExperimentLocale() && record_search_engine) { const TemplateURL* default_search_engine = profile->GetTemplateURLModel()->GetDefaultSearchProvider(); + // The default engine can be NULL if the administrator has disabled + // default search. + TemplateURLPrepopulateData::SearchEngineType search_engine_type = + default_search_engine ? default_search_engine->search_engine_type() : + TemplateURLPrepopulateData::SEARCH_ENGINE_OTHER; // Record the search engine chosen. if (master_prefs.run_search_engine_experiment) { UMA_HISTOGRAM_ENUMERATION( "Chrome.SearchSelectExperiment", - default_search_engine->search_engine_type(), + search_engine_type, TemplateURLPrepopulateData::SEARCH_ENGINE_MAX); // If the selection has been randomized, also record the winner by slot. if (master_prefs.randomize_search_engine_experiment) { @@ -1522,7 +1527,7 @@ int BrowserMain(const MainFunctionParams& parameters) { experiment_type.push_back('1' + engine_pos); UMA_HISTOGRAM_ENUMERATION( experiment_type, - default_search_engine->search_engine_type(), + search_engine_type, TemplateURLPrepopulateData::SEARCH_ENGINE_MAX); } else { NOTREACHED() << "Invalid search engine selection slot."; @@ -1531,7 +1536,7 @@ int BrowserMain(const MainFunctionParams& parameters) { } else { UMA_HISTOGRAM_ENUMERATION( "Chrome.SearchSelectExempt", - default_search_engine->search_engine_type(), + search_engine_type, TemplateURLPrepopulateData::SEARCH_ENGINE_MAX); } } diff --git a/chrome/browser/first_run/first_run.cc b/chrome/browser/first_run/first_run.cc index 596419f..663c52d 100644 --- a/chrome/browser/first_run/first_run.cc +++ b/chrome/browser/first_run/first_run.cc @@ -22,6 +22,7 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/process_singleton.h" #include "chrome/browser/profile_manager.h" +#include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/shell_integration.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -564,7 +565,7 @@ void FirstRun::AutoImport( UserMetrics::RecordAction(UserMetricsAction("FirstRunDef_Accept")); // Launch the search engine dialog only if build is organic, and user has not - // already set search preferences. + // already set preferences. if (IsOrganic() && !local_state_file_exists) { // The home page string may be set in the preferences, but the user should // initially use Chrome with the NTP as home page in organic builds. @@ -575,9 +576,14 @@ void FirstRun::AutoImport( if (make_chrome_default) ShellIntegration::SetAsDefaultBrowser(); - FirstRun::SetShowFirstRunBubblePref(true); - // Set the first run bubble to minimal. - FirstRun::SetMinimalFirstRunBubblePref(); + // Don't display the minimal bubble if there is no default search provider. + TemplateURLModel* search_engines_model = profile->GetTemplateURLModel(); + if (search_engines_model && + search_engines_model->GetDefaultSearchProvider()) { + FirstRun::SetShowFirstRunBubblePref(true); + // Set the first run bubble to minimal. + FirstRun::SetMinimalFirstRunBubblePref(); + } FirstRun::SetShowWelcomePagePref(); FirstRun::SetPersonalDataManagerFirstRunPref(); diff --git a/chrome/browser/first_run/first_run_mac.mm b/chrome/browser/first_run/first_run_mac.mm index 3159e9d..b297d15 100644 --- a/chrome/browser/first_run/first_run_mac.mm +++ b/chrome/browser/first_run/first_run_mac.mm @@ -9,6 +9,8 @@ #import "chrome/browser/cocoa/first_run_dialog.h" #import "chrome/browser/cocoa/search_engine_dialog_controller.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/shell_integration.h" #include "chrome/common/pref_names.h" #include "chrome/installer/util/google_update_constants.h" @@ -71,7 +73,12 @@ void ShowFirstRun(Profile* profile) { FirstRun::CreateSentinel(); // Set preference to show first run bubble and welcome page. - FirstRun::SetShowFirstRunBubblePref(true); + // Don't display the minimal bubble if there is no default search provider. + TemplateURLModel* search_engines_model = profile->GetTemplateURLModel(); + if (search_engines_model && + search_engines_model->GetDefaultSearchProvider()) { + FirstRun::SetShowFirstRunBubblePref(true); + } FirstRun::SetShowWelcomePagePref(); } @@ -80,8 +87,13 @@ void ShowFirstRun(Profile* profile) { // static void FirstRun::ShowFirstRunDialog(Profile* profile, bool randomize_search_engine_experiment) { - ShowSearchEngineSelectionDialog(profile, - randomize_search_engine_experiment); + // If the default search is not managed via policy, ask the user to + // choose a default. + TemplateURLModel* model = profile->GetTemplateURLModel(); + if (model && !model->is_default_search_managed()) { + ShowSearchEngineSelectionDialog(profile, + randomize_search_engine_experiment); + } ShowFirstRun(profile); } diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc index 4f9175d..a7f7a3c 100644 --- a/chrome/browser/first_run/first_run_win.cc +++ b/chrome/browser/first_run/first_run_win.cc @@ -31,6 +31,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/process_singleton.h" #include "chrome/browser/profile.h" +#include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/views/first_run_search_engine_view.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" @@ -453,6 +454,12 @@ bool FirstRun::IsOrganic() { // static void FirstRun::ShowFirstRunDialog(Profile* profile, bool randomize_search_engine_experiment) { + // If the default search is managed via policy, we don't ask the user to + // choose. + TemplateURLModel* model = profile->GetTemplateURLModel(); + if (NULL == model || model->is_default_search_managed()) + return; + views::Window* search_engine_dialog = views::Window::CreateChromeWindow( NULL, gfx::Rect(), diff --git a/chrome/browser/gtk/first_run_dialog.cc b/chrome/browser/gtk/first_run_dialog.cc index c30da15..45b0589 100644 --- a/chrome/browser/gtk/first_run_dialog.cc +++ b/chrome/browser/gtk/first_run_dialog.cc @@ -86,9 +86,32 @@ void SetWelcomePosition(GtkFloatingContainer* container, // static bool FirstRunDialog::Show(Profile* profile, bool randomize_search_engine_order) { + // Figure out which dialogs we will show. + // If the default search is managed via policy, we won't ask. + const TemplateURLModel* search_engines_model = profile->GetTemplateURLModel(); + bool show_search_engines_dialog = search_engines_model && + !search_engines_model->is_default_search_managed(); + +#if defined(GOOGLE_CHROME_BUILD) + // If the metrics reporting is managed, we won't ask. + const PrefService::Preference* metrics_reporting_pref = + g_browser_process->local_state()->FindPreference( + prefs::kMetricsReportingEnabled); + bool show_reporting_dialog = !metrics_reporting_pref || + !metrics_reporting_pref->IsManaged(); +#else + bool show_reporting_dialog = false; +#endif + + if (!show_search_engines_dialog && !show_reporting_dialog) + return true; // Nothing to do + int response = -1; // Object deletes itself. - new FirstRunDialog(profile, randomize_search_engine_order, response); + new FirstRunDialog(profile, + show_reporting_dialog, + show_search_engines_dialog, + &response); // TODO(port): it should be sufficient to just run the dialog: // int response = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -101,16 +124,23 @@ bool FirstRunDialog::Show(Profile* profile, } FirstRunDialog::FirstRunDialog(Profile* profile, - bool randomize_search_engine_order, - int& response) + bool show_reporting_dialog, + bool show_search_engines_dialog, + int* response) : search_engine_window_(NULL), dialog_(NULL), report_crashes_(NULL), make_default_(NULL), profile_(profile), chosen_search_engine_(NULL), + show_reporting_dialog_(show_reporting_dialog), response_(response) { + if (!show_search_engines_dialog) { + ShowReportingDialog(); + return; + } search_engines_model_ = profile_->GetTemplateURLModel(); + ShowSearchEngineWindow(); search_engines_model_->AddObserver(this); @@ -191,21 +221,17 @@ void FirstRunDialog::ShowSearchEngineWindow() { gtk_window_present(GTK_WINDOW(search_engine_window_)); } -void FirstRunDialog::ShowDialog() { +void FirstRunDialog::ShowReportingDialog() { // The purpose of the dialog is to ask the user to enable stats and crash // reporting. This setting may be controlled through configuration management // in enterprise scenarios. If that is the case, skip the dialog entirely, // it's not worth bothering the user for only the default browser question // (which is likely to be forced in enterprise deployments anyway). - const PrefService::Preference* metrics_reporting_pref = - g_browser_process->local_state()->FindPreference( - prefs::kMetricsReportingEnabled); - if (metrics_reporting_pref && metrics_reporting_pref->IsManaged()) { + if (!show_reporting_dialog_) { OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); return; } -#if defined(GOOGLE_CHROME_BUILD) dialog_ = gtk_dialog_new_with_buttons( l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), NULL, // No parent @@ -251,10 +277,6 @@ void FirstRunDialog::ShowDialog() { g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseDialogThunk), this); gtk_widget_show_all(dialog_); -#else // !defined(GOOGLE_CHROME_BUILD) - // We don't show the dialog in chromium. Pretend the user accepted. - OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); -#endif // !defined(GOOGLE_CHROME_BUILD) } void FirstRunDialog::OnTemplateURLModelChanged() { @@ -348,7 +370,7 @@ void FirstRunDialog::OnSearchEngineWindowDestroy(GtkWidget* sender) { search_engine_window_ = NULL; if (chosen_search_engine_) { search_engines_model_->SetDefaultSearchProvider(chosen_search_engine_); - ShowDialog(); + ShowReportingDialog(); } else { FirstRunDone(); } @@ -357,7 +379,7 @@ void FirstRunDialog::OnSearchEngineWindowDestroy(GtkWidget* sender) { void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { if (dialog_) gtk_widget_hide_all(dialog_); - response_ = response; + *response_ = response; // Mark that first run has ran. FirstRun::CreateSentinel(); diff --git a/chrome/browser/gtk/first_run_dialog.h b/chrome/browser/gtk/first_run_dialog.h index fdd47a7..234a64b 100644 --- a/chrome/browser/gtk/first_run_dialog.h +++ b/chrome/browser/gtk/first_run_dialog.h @@ -25,8 +25,9 @@ class FirstRunDialog : public TemplateURLModelObserver { private: FirstRunDialog(Profile* profile, - bool randomize_search_engine_order, - int& response); + bool show_reporting_dialog, + bool show_search_engines_dialog, + int* response); virtual ~FirstRunDialog(); CHROMEGTK_CALLBACK_1(FirstRunDialog, void, OnResponseDialog, int); @@ -35,7 +36,7 @@ class FirstRunDialog : public TemplateURLModelObserver { CHROMEG_CALLBACK_0(FirstRunDialog, void, OnLearnMoreLinkClicked, GtkButton*); void ShowSearchEngineWindow(); - void ShowDialog(); + void ShowReportingDialog(); // This method closes the first run window and quits the message loop so that // the Chrome startup can continue. This should be called when all the @@ -68,8 +69,12 @@ class FirstRunDialog : public TemplateURLModelObserver { // search engine. TemplateURL* chosen_search_engine_; + // Whether we should show the dialog asking the user whether to report + // crashes and usage stats. + bool show_reporting_dialog_; + // User response (accept or cancel) is returned through this. - int& response_; + int* response_; DISALLOW_COPY_AND_ASSIGN(FirstRunDialog); }; diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 4d0d33c..e7bcb92 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -803,10 +803,8 @@ bool TemplateURLModel::LoadDefaultSearchProviderFromPrefs( if (!prefs || !prefs->HasPrefPath(prefs::kDefaultSearchProviderSearchURL)) return false; - // By default, kDefaultSearchProviderEnabled is true. Users of previous - // versions will transition correctly. const PrefService::Preference* pref = - prefs->FindPreference(prefs::kDefaultSearchProviderEnabled); + prefs->FindPreference(prefs::kDefaultSearchProviderSearchURL); *is_managed = pref && pref->IsManaged(); bool enabled = diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index 7f4dc72..15c4b12 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -186,7 +186,8 @@ class TemplateURLModelTest : public testing::Test { // Set the managed preferences for the default search provider and trigger // notification. - void SetManagedDefaultSearchPreferences(const char* name, + void SetManagedDefaultSearchPreferences(bool enabled, + const char* name, const char* search_url, const char* suggest_url, const char* icon_url, @@ -195,7 +196,7 @@ class TemplateURLModelTest : public testing::Test { TestingPrefService* service = profile()->GetTestingPrefService(); service->SetManagedPrefWithoutNotification( prefs::kDefaultSearchProviderEnabled, - Value::CreateBooleanValue(true)); + Value::CreateBooleanValue(enabled)); service->SetManagedPrefWithoutNotification( prefs::kDefaultSearchProviderName, Value::CreateStringValue(name)); @@ -222,16 +223,6 @@ class TemplateURLModelTest : public testing::Test { NotifyManagedPrefsHaveChanged(); } - // Set the managed preferences for the default search provider and trigger - // notification. - void DisableManagedDefaultSearchProvider() { - TestingPrefService* service = profile()->GetTestingPrefService(); - service->SetManagedPrefWithoutNotification( - prefs::kDefaultSearchProviderEnabled, - Value::CreateBooleanValue(false)); - NotifyManagedPrefsHaveChanged(); - } - // Remove all the managed preferences for the default search provider and // trigger notification. void RemoveManagedDefaultSearchPreferences() { @@ -1120,7 +1111,7 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { const char kSearchURL[] = "http://test.com/search?t={searchTerms}"; const char kIconURL[] = "http://test.com/icon.jpg"; const char kEncodings[] = "UTF-16;UTF-32"; - SetManagedDefaultSearchPreferences(kName, kSearchURL, "", kIconURL, + SetManagedDefaultSearchPreferences(true, kName, kSearchURL, "", kIconURL, kEncodings, ""); VerifyObserverCount(1); EXPECT_TRUE(model()->is_default_search_managed()); @@ -1144,8 +1135,8 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { const char kNewName[] = "test2"; const char kNewSearchURL[] = "http://other.com/search?t={searchTerms}"; const char kNewSuggestURL[] = "http://other.com/suggest?t={searchTerms}"; - SetManagedDefaultSearchPreferences(kNewName, kNewSearchURL, kNewSuggestURL, - "", "", ""); + SetManagedDefaultSearchPreferences(true, kNewName, kNewSearchURL, + kNewSuggestURL, "", "", ""); VerifyObserverCount(1); EXPECT_TRUE(model()->is_default_search_managed()); EXPECT_EQ(2 + initial_count, model()->GetTemplateURLs().size()); @@ -1174,14 +1165,14 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { EXPECT_EQ(actual_final_managed_default->show_in_default_list(), true); // Disable the default search provider through policy. - DisableManagedDefaultSearchProvider(); + SetManagedDefaultSearchPreferences(false, "", "", "", "", "", ""); VerifyObserverCount(1); EXPECT_TRUE(model()->is_default_search_managed()); EXPECT_TRUE(NULL == model()->GetDefaultSearchProvider()); EXPECT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); // Re-enable it. - SetManagedDefaultSearchPreferences(kName, kSearchURL, "", kIconURL, + SetManagedDefaultSearchPreferences(true, kName, kSearchURL, "", kIconURL, kEncodings, ""); VerifyObserverCount(1); EXPECT_TRUE(model()->is_default_search_managed()); |