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

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: 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/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/path_service.h" 10 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" 14 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/pending_extension_manager.h" 16 #include "chrome/browser/extensions/pending_extension_manager.h"
17 #include "chrome/browser/extensions/updater/extension_updater.h" 17 #include "chrome/browser/extensions/updater/extension_updater.h"
18 #include "chrome/browser/extensions/webstore_startup_installer.h" 18 #include "chrome/browser/extensions/webstore_startup_installer.h"
19 #include "chrome/browser/plugins/plugin_prefs.h" 19 #include "chrome/browser/plugins/plugin_prefs.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/search/hotword_service_factory.h" 21 #include "chrome/browser/search/hotword_service_factory.h"
22 #include "chrome/browser/ui/extensions/application_launch.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/extensions/extension_constants.h" 24 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/plugin_service.h" 28 #include "content/public/browser/plugin_service.h"
28 #include "content/public/common/webplugininfo.h" 29 #include "content/public/common/webplugininfo.h"
29 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
30 #include "extensions/browser/uninstall_reason.h" 31 #include "extensions/browser/uninstall_reason.h"
31 #include "extensions/common/extension.h" 32 #include "extensions/common/extension.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 199 }
199 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state, 200 UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
200 NUM_HOTWORD_ENABLED_METRICS); 201 NUM_HOTWORD_ENABLED_METRICS);
201 202
202 pref_registrar_.Init(profile_->GetPrefs()); 203 pref_registrar_.Init(profile_->GetPrefs());
203 pref_registrar_.Add( 204 pref_registrar_.Add(
204 prefs::kHotwordSearchEnabled, 205 prefs::kHotwordSearchEnabled,
205 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, 206 base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
206 base::Unretained(this))); 207 base::Unretained(this)));
207 208
209 pref_registrar_.Add(
210 prefs::kHotwordAlwaysOnSearchEnabled,
211 base::Bind(&HotwordService::OnHotwordAlwaysOnSearchEnabledChanged,
212 base::Unretained(this)));
213
208 registrar_.Add(this, 214 registrar_.Add(this,
209 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 215 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
210 content::NotificationService::AllSources()); 216 content::NotificationService::AllSources());
211 217
212 extensions::ExtensionSystem::Get(profile_)->ready().Post( 218 extensions::ExtensionSystem::Get(profile_)->ready().Post(
213 FROM_HERE, 219 FROM_HERE,
214 base::Bind(base::IgnoreResult( 220 base::Bind(base::IgnoreResult(
215 &HotwordService::MaybeReinstallHotwordExtension), 221 &HotwordService::MaybeReinstallHotwordExtension),
216 weak_factory_.GetWeakPtr())); 222 weak_factory_.GetWeakPtr()));
217 223
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 434
429 void HotwordService::DisableHotwordExtension( 435 void HotwordService::DisableHotwordExtension(
430 ExtensionService* extension_service) { 436 ExtensionService* extension_service) {
431 if (extension_service) { 437 if (extension_service) {
432 extension_service->DisableExtension( 438 extension_service->DisableExtension(
433 extension_misc::kHotwordExtensionId, 439 extension_misc::kHotwordExtensionId,
434 extensions::Extension::DISABLE_USER_ACTION); 440 extensions::Extension::DISABLE_USER_ACTION);
435 } 441 }
436 } 442 }
437 443
444 void HotwordService::OnHotwordAlwaysOnSearchEnabledChanged(
445 const std::string& pref_name) {
446 DCHECK_EQ(pref_name, std::string(prefs::kHotwordAlwaysOnSearchEnabled));
447
448 ExtensionService* extension_service = GetExtensionService(profile_);
449 if (!extension_service)
450 return;
451
452 const extensions::Extension* extension = extension_service->GetExtensionById(
453 extension_misc::kHotwordAudioVerificationExtensionId, true);
454 if (!extension)
455 return;
456
457 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled)) {
458 OpenApplication(AppLaunchParams(
459 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
460 }
461 }
462
438 void HotwordService::OnHotwordSearchEnabledChanged( 463 void HotwordService::OnHotwordSearchEnabledChanged(
439 const std::string& pref_name) { 464 const std::string& pref_name) {
440 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); 465 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
441 466
442 ExtensionService* extension_service = GetExtensionService(profile_); 467 ExtensionService* extension_service = GetExtensionService(profile_);
443 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) 468 if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
444 EnableHotwordExtension(extension_service); 469 EnableHotwordExtension(extension_service);
445 else 470 else
446 DisableHotwordExtension(extension_service); 471 DisableHotwordExtension(extension_service);
447 } 472 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 return false; 508 return false;
484 509
485 std::string previous_locale = 510 std::string previous_locale =
486 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage); 511 profile_->GetPrefs()->GetString(prefs::kHotwordPreviousLanguage);
487 std::string locale = GetCurrentLocale(profile_); 512 std::string locale = GetCurrentLocale(profile_);
488 513
489 // If it's a new locale, then the old extension should be uninstalled. 514 // If it's a new locale, then the old extension should be uninstalled.
490 return locale != previous_locale && 515 return locale != previous_locale &&
491 HotwordService::DoesHotwordSupportLanguage(profile_); 516 HotwordService::DoesHotwordSupportLanguage(profile_);
492 } 517 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698