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

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

Issue 471853002: Use the new hotword extension in the launcher when it is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
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/command_line.h"
7 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
8 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" 15 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/pending_extension_manager.h" 17 #include "chrome/browser/extensions/pending_extension_manager.h"
17 #include "chrome/browser/extensions/updater/extension_updater.h" 18 #include "chrome/browser/extensions/updater/extension_updater.h"
18 #include "chrome/browser/extensions/webstore_startup_installer.h" 19 #include "chrome/browser/extensions/webstore_startup_installer.h"
19 #include "chrome/browser/plugins/plugin_prefs.h" 20 #include "chrome/browser/plugins/plugin_prefs.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/search/hotword_service_factory.h" 22 #include "chrome/browser/search/hotword_service_factory.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/plugin_service.h" 29 #include "content/public/browser/plugin_service.h"
28 #include "content/public/common/webplugininfo.h" 30 #include "content/public/common/webplugininfo.h"
29 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
30 #include "extensions/browser/uninstall_reason.h" 32 #include "extensions/browser/uninstall_reason.h"
31 #include "extensions/common/extension.h" 33 #include "extensions/common/extension.h"
32 #include "extensions/common/one_shot_event.h" 34 #include "extensions/common/one_shot_event.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 l10n_util::NormalizeLocale(GetCurrentLocale(profile)); 168 l10n_util::NormalizeLocale(GetCurrentLocale(profile));
167 base::StringToLowerASCII(&normalized_locale); 169 base::StringToLowerASCII(&normalized_locale);
168 170
169 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) { 171 for (size_t i = 0; i < arraysize(kSupportedLocales); i++) {
170 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0) 172 if (normalized_locale.compare(0, 2, kSupportedLocales[i]) == 0)
171 return true; 173 return true;
172 } 174 }
173 return false; 175 return false;
174 } 176 }
175 177
178 // static
179 bool HotwordService::IsExperimentalHotwordingEnabled() {
180 CommandLine* command_line = CommandLine::ForCurrentProcess();
181 return command_line->HasSwitch(switches::kEnableExperimentalHotwording);
182 }
183
176 HotwordService::HotwordService(Profile* profile) 184 HotwordService::HotwordService(Profile* profile)
177 : profile_(profile), 185 : profile_(profile),
178 extension_registry_observer_(this), 186 extension_registry_observer_(this),
179 client_(NULL), 187 client_(NULL),
180 error_message_(0), 188 error_message_(0),
181 reinstall_pending_(false), 189 reinstall_pending_(false),
182 weak_factory_(this) { 190 weak_factory_(this) {
183 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile)); 191 extension_registry_observer_.Add(extensions::ExtensionRegistry::Get(profile));
184 // This will be called during profile initialization which is a good time 192 // This will be called during profile initialization which is a good time
185 // to check the user's hotword state. 193 // to check the user's hotword state.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 448 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
441 449
442 ExtensionService* extension_service = GetExtensionService(profile_); 450 ExtensionService* extension_service = GetExtensionService(profile_);
443 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 451 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
444 EnableHotwordExtension(extension_service); 452 EnableHotwordExtension(extension_service);
445 else 453 else
446 DisableHotwordExtension(extension_service); 454 DisableHotwordExtension(extension_service);
447 } 455 }
448 456
449 void HotwordService::RequestHotwordSession(HotwordClient* client) { 457 void HotwordService::RequestHotwordSession(HotwordClient* client) {
450 if (!IsServiceAvailable() || client_) 458 if (!IsServiceAvailable() || (client_ && client_ != client))
arv (Not doing code reviews) 2014/08/14 15:48:06 This looks suspicious. Why are we exiting if the p
Jun Mukai 2014/08/14 22:10:08 IIRC there is only one client instance right now.
Anand Mistry (off Chromium) 2014/08/15 00:14:51 I have no plans to add additional clients. My only
Jun Mukai 2014/08/15 00:30:07 You seems not answering to our concerns. If we ca
451 return; 459 return;
452 460
453 client_ = client; 461 client_ = client;
454 462
455 HotwordPrivateEventService* event_service = 463 HotwordPrivateEventService* event_service =
456 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_); 464 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>::Get(profile_);
457 if (event_service) 465 if (event_service)
458 event_service->OnHotwordSessionRequested(); 466 event_service->OnHotwordSessionRequested();
459 } 467 }
460 468
(...skipping 22 matching lines...) Expand all
483 return false; 491 return false;
484 492
485 std::string previous_locale = 493 std::string previous_locale =
486 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 494 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
487 std::string locale = GetCurrentLocale(profile_); 495 std::string locale = GetCurrentLocale(profile_);
488 496
489 // If it's a new locale, then the old extension should be uninstalled. 497 // If it's a new locale, then the old extension should be uninstalled.
490 return locale != previous_locale && 498 return locale != previous_locale &&
491 HotwordService::DoesHotwordSupportLanguage(profile_); 499 HotwordService::DoesHotwordSupportLanguage(profile_);
492 } 500 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698