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/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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 using content::UserMetricsAction; | 33 using content::UserMetricsAction; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const char* GetInstantPrefName(Profile* profile) { | 37 const char* GetInstantPrefName(Profile* profile) { |
38 return chrome::search::IsInstantExtendedAPIEnabled(profile) ? | 38 return chrome::search::IsInstantExtendedAPIEnabled(profile) ? |
39 prefs::kInstantExtendedEnabled : prefs::kInstantEnabled; | 39 prefs::kInstantExtendedEnabled : prefs::kInstantEnabled; |
40 } | 40 } |
41 | 41 |
| 42 // Returns the PrefsService to use for checking the Instant pref for the given |
| 43 // profile, or NULL if profile does not support instant. |
| 44 PrefService* GetPrefsForInstantEnabledCheck(Profile* profile) { |
| 45 if (profile && !profile->IsOffTheRecord()) |
| 46 return profile->GetPrefs(); |
| 47 return NULL; |
| 48 } |
| 49 |
42 } // namespace | 50 } // namespace |
43 | 51 |
44 namespace chrome { | 52 namespace chrome { |
45 | 53 |
46 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
47 // BrowserInstantController, public: | 55 // BrowserInstantController, public: |
48 | 56 |
49 BrowserInstantController::BrowserInstantController(Browser* browser) | 57 BrowserInstantController::BrowserInstantController(Browser* browser) |
50 : browser_(browser), | 58 : browser_(browser), |
51 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 59 instant_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
52 chrome::search::IsInstantExtendedAPIEnabled(profile())), | 60 chrome::search::IsInstantExtendedAPIEnabled(profile())), |
53 instant_unload_handler_(browser), | 61 instant_unload_handler_(browser), |
54 initialized_theme_info_(false) { | 62 initialized_theme_info_(false) { |
55 profile_pref_registrar_.Init(profile()->GetPrefs()); | 63 profile_pref_registrar_.Init(profile()->GetPrefs()); |
56 profile_pref_registrar_.Add( | 64 profile_pref_registrar_.Add( |
57 GetInstantPrefName(profile()), | 65 GetInstantPrefName(profile()), |
58 base::Bind(&BrowserInstantController::ResetInstant, | 66 base::Bind(&BrowserInstantController::ResetInstant, |
59 base::Unretained(this))); | 67 base::Unretained(this))); |
60 profile_pref_registrar_.Add( | 68 profile_pref_registrar_.Add( |
61 prefs::kSearchSuggestEnabled, | 69 prefs::kSearchSuggestEnabled, |
62 base::Bind(&BrowserInstantController::ResetInstant, | 70 base::Bind(&BrowserInstantController::ResetInstant, |
63 base::Unretained(this))); | 71 base::Unretained(this))); |
64 ResetInstant(); | 72 ResetInstant(); |
65 browser_->search_model()->AddObserver(this); | 73 browser_->search_model()->AddObserver(this); |
66 | 74 |
| 75 if (chrome::search::IsInstantExtendedAPIEnabled(profile())) { |
| 76 // Only record this for valid (e.g. non-incognito) profiles. |
| 77 PrefService* prefs = GetPrefsForInstantEnabledCheck(profile()); |
| 78 if (prefs) { |
| 79 const bool pref_value = prefs->GetBoolean(GetInstantPrefName(profile())); |
| 80 chrome::search::RecordInstantExtendedPrefValue(pref_value); |
| 81 } |
| 82 } |
| 83 |
67 #if defined(ENABLE_THEMES) | 84 #if defined(ENABLE_THEMES) |
68 // Listen for theme installation. | 85 // Listen for theme installation. |
69 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 86 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
70 content::Source<ThemeService>( | 87 content::Source<ThemeService>( |
71 ThemeServiceFactory::GetForProfile(profile()))); | 88 ThemeServiceFactory::GetForProfile(profile()))); |
72 #endif // defined(ENABLE_THEMES) | 89 #endif // defined(ENABLE_THEMES) |
73 } | 90 } |
74 | 91 |
75 BrowserInstantController::~BrowserInstantController() { | 92 BrowserInstantController::~BrowserInstantController() { |
76 browser_->search_model()->RemoveObserver(this); | 93 browser_->search_model()->RemoveObserver(this); |
77 } | 94 } |
78 | 95 |
79 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { | 96 bool BrowserInstantController::IsInstantEnabled(Profile* profile) { |
80 return profile && !profile->IsOffTheRecord() && profile->GetPrefs() && | 97 PrefService* prefs = GetPrefsForInstantEnabledCheck(profile); |
81 profile->GetPrefs()->GetBoolean(GetInstantPrefName(profile)); | 98 return prefs && prefs->GetBoolean(GetInstantPrefName(profile)); |
82 } | 99 } |
83 | 100 |
84 void BrowserInstantController::RegisterUserPrefs( | 101 void BrowserInstantController::RegisterUserPrefs( |
85 PrefService* prefs, | 102 PrefService* prefs, |
86 PrefRegistrySyncable* registry) { | 103 PrefRegistrySyncable* registry) { |
87 // TODO(joi): Get rid of the need for PrefService param above. | 104 // TODO(joi): Get rid of the need for PrefService param above. |
88 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, | 105 registry->RegisterBooleanPref(prefs::kInstantConfirmDialogShown, false, |
89 PrefRegistrySyncable::SYNCABLE_PREF); | 106 PrefRegistrySyncable::SYNCABLE_PREF); |
90 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, | 107 registry->RegisterBooleanPref(prefs::kInstantEnabled, false, |
91 PrefRegistrySyncable::SYNCABLE_PREF); | 108 PrefRegistrySyncable::SYNCABLE_PREF); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 initialized_theme_info_ = true; | 377 initialized_theme_info_ = true; |
361 } | 378 } |
362 | 379 |
363 DCHECK(initialized_theme_info_); | 380 DCHECK(initialized_theme_info_); |
364 | 381 |
365 if (browser_->search_model()->mode().is_ntp()) | 382 if (browser_->search_model()->mode().is_ntp()) |
366 instant_.ThemeChanged(theme_info_); | 383 instant_.ThemeChanged(theme_info_); |
367 } | 384 } |
368 | 385 |
369 } // namespace chrome | 386 } // namespace chrome |
OLD | NEW |