OLD | NEW |
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 #include "chrome/browser/extensions/api/braille_display_private/braille_display_
private_api.h" | 5 #include "chrome/browser/extensions/api/braille_display_private/braille_display_
private_api.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
9 #include "chrome/browser/extensions/api/braille_display_private/braille_controll
er.h" | 11 #include "chrome/browser/extensions/api/braille_display_private/braille_controll
er.h" |
10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
12 | 14 |
13 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
14 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 16 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
16 #endif | 18 #endif |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 BrailleDisplayPrivateAPI::GetFactoryInstance() { | 62 BrailleDisplayPrivateAPI::GetFactoryInstance() { |
61 return g_factory.Pointer(); | 63 return g_factory.Pointer(); |
62 } | 64 } |
63 | 65 |
64 void BrailleDisplayPrivateAPI::OnBrailleDisplayStateChanged( | 66 void BrailleDisplayPrivateAPI::OnBrailleDisplayStateChanged( |
65 const DisplayState& display_state) { | 67 const DisplayState& display_state) { |
66 scoped_ptr<Event> event( | 68 scoped_ptr<Event> event( |
67 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_DISPLAY_STATE_CHANGED, | 69 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_DISPLAY_STATE_CHANGED, |
68 OnDisplayStateChanged::kEventName, | 70 OnDisplayStateChanged::kEventName, |
69 OnDisplayStateChanged::Create(display_state))); | 71 OnDisplayStateChanged::Create(display_state))); |
70 event_delegate_->BroadcastEvent(event.Pass()); | 72 event_delegate_->BroadcastEvent(std::move(event)); |
71 } | 73 } |
72 | 74 |
73 void BrailleDisplayPrivateAPI::OnBrailleKeyEvent(const KeyEvent& key_event) { | 75 void BrailleDisplayPrivateAPI::OnBrailleKeyEvent(const KeyEvent& key_event) { |
74 // Key events only go to extensions of the active profile. | 76 // Key events only go to extensions of the active profile. |
75 if (!IsProfileActive()) | 77 if (!IsProfileActive()) |
76 return; | 78 return; |
77 scoped_ptr<Event> event( | 79 scoped_ptr<Event> event( |
78 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_KEY_EVENT, | 80 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_KEY_EVENT, |
79 OnKeyEvent::kEventName, OnKeyEvent::Create(key_event))); | 81 OnKeyEvent::kEventName, OnKeyEvent::Create(key_event))); |
80 event_delegate_->BroadcastEvent(event.Pass()); | 82 event_delegate_->BroadcastEvent(std::move(event)); |
81 } | 83 } |
82 | 84 |
83 bool BrailleDisplayPrivateAPI::IsProfileActive() { | 85 bool BrailleDisplayPrivateAPI::IsProfileActive() { |
84 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
85 Profile* active_profile; | 87 Profile* active_profile; |
86 chromeos::ScreenLocker* screen_locker = | 88 chromeos::ScreenLocker* screen_locker = |
87 chromeos::ScreenLocker::default_screen_locker(); | 89 chromeos::ScreenLocker::default_screen_locker(); |
88 if (screen_locker && screen_locker->locked()) { | 90 if (screen_locker && screen_locker->locked()) { |
89 active_profile = chromeos::ProfileHelper::GetSigninProfile(); | 91 active_profile = chromeos::ProfileHelper::GetSigninProfile(); |
90 } else { | 92 } else { |
91 // Since we are creating one instance per profile / user, we should be fine | 93 // Since we are creating one instance per profile / user, we should be fine |
92 // comparing against the active user. That said - if we ever change that, | 94 // comparing against the active user. That said - if we ever change that, |
93 // this code will need to be changed. | 95 // this code will need to be changed. |
94 active_profile = ProfileManager::GetActiveUserProfile(); | 96 active_profile = ProfileManager::GetActiveUserProfile(); |
95 } | 97 } |
96 return profile_->IsSameProfile(active_profile); | 98 return profile_->IsSameProfile(active_profile); |
97 #else // !defined(OS_CHROMEOS) | 99 #else // !defined(OS_CHROMEOS) |
98 return true; | 100 return true; |
99 #endif | 101 #endif |
100 } | 102 } |
101 | 103 |
102 void BrailleDisplayPrivateAPI::SetEventDelegateForTest( | 104 void BrailleDisplayPrivateAPI::SetEventDelegateForTest( |
103 scoped_ptr<EventDelegate> delegate) { | 105 scoped_ptr<EventDelegate> delegate) { |
104 event_delegate_ = delegate.Pass(); | 106 event_delegate_ = std::move(delegate); |
105 } | 107 } |
106 | 108 |
107 void BrailleDisplayPrivateAPI::OnListenerAdded( | 109 void BrailleDisplayPrivateAPI::OnListenerAdded( |
108 const EventListenerInfo& details) { | 110 const EventListenerInfo& details) { |
109 BrailleController* braille_controller = BrailleController::GetInstance(); | 111 BrailleController* braille_controller = BrailleController::GetInstance(); |
110 if (!scoped_observer_.IsObserving(braille_controller)) | 112 if (!scoped_observer_.IsObserving(braille_controller)) |
111 scoped_observer_.Add(braille_controller); | 113 scoped_observer_.Add(braille_controller); |
112 } | 114 } |
113 | 115 |
114 void BrailleDisplayPrivateAPI::OnListenerRemoved( | 116 void BrailleDisplayPrivateAPI::OnListenerRemoved( |
(...skipping 12 matching lines...) Expand all Loading... |
127 event_router->RegisterObserver(observer_, OnDisplayStateChanged::kEventName); | 129 event_router->RegisterObserver(observer_, OnDisplayStateChanged::kEventName); |
128 event_router->RegisterObserver(observer_, OnKeyEvent::kEventName); | 130 event_router->RegisterObserver(observer_, OnKeyEvent::kEventName); |
129 } | 131 } |
130 | 132 |
131 BrailleDisplayPrivateAPI::DefaultEventDelegate::~DefaultEventDelegate() { | 133 BrailleDisplayPrivateAPI::DefaultEventDelegate::~DefaultEventDelegate() { |
132 EventRouter::Get(profile_)->UnregisterObserver(observer_); | 134 EventRouter::Get(profile_)->UnregisterObserver(observer_); |
133 } | 135 } |
134 | 136 |
135 void BrailleDisplayPrivateAPI::DefaultEventDelegate::BroadcastEvent( | 137 void BrailleDisplayPrivateAPI::DefaultEventDelegate::BroadcastEvent( |
136 scoped_ptr<Event> event) { | 138 scoped_ptr<Event> event) { |
137 EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); | 139 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); |
138 } | 140 } |
139 | 141 |
140 bool BrailleDisplayPrivateAPI::DefaultEventDelegate::HasListener() { | 142 bool BrailleDisplayPrivateAPI::DefaultEventDelegate::HasListener() { |
141 EventRouter* event_router = EventRouter::Get(profile_); | 143 EventRouter* event_router = EventRouter::Get(profile_); |
142 return (event_router->HasEventListener(OnDisplayStateChanged::kEventName) || | 144 return (event_router->HasEventListener(OnDisplayStateChanged::kEventName) || |
143 event_router->HasEventListener(OnKeyEvent::kEventName)); | 145 event_router->HasEventListener(OnKeyEvent::kEventName)); |
144 } | 146 } |
145 | 147 |
146 namespace api { | 148 namespace api { |
147 bool BrailleDisplayPrivateGetDisplayStateFunction::Prepare() { | 149 bool BrailleDisplayPrivateGetDisplayStateFunction::Prepare() { |
(...skipping 25 matching lines...) Expand all Loading... |
173 | 175 |
174 void BrailleDisplayPrivateWriteDotsFunction::Work() { | 176 void BrailleDisplayPrivateWriteDotsFunction::Work() { |
175 BrailleController::GetInstance()->WriteDots(params_->cells); | 177 BrailleController::GetInstance()->WriteDots(params_->cells); |
176 } | 178 } |
177 | 179 |
178 bool BrailleDisplayPrivateWriteDotsFunction::Respond() { | 180 bool BrailleDisplayPrivateWriteDotsFunction::Respond() { |
179 return true; | 181 return true; |
180 } | 182 } |
181 } // namespace api | 183 } // namespace api |
182 } // namespace extensions | 184 } // namespace extensions |
OLD | NEW |