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

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

Issue 267653005: Adds HotwordPrivate API for integrating the hotword feature to AppLauncher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add hotword type Created 6 years, 7 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
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"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "extensions/browser/extension_system.h" 20 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 23
24 using extensions::BrowserContextKeyedAPIFactory;
25 using extensions::HotwordPrivateEventService;
26
23 namespace { 27 namespace {
24 const int kMaxTimesToShowOptInPopup = 10; 28 const int kMaxTimesToShowOptInPopup = 10;
25 29
26 // Allowed languages for hotwording. 30 // Allowed languages for hotwording.
27 static const char* kSupportedLocales[] = { 31 static const char* kSupportedLocales[] = {
28 "en", 32 "en",
29 "en_us" 33 "en_us"
30 }; 34 };
31 35
32 // Enum describing the state of the hotword preference. 36 // Enum describing the state of the hotword preference.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 StringToLowerASCII(&normalized_locale); 117 StringToLowerASCII(&normalized_locale);
114 118
115 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 119 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
116 if (kSupportedLocales[i] == normalized_locale) 120 if (kSupportedLocales[i] == normalized_locale)
117 return true; 121 return true;
118 } 122 }
119 return false; 123 return false;
120 } 124 }
121 125
122 HotwordService::HotwordService(Profile* profile) 126 HotwordService::HotwordService(Profile* profile)
123 : profile_(profile) { 127 : profile_(profile),
128 client_(NULL) {
124 // This will be called during profile initialization which is a good time 129 // This will be called during profile initialization which is a good time
125 // to check the user's hotword state. 130 // to check the user's hotword state.
126 HotwordEnabled enabled_state = UNSET; 131 HotwordEnabled enabled_state = UNSET;
127 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { 132 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) {
128 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 133 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
129 enabled_state = ENABLED; 134 enabled_state = ENABLED;
130 else 135 else
131 enabled_state = DISABLED; 136 enabled_state = DISABLED;
132 } else { 137 } else {
133 // If the preference has not been set the hotword extension should 138 // If the preference has not been set the hotword extension should
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void HotwordService::OnHotwordSearchEnabledChanged( 271 void HotwordService::OnHotwordSearchEnabledChanged(
267 const std::string& pref_name) { 272 const std::string& pref_name) {
268 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 273 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
269 274
270 ExtensionService* extension_service = GetExtensionService(profile_); 275 ExtensionService* extension_service = GetExtensionService(profile_);
271 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 276 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
272 EnableHotwordExtension(extension_service); 277 EnableHotwordExtension(extension_service);
273 else 278 else
274 DisableHotwordExtension(extension_service); 279 DisableHotwordExtension(extension_service);
275 } 280 }
281
282 void HotwordService::RequestHotwordSession(
283 HotwordClient* client) {
rpetterson 2014/05/02 19:13:16 move to line above
Jun Mukai 2014/05/02 22:18:57 Done.
284 if (!IsServiceAvailable())
285 return;
286
287 if (client_)
rpetterson 2014/05/02 19:13:16 combine with the line above: if (!IsServiceAvailab
Jun Mukai 2014/05/02 22:18:57 Done.
288 return;
289
290 client_ = client;
291
292 HotwordPrivateEventService* event_service =
293 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
294 if (event_service)
295 event_service->OnHotwordSessionRequested();
296 }
297
298 void HotwordService::StopHotwordSession(
299 HotwordClient* client) {
rpetterson 2014/05/02 19:13:16 move to line above
Jun Mukai 2014/05/02 22:18:57 Done.
300 if (!IsServiceAvailable())
301 return;
302
303 DCHECK(client_ == client);
304
305 client_ = NULL;
306 HotwordPrivateEventService* event_service =
307 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
308 if (event_service)
309 event_service->OnHotwordSessionStopped();
310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698