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

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: fix unittest compile errors 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
« no previous file with comments | « no previous file | chrome/browser/search/hotword_service.cc » ('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 #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
40 // Checks for whether all the necessary files have downloaded to allow for 58 // Checks for whether all the necessary files have downloaded to allow for
41 // using the extension. 59 // using the extension.
42 virtual bool IsServiceAvailable(); 60 virtual bool IsServiceAvailable();
43 61
44 // Determine if hotwording is allowed in this profile based on field trials 62 // Determine if hotwording is allowed in this profile based on field trials
45 // and language. 63 // and language.
46 virtual bool IsHotwordAllowed(); 64 virtual bool IsHotwordAllowed();
47 65
48 // Checks if the user has opted into audio logging. Returns true if the user 66 // Checks if the user has opted into audio logging. Returns true if the user
49 // is opted in, false otherwise.. 67 // is opted in, false otherwise..
50 bool IsOptedIntoAudioLogging(); 68 bool IsOptedIntoAudioLogging();
51 69
52 // Control the state of the hotword extension. 70 // Control the state of the hotword extension.
53 void EnableHotwordExtension(ExtensionService* extension_service); 71 void EnableHotwordExtension(ExtensionService* extension_service);
54 void DisableHotwordExtension(ExtensionService* extension_service); 72 void DisableHotwordExtension(ExtensionService* extension_service);
55 73
56 // Handles enabling/disabling the hotword extension when the user 74 // Handles enabling/disabling the hotword extension when the user
57 // turns it off via the settings menu. 75 // turns it off via the settings menu.
58 void OnHotwordSearchEnabledChanged(const std::string& pref_name); 76 void OnHotwordSearchEnabledChanged(const std::string& pref_name);
59 77
60 // Called to handle the hotword session from |client|. 78 // Called to handle the hotword session from |client|.
61 void RequestHotwordSession(HotwordClient* client); 79 void RequestHotwordSession(HotwordClient* client);
62 void StopHotwordSession(HotwordClient* client); 80 void StopHotwordSession(HotwordClient* client);
63 HotwordClient* client() { return client_; } 81 HotwordClient* client() { return client_; }
64 82
83 // Checks if the current version of the hotword extension should be
84 // uninstalled in order to update to a different language version.
85 // Returns true if the extension was uninstalled.
86 bool MaybeReinstallHotwordExtension();
87
88 // Checks based on locale if the current version should be uninstalled so that
89 // a version with a different language can be installed.
90 bool ShouldReinstallHotwordExtension();
91
92 // Helper functions pulled out for testing purposes.
93 // UninstallHotwordExtension returns true if the extension was uninstalled.
94 virtual bool UninstallHotwordExtension(ExtensionService* extension_service);
95 virtual void InstallHotwordExtensionFromWebstore();
96
97 // Sets the pref value of the previous language.
98 void SetPreviousLanguagePref();
99
65 // Returns the current error message id. A value of 0 indicates 100 // Returns the current error message id. A value of 0 indicates
66 // no error. 101 // no error.
67 int error_message() { return error_message_; } 102 int error_message() { return error_message_; }
68 103
69 private: 104 private:
70 Profile* profile_; 105 Profile* profile_;
71 106
72 PrefChangeRegistrar pref_registrar_; 107 PrefChangeRegistrar pref_registrar_;
73 108
74 content::NotificationRegistrar registrar_; 109 content::NotificationRegistrar registrar_;
75 110
111 // For observing the ExtensionRegistry.
112 ScopedObserver<extensions::ExtensionRegistry,
113 extensions::ExtensionRegistryObserver>
114 extension_registry_observer_;
115
116 scoped_refptr<extensions::WebstoreStandaloneInstaller> installer_;
117
76 HotwordClient* client_; 118 HotwordClient* client_;
77 int error_message_; 119 int error_message_;
120 bool reinstall_pending_;
121
122 base::WeakPtrFactory<HotwordService> weak_factory_;
78 123
79 DISALLOW_COPY_AND_ASSIGN(HotwordService); 124 DISALLOW_COPY_AND_ASSIGN(HotwordService);
80 }; 125 };
81 126
82 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_ 127 #endif // CHROME_BROWSER_SEARCH_HOTWORD_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search/hotword_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698