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

Side by Side Diff: chrome/browser/search/hotword_service.cc

Issue 196753002: [Hotword] Making enabling/disabling the setting enable/disable the hotword extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneeded includes Created 6 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/search/hotword_service.h ('k') | extensions/browser/admin_policy.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/search/hotword_service.h" 5 #include "chrome/browser/search/hotword_service.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 availability_state = PENDING_DOWNLOAD; 54 availability_state = PENDING_DOWNLOAD;
55 } else if (!service->IsExtensionEnabled( 55 } else if (!service->IsExtensionEnabled(
56 extension_misc::kHotwordExtensionId)) { 56 extension_misc::kHotwordExtensionId)) {
57 availability_state = DISABLED_EXTENSION; 57 availability_state = DISABLED_EXTENSION;
58 } 58 }
59 UMA_HISTOGRAM_ENUMERATION("Hotword.HotwordExtensionAvailability", 59 UMA_HISTOGRAM_ENUMERATION("Hotword.HotwordExtensionAvailability",
60 availability_state, 60 availability_state,
61 NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS); 61 NUM_HOTWORD_EXTENSION_AVAILABILITY_METRICS);
62 } 62 }
63 63
64 ExtensionService* GetExtensionService(Profile* profile) {
65 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
66
67 extensions::ExtensionSystem* extension_system =
68 extensions::ExtensionSystem::Get(profile);
69 if (!extension_system || !extension_system->extension_service())
Jered 2014/03/12 23:30:49 nit: simpler if written if (extension_system) re
rpetterson 2014/03/12 23:34:29 Done.
70 return NULL;
71 return extension_system->extension_service();
72 }
73
64 } // namespace 74 } // namespace
65 75
66 namespace hotword_internal { 76 namespace hotword_internal {
67 // Constants for the hotword field trial. 77 // Constants for the hotword field trial.
68 const char kHotwordFieldTrialName[] = "VoiceTrigger"; 78 const char kHotwordFieldTrialName[] = "VoiceTrigger";
69 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled"; 79 const char kHotwordFieldTrialDisabledGroupName[] = "Disabled";
70 } // namespace hotword_internal 80 } // namespace hotword_internal
71 81
72 // static 82 // static
73 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) { 83 bool HotwordService::DoesHotwordSupportLanguage(Profile* profile) {
(...skipping 13 matching lines...) Expand all
87 HotwordService::HotwordService(Profile* profile) 97 HotwordService::HotwordService(Profile* profile)
88 : profile_(profile) { 98 : profile_(profile) {
89 // This will be called during profile initialization which is a good time 99 // This will be called during profile initialization which is a good time
90 // to check the user's hotword state. 100 // to check the user's hotword state.
91 HotwordEnabled enabled_state = UNSET; 101 HotwordEnabled enabled_state = UNSET;
92 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { 102 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) {
93 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 103 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
94 enabled_state = ENABLED; 104 enabled_state = ENABLED;
95 else 105 else
96 enabled_state = DISABLED; 106 enabled_state = DISABLED;
107 } else {
108 // If the preference has not been set the hotword extension should
109 // not be running.
110 DisableHotwordExtension();
97 } 111 }
98 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, 112 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
99 NUM_HOTWORD_ENABLED_METRICS); 113 NUM_HOTWORD_ENABLED_METRICS);
114
115 pref_registrar_.Init(profile_->GetPrefs());
116 pref_registrar_.Add(
117 prefs::kHotwordSearchEnabled,
118 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
119 base::Unretained(this)));
100 } 120 }
101 121
102 HotwordService::~HotwordService() { 122 HotwordService::~HotwordService() {
103 } 123 }
104 124
105 bool HotwordService::ShouldShowOptInPopup() { 125 bool HotwordService::ShouldShowOptInPopup() {
106 if (profile_->IsOffTheRecord()) 126 if (profile_->IsOffTheRecord())
107 return false; 127 return false;
108 128
109 // Profile is not off the record. 129 // Profile is not off the record.
(...skipping 14 matching lines...) Expand all
124 prefs::kHotwordOptInPopupTimesShown); 144 prefs::kHotwordOptInPopupTimesShown);
125 profile_->GetPrefs()->SetInteger(prefs::kHotwordOptInPopupTimesShown, 145 profile_->GetPrefs()->SetInteger(prefs::kHotwordOptInPopupTimesShown,
126 ++number_shown); 146 ++number_shown);
127 // TODO(rlp): actually show opt in popup when linked up to extension. 147 // TODO(rlp): actually show opt in popup when linked up to extension.
128 } 148 }
129 149
130 bool HotwordService::IsServiceAvailable() { 150 bool HotwordService::IsServiceAvailable() {
131 extensions::ExtensionSystem* system = 151 extensions::ExtensionSystem* system =
132 extensions::ExtensionSystem::Get(profile_); 152 extensions::ExtensionSystem::Get(profile_);
133 ExtensionService* service = system->extension_service(); 153 ExtensionService* service = system->extension_service();
134 // Do not include disabled extension (false parameter) because if the 154 // Include disabled extensions (true parameter) since it may not be enabled
135 // extension is disabled, it's not available. 155 // if the user opted out.
136 const extensions::Extension* extension = 156 const extensions::Extension* extension =
137 service->GetExtensionById(extension_misc::kHotwordExtensionId, false); 157 service->GetExtensionById(extension_misc::kHotwordExtensionId, true);
138 158
139 RecordAvailabilityMetrics(service, extension); 159 RecordAvailabilityMetrics(service, extension);
140 160
141 return extension && IsHotwordAllowed(); 161 return extension && IsHotwordAllowed();
142 } 162 }
143 163
144 bool HotwordService::IsHotwordAllowed() { 164 bool HotwordService::IsHotwordAllowed() {
145 std::string group = base::FieldTrialList::FindFullName( 165 std::string group = base::FieldTrialList::FindFullName(
146 hotword_internal::kHotwordFieldTrialName); 166 hotword_internal::kHotwordFieldTrialName);
147 return !group.empty() && 167 return !group.empty() &&
148 group != hotword_internal::kHotwordFieldTrialDisabledGroupName && 168 group != hotword_internal::kHotwordFieldTrialDisabledGroupName &&
149 DoesHotwordSupportLanguage(profile_); 169 DoesHotwordSupportLanguage(profile_);
150 } 170 }
151 171
152 bool HotwordService::RetryHotwordExtension() { 172 bool HotwordService::RetryHotwordExtension() {
153 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 173 ExtensionService* extension_service = GetExtensionService(profile_);
154 174 if (!extension_service)
155 extensions::ExtensionSystem* extension_system =
156 extensions::ExtensionSystem::Get(profile_);
157 if (!extension_system || !extension_system->extension_service())
158 return false; 175 return false;
159 ExtensionService* extension_service = extension_system->extension_service();
160 176
161 extension_service->ReloadExtension(extension_misc::kHotwordExtensionId); 177 extension_service->ReloadExtension(extension_misc::kHotwordExtensionId);
162 return true; 178 return true;
163 } 179 }
180
181 void HotwordService::DisableHotwordExtension() {
182 ExtensionService* extension_service = GetExtensionService(profile_);
183 if (extension_service)
Jered 2014/03/12 23:30:49 nit: prefer if wrapped lines go in {} but up to yo
rpetterson 2014/03/12 23:34:29 I agree. I just missed that when doing the refacto
184 extension_service->DisableExtension(
185 extension_misc::kHotwordExtensionId,
186 extensions::Extension::DISABLE_USER_ACTION);
187 }
188
189 void HotwordService::EnableHotwordExtension() {
190 ExtensionService* extension_service = GetExtensionService(profile_);
191 if (extension_service)
192 extension_service->EnableExtension(extension_misc::kHotwordExtensionId);
193 }
194
195 void HotwordService::OnHotwordSearchEnabledChanged(
196 const std::string& pref_name) {
197 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
198
199 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
200 EnableHotwordExtension();
201 else
202 DisableHotwordExtension();
203 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | extensions/browser/admin_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698