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/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search/hotword_client.h" |
10 #include "chrome/browser/search/hotword_service.h" | 11 #include "chrome/browser/search/hotword_service.h" |
11 #include "chrome/browser/search/hotword_service_factory.h" | 12 #include "chrome/browser/search/hotword_service_factory.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "extensions/browser/event_router.h" | 14 #include "extensions/browser/event_router.h" |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 | 17 |
17 namespace OnEnabledChanged = | 18 namespace OnEnabledChanged = |
18 api::hotword_private::OnEnabledChanged; | 19 api::hotword_private::OnEnabledChanged; |
19 | 20 |
(...skipping 24 matching lines...) Expand all Loading... |
44 } | 45 } |
45 | 46 |
46 // static | 47 // static |
47 const char* HotwordPrivateEventService::service_name() { | 48 const char* HotwordPrivateEventService::service_name() { |
48 return "HotwordPrivateEventService"; | 49 return "HotwordPrivateEventService"; |
49 } | 50 } |
50 | 51 |
51 void HotwordPrivateEventService::OnEnabledChanged( | 52 void HotwordPrivateEventService::OnEnabledChanged( |
52 const std::string& pref_name) { | 53 const std::string& pref_name) { |
53 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); | 54 DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled)); |
54 SignalEvent(); | 55 SignalEvent(OnEnabledChanged::kEventName); |
55 } | 56 } |
56 | 57 |
57 void HotwordPrivateEventService::SignalEvent() { | 58 void HotwordPrivateEventService::OnHotwordSessionRequested() { |
58 using OnEnabledChanged::kEventName; | 59 SignalEvent(api::hotword_private::OnHotwordSessionRequested::kEventName); |
| 60 } |
59 | 61 |
| 62 void HotwordPrivateEventService::OnHotwordSessionStopped() { |
| 63 SignalEvent(api::hotword_private::OnHotwordSessionStopped::kEventName); |
| 64 } |
| 65 |
| 66 void HotwordPrivateEventService::SignalEvent(const std::string& event_name) { |
60 EventRouter* router = EventRouter::Get(profile_); | 67 EventRouter* router = EventRouter::Get(profile_); |
61 if (!router || !router->HasEventListener(kEventName)) | 68 if (!router || !router->HasEventListener(event_name)) |
62 return; | 69 return; |
63 scoped_ptr<base::ListValue> args(new base::ListValue()); | 70 scoped_ptr<base::ListValue> args(new base::ListValue()); |
64 scoped_ptr<Event> event(new Event(kEventName, args.Pass())); | 71 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
65 router->BroadcastEvent(event.Pass()); | 72 router->BroadcastEvent(event.Pass()); |
66 } | 73 } |
67 | 74 |
68 bool HotwordPrivateSetEnabledFunction::RunSync() { | 75 bool HotwordPrivateSetEnabledFunction::RunSync() { |
69 scoped_ptr<api::hotword_private::SetEnabled::Params> params( | 76 scoped_ptr<api::hotword_private::SetEnabled::Params> params( |
70 api::hotword_private::SetEnabled::Params::Create(*args_)); | 77 api::hotword_private::SetEnabled::Params::Create(*args_)); |
71 EXTENSION_FUNCTION_VALIDATE(params.get()); | 78 EXTENSION_FUNCTION_VALIDATE(params.get()); |
72 | 79 |
73 PrefService* prefs = GetProfile()->GetPrefs(); | 80 PrefService* prefs = GetProfile()->GetPrefs(); |
74 prefs->SetBoolean(prefs::kHotwordSearchEnabled, params->state); | 81 prefs->SetBoolean(prefs::kHotwordSearchEnabled, params->state); |
(...skipping 24 matching lines...) Expand all Loading... |
99 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); | 106 result.enabled_set = prefs->HasPrefPath(prefs::kHotwordSearchEnabled); |
100 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); | 107 result.enabled = prefs->GetBoolean(prefs::kHotwordSearchEnabled); |
101 result.audio_logging_enabled = false; | 108 result.audio_logging_enabled = false; |
102 if (hotword_service) | 109 if (hotword_service) |
103 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); | 110 result.audio_logging_enabled = hotword_service->IsOptedIntoAudioLogging(); |
104 | 111 |
105 SetResult(result.ToValue().release()); | 112 SetResult(result.ToValue().release()); |
106 return true; | 113 return true; |
107 } | 114 } |
108 | 115 |
| 116 bool HotwordPrivateSetHotwordSessionStateFunction::RunSync() { |
| 117 scoped_ptr<api::hotword_private::SetHotwordSessionState::Params> params( |
| 118 api::hotword_private::SetHotwordSessionState::Params::Create(*args_)); |
| 119 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 120 |
| 121 HotwordService* hotword_service = |
| 122 HotwordServiceFactory::GetForProfile(GetProfile()); |
| 123 if (hotword_service && hotword_service->client()) |
| 124 hotword_service->client()->OnHotwordStateChanged(params->started); |
| 125 return true; |
| 126 } |
| 127 |
| 128 bool HotwordPrivateNotifyHotwordRecognitionFunction::RunSync() { |
| 129 HotwordService* hotword_service = |
| 130 HotwordServiceFactory::GetForProfile(GetProfile()); |
| 131 if (hotword_service && hotword_service->client()) |
| 132 hotword_service->client()->OnHotwordRecognized(); |
| 133 return true; |
| 134 } |
| 135 |
109 } // namespace extensions | 136 } // namespace extensions |
OLD | NEW |