diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-25 04:03:03 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-25 04:03:03 +0000 |
commit | 2b6009cfa76c3b67962566a66a80dc3ad66f9c0b (patch) | |
tree | 0219f72793053a37112d00f14d1d3a5b44d9d846 | |
parent | 533a969a3a34716234c12c09da5e659436a82ab1 (diff) | |
download | chromium_src-2b6009cfa76c3b67962566a66a80dc3ad66f9c0b.zip chromium_src-2b6009cfa76c3b67962566a66a80dc3ad66f9c0b.tar.gz chromium_src-2b6009cfa76c3b67962566a66a80dc3ad66f9c0b.tar.bz2 |
Merge 258556 "[Hotword] Disable the extension if they've never s..."
> [Hotword] Disable the extension if they've never set the preference after install.
>
> The situation is that when the user first installs the extension, the disable during
> HowtordService() occurs before the installation has occurred. Therefore, we need to
> listen for completion of that installation and *then* disable the extension.
>
> BUG=349573
>
> Review URL: https://codereview.chromium.org/206573004
TBR=rlp@chromium.org
Review URL: https://codereview.chromium.org/209383016
git-svn-id: svn://svn.chromium.org/chrome/branches/1847/src@259141 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/search/hotword_service.cc | 26 | ||||
-rw-r--r-- | chrome/browser/search/hotword_service.h | 12 |
2 files changed, 37 insertions, 1 deletions
diff --git a/chrome/browser/search/hotword_service.cc b/chrome/browser/search/hotword_service.cc index b3d5cd3..db5dc5a 100644 --- a/chrome/browser/search/hotword_service.cc +++ b/chrome/browser/search/hotword_service.cc @@ -9,11 +9,13 @@ #include "base/metrics/histogram.h" #include "base/prefs/pref_service.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/chrome_notification_types.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 "content/public/browser/notification_service.h" #include "extensions/browser/extension_system.h" #include "extensions/common/extension.h" #include "ui/base/l10n/l10n_util.h" @@ -117,11 +119,35 @@ HotwordService::HotwordService(Profile* profile) prefs::kHotwordSearchEnabled, base::Bind(&HotwordService::OnHotwordSearchEnabledChanged, base::Unretained(this))); + + registrar_.Add(this, + chrome::NOTIFICATION_EXTENSION_INSTALLED, + content::Source<Profile>(profile_)); } HotwordService::~HotwordService() { } +void HotwordService::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + if (type == chrome::NOTIFICATION_EXTENSION_INSTALLED) { + const extensions::Extension* extension = + content::Details<const extensions::InstalledExtensionInfo>(details) + ->extension; + if (extension->id() == extension_misc::kHotwordExtensionId && + !profile_->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled)) { + DisableHotwordExtension(GetExtensionService(profile_)); + // Once the extension is disabled, it will not be enabled until the + // user opts in at which point the pref registrar will take over + // enabling and disabling. + registrar_.Remove(this, + chrome::NOTIFICATION_EXTENSION_INSTALLED, + content::Source<Profile>(profile_)); + } + } +} + bool HotwordService::ShouldShowOptInPopup() { if (profile_->IsOffTheRecord()) return false; diff --git a/chrome/browser/search/hotword_service.h b/chrome/browser/search/hotword_service.h index a292bb7..84e8cbd 100644 --- a/chrome/browser/search/hotword_service.h +++ b/chrome/browser/search/hotword_service.h @@ -8,6 +8,8 @@ #include "base/basictypes.h" #include "base/prefs/pref_change_registrar.h" #include "components/browser_context_keyed_service/browser_context_keyed_service.h" +#include "content/public/browser/notification_observer.h" +#include "content/public/browser/notification_registrar.h" class ExtensionService; class Profile; @@ -20,7 +22,8 @@ extern const char kHotwordFieldTrialDisabledGroupName[]; // Provides an interface for the Hotword component that does voice triggered // search. -class HotwordService : public BrowserContextKeyedService { +class HotwordService : public content::NotificationObserver, + public BrowserContextKeyedService { public: // Returns true if the hotword supports the current system language. static bool DoesHotwordSupportLanguage(Profile* profile); @@ -28,6 +31,11 @@ class HotwordService : public BrowserContextKeyedService { explicit HotwordService(Profile* profile); virtual ~HotwordService(); + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + bool ShouldShowOptInPopup(); // Used in testing to ensure that the popup is not shown more than this @@ -65,6 +73,8 @@ class HotwordService : public BrowserContextKeyedService { PrefChangeRegistrar pref_registrar_; + content::NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(HotwordService); }; |