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

Side by Side Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 12315116: Add ability to change default pref values, and use in BrowserInstantController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge LKGR and address review nit. Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.h ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_instant_controller.h" 5 #include "chrome/browser/ui/browser_instant_controller.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_web_ui.h" 9 #include "chrome/browser/extensions/extension_web_ui.h"
10 #include "chrome/browser/prefs/pref_registry_syncable.h" 10 #include "chrome/browser/prefs/pref_registry_syncable.h"
(...skipping 29 matching lines...) Expand all
40 40
41 //////////////////////////////////////////////////////////////////////////////// 41 ////////////////////////////////////////////////////////////////////////////////
42 // BrowserInstantController, public: 42 // BrowserInstantController, public:
43 43
44 BrowserInstantController::BrowserInstantController(Browser* browser) 44 BrowserInstantController::BrowserInstantController(Browser* browser)
45 : browser_(browser), 45 : browser_(browser),
46 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), 46 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
47 chrome::search::IsInstantExtendedAPIEnabled(profile())), 47 chrome::search::IsInstantExtendedAPIEnabled(profile())),
48 instant_unload_handler_(browser), 48 instant_unload_handler_(browser),
49 initialized_theme_info_(false) { 49 initialized_theme_info_(false) {
50 profile_pref_registrar_.Init(profile()->GetPrefs()); 50 PrefService* prefs = profile()->GetPrefs();
51
52 // The kInstantExtendedEnabled and kInstantEnabled preferences are
53 // separate, as the way opt-in is done is a bit different, and
54 // because the experiment that controls the behavior of
55 // kInstantExtendedEnabled (value retrieved via
56 // search::GetInstantExtendedDefaultSetting) may take different
57 // settings on different Chrome set-ups for the same user.
58 //
59 // In one mode of the experiment, however, the
60 // kInstantExtendedEnabled preference's default value is set to the
61 // existing value of kInstantEnabled.
62 //
63 // Because this requires reading the value of the kInstantEnabled
64 // value, we reset the default for kInstantExtendedEnabled here,
65 // instead of fully determining the default in RegisterUserPrefs,
66 // below.
67 bool instant_extended_default = true;
68 switch (search::GetInstantExtendedDefaultSetting()) {
69 case search::INSTANT_DEFAULT_ON:
70 instant_extended_default = true;
71 break;
72 case search::INSTANT_USE_EXISTING:
73 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled);
74 case search::INSTANT_DEFAULT_OFF:
75 instant_extended_default = false;
76 break;
77 }
78
79 prefs->SetDefaultPrefValue(
80 prefs::kInstantExtendedEnabled,
81 Value::CreateBooleanValue(instant_extended_default));
82
83 profile_pref_registrar_.Init(prefs);
51 profile_pref_registrar_.Add( 84 profile_pref_registrar_.Add(
52 GetInstantPrefName(profile()), 85 GetInstantPrefName(profile()),
53 base::Bind(&BrowserInstantController::ResetInstant, 86 base::Bind(&BrowserInstantController::ResetInstant,
54 base::Unretained(this))); 87 base::Unretained(this)));
55 profile_pref_registrar_.Add( 88 profile_pref_registrar_.Add(
56 prefs::kSearchSuggestEnabled, 89 prefs::kSearchSuggestEnabled,
57 base::Bind(&BrowserInstantController::ResetInstant, 90 base::Bind(&BrowserInstantController::ResetInstant,
58 base::Unretained(this))); 91 base::Unretained(this)));
59 ResetInstant(); 92 ResetInstant();
60 browser_->search_model()->AddObserver(this); 93 browser_->search_model()->AddObserver(this);
61 94
62 #if defined(ENABLE_THEMES) 95 #if defined(ENABLE_THEMES)
63 // Listen for theme installation. 96 // Listen for theme installation.
64 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 97 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
65 content::Source<ThemeService>( 98 content::Source<ThemeService>(
66 ThemeServiceFactory::GetForProfile(profile()))); 99 ThemeServiceFactory::GetForProfile(profile())));
67 #endif // defined(ENABLE_THEMES) 100 #endif // defined(ENABLE_THEMES)
68 } 101 }
69 102
70 BrowserInstantController::~BrowserInstantController() { 103 BrowserInstantController::~BrowserInstantController() {
71 browser_->search_model()->RemoveObserver(this); 104 browser_->search_model()->RemoveObserver(this);
72 } 105 }
73 106
74 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { 107 bool BrowserInstantController::IsInstantEnabled(Profile* profile) {
75 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && 108 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() &&
76 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); 109 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile));
77 } 110 }
78 111
79 void BrowserInstantController::RegisterUserPrefs( 112 void BrowserInstantController::RegisterUserPrefs(
80 PrefService* prefs,
81 PrefRegistrySyncable* registry) { 113 PrefRegistrySyncable* registry) {
82 // TODO(joi): Get rid of the need for PrefService param above.
83 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, 114 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false,
84 PrefRegistrySyncable::SYNCABLE_PREF); 115 PrefRegistrySyncable::SYNCABLE_PREF);
85 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, 116 registry->RegisterBooleanPref(prefs::kInstantEnabled, false,
86 PrefRegistrySyncable::SYNCABLE_PREF); 117 PrefRegistrySyncable::SYNCABLE_PREF);
87 118
88 bool instant_extended_default = true; 119 // Note that the default for this pref gets reset in the
89 switch (search::GetInstantExtendedDefaultSetting()) { 120 // BrowserInstantController constructor.
90 case search::INSTANT_DEFAULT_ON:
91 instant_extended_default = true;
92 break;
93 case search::INSTANT_USE_EXISTING:
94 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled);
95 break;
96 case search::INSTANT_DEFAULT_OFF:
97 instant_extended_default = false;
98 break;
99 }
100
101 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, 121 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled,
102 instant_extended_default, 122 false,
103 PrefRegistrySyncable::SYNCABLE_PREF); 123 PrefRegistrySyncable::SYNCABLE_PREF);
104 } 124 }
105 125
106 bool BrowserInstantController::MaybeSwapInInstantNTPContents( 126 bool BrowserInstantController::MaybeSwapInInstantNTPContents(
107 const GURL& url, 127 const GURL& url,
108 content::WebContents* source_contents, 128 content::WebContents* source_contents,
109 content::WebContents** target_contents) { 129 content::WebContents** target_contents) {
110 if (url != GURL(chrome::kChromeUINewTabURL)) 130 if (url != GURL(chrome::kChromeUINewTabURL))
111 return false; 131 return false;
112 132
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 initialized_theme_info_ = true; 368 initialized_theme_info_ = true;
349 } 369 }
350 370
351 DCHECK(initialized_theme_info_); 371 DCHECK(initialized_theme_info_);
352 372
353 if (browser_->search_model()->mode().is_ntp()) 373 if (browser_->search_model()->mode().is_ntp())
354 instant_.ThemeChanged(theme_info_); 374 instant_.ThemeChanged(theme_info_);
355 } 375 }
356 376
357 } // namespace chrome 377 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.h ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698