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

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: fix 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 "de", 33 "de",
30 "fr", 34 "fr",
31 "ru" 35 "ru"
32 }; 36 };
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 StringToLowerASCII(&normalized_locale); 119 StringToLowerASCII(&normalized_locale);
116 120
117 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 121 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
118 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0) 122 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0)
119 return true; 123 return true;
120 } 124 }
121 return false; 125 return false;
122 } 126 }
123 127
124 HotwordService::HotwordService(Profile* profile) 128 HotwordService::HotwordService(Profile* profile)
125 : profile_(profile) { 129 : profile_(profile),
130 client_(NULL) {
126 // This will be called during profile initialization which is a good time 131 // This will be called during profile initialization which is a good time
127 // to check the user's hotword state. 132 // to check the user's hotword state.
128 HotwordEnabled enabled_state = UNSET; 133 HotwordEnabled enabled_state = UNSET;
129 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) { 134 if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled)) {
130 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 135 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
131 enabled_state = ENABLED; 136 enabled_state = ENABLED;
132 else 137 else
133 enabled_state = DISABLED; 138 enabled_state = DISABLED;
134 } else { 139 } else {
135 // If the preference has not been set the hotword extension should 140 // If the preference has not been set the hotword extension should
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void HotwordService::OnHotwordSearchEnabledChanged( 273 void HotwordService::OnHotwordSearchEnabledChanged(
269 const std::string& pref_name) { 274 const std::string& pref_name) {
270 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 275 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
271 276
272 ExtensionService* extension_service = GetExtensionService(profile_); 277 ExtensionService* extension_service = GetExtensionService(profile_);
273 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 278 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
274 EnableHotwordExtension(extension_service); 279 EnableHotwordExtension(extension_service);
275 else 280 else
276 DisableHotwordExtension(extension_service); 281 DisableHotwordExtension(extension_service);
277 } 282 }
283
284 void HotwordService::RequestHotwordSession(HotwordClient* client) {
285 if (!IsServiceAvailable() || client_)
286 return;
287
288 client_ = client;
289
290 HotwordPrivateEventService* event_service =
291 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
292 if (event_service)
293 event_service->OnHotwordSessionRequested();
294 }
295
296 void HotwordService::StopHotwordSession(HotwordClient* client) {
297 if (!IsServiceAvailable())
298 return;
299
300 DCHECK(client_ == client);
301
302 client_ = NULL;
303 HotwordPrivateEventService* event_service =
304 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
305 if (event_service)
306 event_service->OnHotwordSessionStopped();
307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698