OLD | NEW |
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/prefs/pref_registry_syncable.h" | 9 #include "chrome/browser/prefs/pref_registry_syncable.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
41 // BrowserInstantController, public: | 41 // BrowserInstantController, public: |
42 | 42 |
43 BrowserInstantController::BrowserInstantController(Browser* browser) | 43 BrowserInstantController::BrowserInstantController(Browser* browser) |
44 : browser_(browser), | 44 : browser_(browser), |
45 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 45 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
46 chrome::search::IsInstantExtendedAPIEnabled(profile())), | 46 chrome::search::IsInstantExtendedAPIEnabled(profile())), |
47 instant_unload_handler_(browser), | 47 instant_unload_handler_(browser), |
48 initialized_theme_info_(false) { | 48 initialized_theme_info_(false) { |
49 profile_pref_registrar_.Init(profile()->GetPrefs()); | 49 PrefService* prefs = profile()->GetPrefs(); |
| 50 |
| 51 // The kInstantExtendedEnabled and kInstantEnabled preferences are |
| 52 // separate, as the way opt-in is done is a bit different, and |
| 53 // because the experiment that controls the behavior of |
| 54 // kInstantExtendedEnabled (value retrieved via |
| 55 // search::GetInstantExtendedDefaultSetting) may take different |
| 56 // settings on different Chrome set-ups for the same user. |
| 57 // |
| 58 // In one mode of the experiment, however, the |
| 59 // kInstantExtendedEnabled preference's default value is set to the |
| 60 // existing value of kInstantEnabled. |
| 61 // |
| 62 // Because this requires reading the value of the kInstantEnabled |
| 63 // value, we reset the default for kInstantExtendedEnabled here, |
| 64 // instead of fully determining the default in RegisterUserPrefs, |
| 65 // below. |
| 66 bool instant_extended_default = true; |
| 67 switch (search::GetInstantExtendedDefaultSetting()) { |
| 68 case search::INSTANT_DEFAULT_ON: |
| 69 instant_extended_default = true; |
| 70 break; |
| 71 case search::INSTANT_USE_EXISTING: |
| 72 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); |
| 73 case search::INSTANT_DEFAULT_OFF: |
| 74 instant_extended_default = false; |
| 75 break; |
| 76 } |
| 77 |
| 78 prefs->SetDefaultPrefValue( |
| 79 prefs::kInstantExtendedEnabled, |
| 80 Value::CreateBooleanValue(instant_extended_default)); |
| 81 |
| 82 profile_pref_registrar_.Init(prefs); |
50 profile_pref_registrar_.Add( | 83 profile_pref_registrar_.Add( |
51 GetInstantPrefName(profile()), | 84 GetInstantPrefName(profile()), |
52 base::Bind(&BrowserInstantController::ResetInstant, | 85 base::Bind(&BrowserInstantController::ResetInstant, |
53 base::Unretained(this))); | 86 base::Unretained(this))); |
54 profile_pref_registrar_.Add( | 87 profile_pref_registrar_.Add( |
55 prefs::kSearchSuggestEnabled, | 88 prefs::kSearchSuggestEnabled, |
56 base::Bind(&BrowserInstantController::ResetInstant, | 89 base::Bind(&BrowserInstantController::ResetInstant, |
57 base::Unretained(this))); | 90 base::Unretained(this))); |
58 ResetInstant(); | 91 ResetInstant(); |
59 browser_->search_model()->AddObserver(this); | 92 browser_->search_model()->AddObserver(this); |
60 | 93 |
61 #if defined(ENABLE_THEMES) | 94 #if defined(ENABLE_THEMES) |
62 // Listen for theme installation. | 95 // Listen for theme installation. |
63 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 96 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
64 content::Source<ThemeService>( | 97 content::Source<ThemeService>( |
65 ThemeServiceFactory::GetForProfile(profile()))); | 98 ThemeServiceFactory::GetForProfile(profile()))); |
66 #endif // defined(ENABLE_THEMES) | 99 #endif // defined(ENABLE_THEMES) |
67 } | 100 } |
68 | 101 |
69 BrowserInstantController::~BrowserInstantController() { | 102 BrowserInstantController::~BrowserInstantController() { |
70 browser_->search_model()->RemoveObserver(this); | 103 browser_->search_model()->RemoveObserver(this); |
71 } | 104 } |
72 | 105 |
73 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 106 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
74 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 107 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && |
75 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); | 108 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); |
76 } | 109 } |
77 | 110 |
78 void BrowserInstantController::RegisterUserPrefs( | 111 void BrowserInstantController::RegisterUserPrefs( |
79 PrefService* prefs, | |
80 PrefRegistrySyncable* registry) { | 112 PrefRegistrySyncable* registry) { |
81 // TODO(joi): Get rid of the need for PrefService param above. | |
82 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 113 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
83 PrefRegistrySyncable::SYNCABLE_PREF); | 114 PrefRegistrySyncable::SYNCABLE_PREF); |
84 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, | 115 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, |
85 PrefRegistrySyncable::SYNCABLE_PREF); | 116 PrefRegistrySyncable::SYNCABLE_PREF); |
86 | 117 |
87 bool instant_extended_default = true; | 118 // Note that the default for this pref gets reset in the |
88 switch (search::GetInstantExtendedDefaultSetting()) { | 119 // BrowserInstantController constructor. |
89 case search::INSTANT_DEFAULT_ON: | |
90 instant_extended_default = true; | |
91 break; | |
92 case search::INSTANT_USE_EXISTING: | |
93 instant_extended_default = prefs->GetBoolean(prefs::kInstantEnabled); | |
94 break; | |
95 case search::INSTANT_DEFAULT_OFF: | |
96 instant_extended_default = false; | |
97 break; | |
98 } | |
99 | |
100 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, | 120 registry->RegisterBooleanPref(prefs::kInstantExtendedEnabled, |
101 instant_extended_default, | 121 false, |
102 PrefRegistrySyncable::SYNCABLE_PREF); | 122 PrefRegistrySyncable::SYNCABLE_PREF); |
103 } | 123 } |
104 | 124 |
105 bool BrowserInstantController::MaybeSwapInInstantNTPContents( | 125 bool BrowserInstantController::MaybeSwapInInstantNTPContents( |
106 const GURL& url, | 126 const GURL& url, |
107 content::WebContents* source_contents, | 127 content::WebContents* source_contents, |
108 content::WebContents** target_contents) { | 128 content::WebContents** target_contents) { |
109 if (url != GURL(chrome::kChromeUINewTabURL)) | 129 if (url != GURL(chrome::kChromeUINewTabURL)) |
110 return false; | 130 return false; |
111 | 131 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 initialized_theme_info_ = true; | 361 initialized_theme_info_ = true; |
342 } | 362 } |
343 | 363 |
344 DCHECK(initialized_theme_info_); | 364 DCHECK(initialized_theme_info_); |
345 | 365 |
346 if (browser_->search_model()->mode().is_ntp()) | 366 if (browser_->search_model()->mode().is_ntp()) |
347 instant_.ThemeChanged(theme_info_); | 367 instant_.ThemeChanged(theme_info_); |
348 } | 368 } |
349 | 369 |
350 } // namespace chrome | 370 } // namespace chrome |
OLD | NEW |