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

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

Issue 330193005: [Hotword] Uninstall and reinstall the extension upon language change. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup Created 6 years, 6 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 6 #define CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
9 #include "base/prefs/pref_change_registrar.h" 10 #include "base/prefs/pref_change_registrar.h"
11 #include "base/scoped_observer.h"
10 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
11 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_registry_observer.h"
13 17
14 class ExtensionService; 18 class ExtensionService;
15 class HotwordClient; 19 class HotwordClient;
16 class Profile; 20 class Profile;
17 21
22 namespace extensions {
23 class Extension;
24 class WebstoreStandaloneInstaller;
25 } // namespace extensions
26
18 namespace hotword_internal { 27 namespace hotword_internal {
19 // Constants for the hotword field trial. 28 // Constants for the hotword field trial.
20 extern const char kHotwordFieldTrialName[]; 29 extern const char kHotwordFieldTrialName[];
21 extern const char kHotwordFieldTrialDisabledGroupName[]; 30 extern const char kHotwordFieldTrialDisabledGroupName[];
22 } // namespace hotword_internal 31 } // namespace hotword_internal
23 32
24 // Provides an interface for the Hotword component that does voice triggered 33 // Provides an interface for the Hotword component that does voice triggered
25 // search. 34 // search.
26 class HotwordService : public content::NotificationObserver, 35 class HotwordService : public content::NotificationObserver,
36 public extensions::ExtensionRegistryObserver,
27 public KeyedService { 37 public KeyedService {
28 public: 38 public:
29 // Returns true if the hotword supports the current system language. 39 // Returns true if the hotword supports the current system language.
30 static bool DoesHotwordSupportLanguage(Profile* profile); 40 static bool DoesHotwordSupportLanguage(Profile* profile);
31 41
32 explicit HotwordService(Profile* profile); 42 explicit HotwordService(Profile* profile);
33 virtual ~HotwordService(); 43 virtual ~HotwordService();
34 44
35 // Overridden from content::NotificationObserver: 45 // Overridden from content::NotificationObserver:
36 virtual void Observe(int type, 46 virtual void Observe(int type,
37 const content::NotificationSource& source, 47 const content::NotificationSource& source,
38 const content::NotificationDetails& details) OVERRIDE; 48 const content::NotificationDetails& details) OVERRIDE;
39 49
50 // Overridden from ExtensionRegisterObserver:
51 virtual void OnExtensionInstalled(
52 content::BrowserContext* browser_context,
53 const extensions::Extension* extension) OVERRIDE;
54 virtual void OnExtensionUninstalled(
55 content::BrowserContext* browser_context,
56 const extensions::Extension* extension) OVERRIDE;
57
58 // Checks if the current version of the hotword extension should be
59 // uninstalled in order to update to a different language version.
60 // Returns true if the extension was uninstalled.
61 bool MaybeUninstallHotwordExtension();
62
40 // Checks for whether all the necessary files have downloaded to allow for 63 // Checks for whether all the necessary files have downloaded to allow for
41 // using the extension. 64 // using the extension.
42 virtual bool IsServiceAvailable(); 65 virtual bool IsServiceAvailable();
43 66
44 // Determine if hotwording is allowed in this profile based on field trials 67 // Determine if hotwording is allowed in this profile based on field trials
45 // and language. 68 // and language.
46 virtual bool IsHotwordAllowed(); 69 virtual bool IsHotwordAllowed();
47 70
48 // Checks if the user has opted into audio logging. Returns true if the user 71 // Checks if the user has opted into audio logging. Returns true if the user
49 // is opted in, false otherwise.. 72 // is opted in, false otherwise..
50 bool IsOptedIntoAudioLogging(); 73 bool IsOptedIntoAudioLogging();
51 74
52 // Control the state of the hotword extension. 75 // Control the state of the hotword extension.
53 void EnableHotwordExtension(ExtensionService* extension_service); 76 void EnableHotwordExtension(ExtensionService* extension_service);
54 void DisableHotwordExtension(ExtensionService* extension_service); 77 void DisableHotwordExtension(ExtensionService* extension_service);
55 78
56 // Handles enabling/disabling the hotword extension when the user 79 // Handles enabling/disabling the hotword extension when the user
57 // turns it off via the settings menu. 80 // turns it off via the settings menu.
58 void OnHotwordSearchEnabledChanged(const std::string& pref_name); 81 void OnHotwordSearchEnabledChanged(const std::string& pref_name);
59 82
60 // Called to handle the hotword session from |client|. 83 // Called to handle the hotword session from |client|.
61 void RequestHotwordSession(HotwordClient* client); 84 void RequestHotwordSession(HotwordClient* client);
62 void StopHotwordSession(HotwordClient* client); 85 void StopHotwordSession(HotwordClient* client);
63 HotwordClient* client() { return client_; } 86 HotwordClient* client() { return client_; }
64 87
88 // Checks based on locale if the current version so be uninstalled so that
Yoyo Zhou 2014/06/18 00:33:21 s/so/should/
rpetterson 2014/06/18 02:08:44 Done.
89 // a version with a different language can be installed.
90 bool ShouldUninstallHotwordExtension();
91
92 // Helper functions pulled out for testing purposes.
93 // UinstallHotwordExtension returns true if the extension was uninstalled.
Yoyo Zhou 2014/06/18 00:33:22 typo: Uninstall
rpetterson 2014/06/18 02:08:44 Done.
94 virtual bool UninstallHotwordExtension(ExtensionService* extension_service);
95 virtual void InstallHotwordExtensionFromWebstore();
96
97 // Sets the pref value of the previous locale.
98 void SetPreviousLocalePref();
99
100 // Called when the extension is done being installed after a language
101 // change.
102 void OnHotwordExtensionInstalled(bool success,
103 const std::string& error);
104
65 // Returns the current error message id. A value of 0 indicates 105 // Returns the current error message id. A value of 0 indicates
66 // no error. 106 // no error.
67 int error_message() { return error_message_; } 107 int error_message() { return error_message_; }
68 108
69 private: 109 private:
70 Profile* profile_; 110 Profile* profile_;
71 111
72 PrefChangeRegistrar pref_registrar_; 112 PrefChangeRegistrar pref_registrar_;
73 113
74 content::NotificationRegistrar registrar_; 114 content::NotificationRegistrar registrar_;
75 115
116 // For observing the ExtensionRegistry.
117 ScopedObserver<extensions::ExtensionRegistry,
118 extensions::ExtensionRegistryObserver>
119 extension_registry_observer_;
120
121 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_;
122
76 HotwordClient* client_; 123 HotwordClient* client_;
77 int error_message_; 124 int error_message_;
125 bool uninstall_pending_;
126
127 base::WeakPtrFactory<HotwordService> weak_factory_;
78 128
79 DISALLOW_COPY_AND_ASSIGN(HotwordService); 129 DISALLOW_COPY_AND_ASSIGN(HotwordService);
80 }; 130 };
81 131
82 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 132 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search/hotword_service.cc » ('j') | chrome/browser/search/hotword_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698