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

Unified Diff: chrome/browser/search/hotword_service.cc

Issue 196753002: [Hotword] Making enabling/disabling the setting enable/disable the hotword extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | extensions/browser/admin_policy.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search/hotword_service.cc
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc
index b9f4bfd7d7452beab3561f312bb697f9998091c5..a0854e915834938616931b93ad8a33f4383a8d69 100644
--- a/chrome/browser/search/hotword_service.cc
+++ b/chrome/browser/search/hotword_service.cc
@@ -8,12 +8,15 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
+#include "base/threading/worker_pool.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
@@ -94,9 +97,19 @@ HotwordService::HotwordService(Profile* profile)
enabled_state = ENABLED;
else
enabled_state = DISABLED;
+ } else {
+ // If the preference has not been set the hotword extension should
+ // not be running.
+ DisableHotwordExtension();
}
UMA_HISTOGRAM_ENUMERATION("Hotword.Enabled", enabled_state,
NUM_HOTWORD_ENABLED_METRICS);
+
+ pref_registrar_.Init(profile_->GetPrefs());
+ pref_registrar_.Add(
+ prefs::kHotwordSearchEnabled,
+ base::Bind(&HotwordService::OnHotwordSearchEnabledChanged,
+ base::Unretained(this)));
}
HotwordService::~HotwordService() {
@@ -134,7 +147,7 @@ bool HotwordService::IsServiceAvailable() {
// Do not include disabled extension (false parameter) because if the
Jered 2014/03/12 20:43:45 nit: Update this comment.
rpetterson 2014/03/12 20:51:25 Done.
// extension is disabled, it's not available.
const extensions::Extension* extension =
- service->GetExtensionById(extension_misc::kHotwordExtensionId, false);
+ service->GetExtensionById(extension_misc::kHotwordExtensionId, true);
RecordAvailabilityMetrics(service, extension);
@@ -161,3 +174,39 @@ bool HotwordService::RetryHotwordExtension() {
extension_service->ReloadExtension(extension_misc::kHotwordExtensionId);
return true;
}
+
+void HotwordService::DisableHotwordExtension() {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile_);
+ if (!extension_system || !extension_system->extension_service())
+ return;
+ ExtensionService* extension_service = extension_system->extension_service();
+
+ extension_service->DisableExtension(
+ extension_misc::kHotwordExtensionId,
+ extensions::Extension::DISABLE_USER_ACTION);
+}
+
+void HotwordService::EnableHotwordExtension() {
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ extensions::ExtensionSystem* extension_system =
+ extensions::ExtensionSystem::Get(profile_);
+ if (!extension_system || !extension_system->extension_service())
+ return;
+ ExtensionService* extension_service = extension_system->extension_service();
+
+ extension_service->EnableExtension(extension_misc::kHotwordExtensionId);
+}
+
+void HotwordService::OnHotwordSearchEnabledChanged(
+ const std::string& pref_name) {
+ DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
+
+ if (profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled))
+ EnableHotwordExtension();
+ else
+ DisableHotwordExtension();
+}
« no previous file with comments | « chrome/browser/search/hotword_service.h ('k') | extensions/browser/admin_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698