OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/api/hotword_private/hotword_private_api.h" | 5 #include "chrome/browser/extensions/api/hotword_private/hotword_private_api.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
26 | 26 |
27 HotwordPrivateEventService::HotwordPrivateEventService( | 27 HotwordPrivateEventService::HotwordPrivateEventService( |
28 content::BrowserContext* context) | 28 content::BrowserContext* context) |
29 : profile_(Profile::FromBrowserContext(context)) { | 29 : profile_(Profile::FromBrowserContext(context)) { |
30 pref_change_registrar_.Init(profile_->GetPrefs()); | 30 pref_change_registrar_.Init(profile_->GetPrefs()); |
31 pref_change_registrar_.Add( | 31 pref_change_registrar_.Add( |
32 prefs::kHotwordSearchEnabled, | 32 prefs::kHotwordSearchEnabled, |
33 base::Bind(&HotwordPrivateEventService::OnEnabledChanged, | 33 base::Bind(&HotwordPrivateEventService::OnEnabledChanged, |
34 base::Unretained(this))); | 34 base::Unretained(this))); |
| 35 pref_change_registrar_.Add( |
| 36 prefs::kHotwordAlwaysOnSearchEnabled, |
| 37 base::Bind(&HotwordPrivateEventService::OnEnabledChanged, |
| 38 base::Unretained(this))); |
35 } | 39 } |
36 | 40 |
37 HotwordPrivateEventService::~HotwordPrivateEventService() { | 41 HotwordPrivateEventService::~HotwordPrivateEventService() { |
38 } | 42 } |
39 | 43 |
40 void HotwordPrivateEventService::Shutdown() { | 44 void HotwordPrivateEventService::Shutdown() { |
41 } | 45 } |
42 | 46 |
43 // static | 47 // static |
44 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>* | 48 BrowserContextKeyedAPIFactory<HotwordPrivateEventService>* |
45 HotwordPrivateEventService::GetFactoryInstance() { | 49 HotwordPrivateEventService::GetFactoryInstance() { |
46 return g_factory.Pointer(); | 50 return g_factory.Pointer(); |
47 } | 51 } |
48 | 52 |
49 // static | 53 // static |
50 const char* HotwordPrivateEventService::service_name() { | 54 const char* HotwordPrivateEventService::service_name() { |
51 return "HotwordPrivateEventService"; | 55 return "HotwordPrivateEventService"; |
52 } | 56 } |
53 | 57 |
54 void HotwordPrivateEventService::OnEnabledChanged( | 58 void HotwordPrivateEventService::OnEnabledChanged( |
55 const std::string& pref_name) { | 59 const std::string& pref_name) { |
56 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); | 60 DCHECK(pref_name == std::string(prefs::kHotwordSearchEnabled) || |
| 61 pref_name == std::string(prefs::kHotwordAlwaysOnSearchEnabled)); |
57 SignalEvent(OnEnabledChanged::kEventName); | 62 SignalEvent(OnEnabledChanged::kEventName); |
58 } | 63 } |
59 | 64 |
60 void HotwordPrivateEventService::OnHotwordSessionRequested() { | 65 void HotwordPrivateEventService::OnHotwordSessionRequested() { |
61 SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName); | 66 SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName); |
62 } | 67 } |
63 | 68 |
64 void HotwordPrivateEventService::OnHotwordSessionStopped() { | 69 void HotwordPrivateEventService::OnHotwordSessionStopped() { |
65 SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName); | 70 SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName); |
66 } | 71 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 HotwordService* hotword_service = | 105 HotwordService* hotword_service = |
101 HotwordServiceFactory::GetForProfile(GetProfile()); | 106 HotwordServiceFactory::GetForProfile(GetProfile()); |
102 if (!hotword_service) | 107 if (!hotword_service) |
103 result.available = false; | 108 result.available = false; |
104 else | 109 else |
105 result.available = hotword_service->IsServiceAvailable(); | 110 result.available = hotword_service->IsServiceAvailable(); |
106 | 111 |
107 PrefService* prefs = GetProfile()->GetPrefs(); | 112 PrefService* prefs = GetProfile()->GetPrefs(); |
108 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); | 113 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); |
109 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); | 114 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); |
| 115 result.always_on_enabled = |
| 116 prefs->GetBoolean(prefs::kHotwordAlwaysOnSearchEnabled); |
110 result.audio_logging_enabled = false; | 117 result.audio_logging_enabled = false; |
111 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 118 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
112 result.experimental_hotword_enabled = command_line->HasSwitch( | 119 result.experimental_hotword_enabled = command_line->HasSwitch( |
113 switches::kEnableExperimentalHotwording); | 120 switches::kEnableExperimentalHotwording); |
114 if (hotword_service) | 121 if (hotword_service) |
115 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); | 122 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); |
116 | 123 |
117 SetResult(result.ToValue().release()); | 124 SetResult(result.ToValue().release()); |
118 return true; | 125 return true; |
119 } | 126 } |
(...skipping 12 matching lines...) Expand all Loading... |
132 | 139 |
133 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { | 140 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { |
134 HotwordService* hotword_service = | 141 HotwordService* hotword_service = |
135 HotwordServiceFactory::GetForProfile(GetProfile()); | 142 HotwordServiceFactory::GetForProfile(GetProfile()); |
136 if (hotword_service && hotword_service->client()) | 143 if (hotword_service && hotword_service->client()) |
137 hotword_service->client()->OnHotwordRecognized(); | 144 hotword_service->client()->OnHotwordRecognized(); |
138 return true; | 145 return true; |
139 } | 146 } |
140 | 147 |
141 } // namespace extensions | 148 } // namespace extensions |
OLD | NEW |