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

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

Issue 467113004: Adds a skeleton component app for Always-On Hotwording opt-in flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/common/extensions/extension_constants.h » ('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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" 15 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/pending_extension_manager.h" 17 #include "chrome/browser/extensions/pending_extension_manager.h"
18 #include "chrome/browser/extensions/updater/extension_updater.h" 18 #include "chrome/browser/extensions/updater/extension_updater.h"
19 #include "chrome/browser/extensions/webstore_startup_installer.h" 19 #include "chrome/browser/extensions/webstore_startup_installer.h"
20 #include "chrome/browser/plugins/plugin_prefs.h" 20 #include "chrome/browser/plugins/plugin_prefs.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/search/hotword_service_factory.h" 22 #include "chrome/browser/search/hotword_service_factory.h"
23 #include "chrome/browser/ui/extensions/application_launch.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/plugin_service.h" 31 #include "content/public/browser/plugin_service.h"
31 #include "content/public/common/webplugininfo.h" 32 #include "content/public/common/webplugininfo.h"
32 #include "extensions/browser/extension_system.h" 33 #include "extensions/browser/extension_system.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 208 }
208 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, 209 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
209 NUM_HOTWORD_ENABLED_METRICS); 210 NUM_HOTWORD_ENABLED_METRICS);
210 211
211 pref_registrar_.Init(profile_->GetPrefs()); 212 pref_registrar_.Init(profile_->GetPrefs());
212 pref_registrar_.Add( 213 pref_registrar_.Add(
213 prefs::kHotwordSearchEnabled, 214 prefs::kHotwordSearchEnabled,
214 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, 215 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
215 base::Unretained(this))); 216 base::Unretained(this)));
216 217
218 pref_registrar_.Add(
219 prefs::kHotwordAlwaysOnSearchEnabled,
220 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged,
221 base::Unretained(this)));
222
217 registrar_.Add(this, 223 registrar_.Add(this,
218 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 224 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
219 content::NotificationService::AllSources()); 225 content::NotificationService::AllSources());
220 226
221 extensions::ExtensionSystem::Get(profile_)->ready().Post( 227 extensions::ExtensionSystem::Get(profile_)->ready().Post(
222 FROM_HERE, 228 FROM_HERE,
223 base::Bind(base::IgnoreResult( 229 base::Bind(base::IgnoreResult(
224 &HotwordService::MaybeReinstallHotwordExtension), 230 &HotwordService::MaybeReinstallHotwordExtension),
225 weak_factory_.GetWeakPtr())); 231 weak_factory_.GetWeakPtr()));
226 232
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 443
438 void HotwordService::DisableHotwordExtension( 444 void HotwordService::DisableHotwordExtension(
439 ExtensionService* extension_service) { 445 ExtensionService* extension_service) {
440 if (extension_service) { 446 if (extension_service) {
441 extension_service->DisableExtension( 447 extension_service->DisableExtension(
442 extension_misc::kHotwordExtensionId, 448 extension_misc::kHotwordExtensionId,
443 extensions::Extension::DISABLE_USER_ACTION); 449 extensions::Extension::DISABLE_USER_ACTION);
444 } 450 }
445 } 451 }
446 452
453 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged(
454 const std::string& pref_name) {
455 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled));
456
457 ExtensionService* extension_service = GetExtensionService(profile_);
458 if (!extension_service)
459 return;
460
461 const extensions::Extension* extension = extension_service->GetExtensionById(
462 extension_misc::kHotwordAudioVerificationAppId, true);
463 if (!extension)
464 return;
465
466 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) {
467 OpenApplication(AppLaunchParams(
468 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
469 }
470 }
471
447 void HotwordService::OnHotwordSearchEnabledChanged( 472 void HotwordService::OnHotwordSearchEnabledChanged(
448 const std::string& pref_name) { 473 const std::string& pref_name) {
449 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 474 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
450 475
451 ExtensionService* extension_service = GetExtensionService(profile_); 476 ExtensionService* extension_service = GetExtensionService(profile_);
452 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 477 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
453 EnableHotwordExtension(extension_service); 478 EnableHotwordExtension(extension_service);
454 else 479 else
455 DisableHotwordExtension(extension_service); 480 DisableHotwordExtension(extension_service);
456 } 481 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return false; 517 return false;
493 518
494 std::string previous_locale = 519 std::string previous_locale =
495 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 520 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
496 std::string locale = GetCurrentLocale(profile_); 521 std::string locale = GetCurrentLocale(profile_);
497 522
498 // If it's a new locale, then the old extension should be uninstalled. 523 // If it's a new locale, then the old extension should be uninstalled.
499 return locale != previous_locale && 524 return locale != previous_locale &&
500 HotwordService::DoesHotwordSupportLanguage(profile_); 525 HotwordService::DoesHotwordSupportLanguage(profile_);
501 } 526 }
OLDNEW
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698