| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 using extensions::api::braille_display_private::BrailleController; | 26 using extensions::api::braille_display_private::BrailleController; |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 | 29 |
| 30 class BrailleDisplayPrivateAPI::DefaultEventDelegate | 30 class BrailleDisplayPrivateAPI::DefaultEventDelegate |
| 31 : public BrailleDisplayPrivateAPI::EventDelegate { | 31 : public BrailleDisplayPrivateAPI::EventDelegate { |
| 32 public: | 32 public: |
| 33 DefaultEventDelegate(EventRouter::Observer* observer, Profile* profile); | 33 DefaultEventDelegate(EventRouter::Observer* observer, Profile* profile); |
| 34 ~DefaultEventDelegate() override; | 34 ~DefaultEventDelegate() override; |
| 35 | 35 |
| 36 void BroadcastEvent(scoped_ptr<Event> event) override; | 36 void BroadcastEvent(std::unique_ptr<Event> event) override; |
| 37 bool HasListener() override; | 37 bool HasListener() override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 EventRouter::Observer* observer_; | 40 EventRouter::Observer* observer_; |
| 41 Profile* profile_; | 41 Profile* profile_; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 BrailleDisplayPrivateAPI::BrailleDisplayPrivateAPI( | 44 BrailleDisplayPrivateAPI::BrailleDisplayPrivateAPI( |
| 45 content::BrowserContext* context) | 45 content::BrowserContext* context) |
| 46 : profile_(Profile::FromBrowserContext(context)), | 46 : profile_(Profile::FromBrowserContext(context)), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 58 LAZY_INSTANCE_INITIALIZER; | 58 LAZY_INSTANCE_INITIALIZER; |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>* | 61 BrowserContextKeyedAPIFactory<BrailleDisplayPrivateAPI>* |
| 62 BrailleDisplayPrivateAPI::GetFactoryInstance() { | 62 BrailleDisplayPrivateAPI::GetFactoryInstance() { |
| 63 return g_factory.Pointer(); | 63 return g_factory.Pointer(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void BrailleDisplayPrivateAPI::OnBrailleDisplayStateChanged( | 66 void BrailleDisplayPrivateAPI::OnBrailleDisplayStateChanged( |
| 67 const DisplayState& display_state) { | 67 const DisplayState& display_state) { |
| 68 scoped_ptr<Event> event( | 68 std::unique_ptr<Event> event( |
| 69 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_DISPLAY_STATE_CHANGED, | 69 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_DISPLAY_STATE_CHANGED, |
| 70 OnDisplayStateChanged::kEventName, | 70 OnDisplayStateChanged::kEventName, |
| 71 OnDisplayStateChanged::Create(display_state))); | 71 OnDisplayStateChanged::Create(display_state))); |
| 72 event_delegate_->BroadcastEvent(std::move(event)); | 72 event_delegate_->BroadcastEvent(std::move(event)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void BrailleDisplayPrivateAPI::OnBrailleKeyEvent(const KeyEvent& key_event) { | 75 void BrailleDisplayPrivateAPI::OnBrailleKeyEvent(const KeyEvent& key_event) { |
| 76 // Key events only go to extensions of the active profile. | 76 // Key events only go to extensions of the active profile. |
| 77 if (!IsProfileActive()) | 77 if (!IsProfileActive()) |
| 78 return; | 78 return; |
| 79 scoped_ptr<Event> event( | 79 std::unique_ptr<Event> event( |
| 80 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_KEY_EVENT, | 80 new Event(events::BRAILLE_DISPLAY_PRIVATE_ON_KEY_EVENT, |
| 81 OnKeyEvent::kEventName, OnKeyEvent::Create(key_event))); | 81 OnKeyEvent::kEventName, OnKeyEvent::Create(key_event))); |
| 82 event_delegate_->BroadcastEvent(std::move(event)); | 82 event_delegate_->BroadcastEvent(std::move(event)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool BrailleDisplayPrivateAPI::IsProfileActive() { | 85 bool BrailleDisplayPrivateAPI::IsProfileActive() { |
| 86 #if defined(OS_CHROMEOS) | 86 #if defined(OS_CHROMEOS) |
| 87 Profile* active_profile; | 87 Profile* active_profile; |
| 88 chromeos::ScreenLocker* screen_locker = | 88 chromeos::ScreenLocker* screen_locker = |
| 89 chromeos::ScreenLocker::default_screen_locker(); | 89 chromeos::ScreenLocker::default_screen_locker(); |
| 90 if (screen_locker && screen_locker->locked()) { | 90 if (screen_locker && screen_locker->locked()) { |
| 91 active_profile = chromeos::ProfileHelper::GetSigninProfile(); | 91 active_profile = chromeos::ProfileHelper::GetSigninProfile(); |
| 92 } else { | 92 } else { |
| 93 // 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 |
| 94 // 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, |
| 95 // this code will need to be changed. | 95 // this code will need to be changed. |
| 96 active_profile = ProfileManager::GetActiveUserProfile(); | 96 active_profile = ProfileManager::GetActiveUserProfile(); |
| 97 } | 97 } |
| 98 return profile_->IsSameProfile(active_profile); | 98 return profile_->IsSameProfile(active_profile); |
| 99 #else // !defined(OS_CHROMEOS) | 99 #else // !defined(OS_CHROMEOS) |
| 100 return true; | 100 return true; |
| 101 #endif | 101 #endif |
| 102 } | 102 } |
| 103 | 103 |
| 104 void BrailleDisplayPrivateAPI::SetEventDelegateForTest( | 104 void BrailleDisplayPrivateAPI::SetEventDelegateForTest( |
| 105 scoped_ptr<EventDelegate> delegate) { | 105 std::unique_ptr<EventDelegate> delegate) { |
| 106 event_delegate_ = std::move(delegate); | 106 event_delegate_ = std::move(delegate); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void BrailleDisplayPrivateAPI::OnListenerAdded( | 109 void BrailleDisplayPrivateAPI::OnListenerAdded( |
| 110 const EventListenerInfo& details) { | 110 const EventListenerInfo& details) { |
| 111 BrailleController* braille_controller = BrailleController::GetInstance(); | 111 BrailleController* braille_controller = BrailleController::GetInstance(); |
| 112 if (!scoped_observer_.IsObserving(braille_controller)) | 112 if (!scoped_observer_.IsObserving(braille_controller)) |
| 113 scoped_observer_.Add(braille_controller); | 113 scoped_observer_.Add(braille_controller); |
| 114 } | 114 } |
| 115 | 115 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 128 EventRouter* event_router = EventRouter::Get(profile_); | 128 EventRouter* event_router = EventRouter::Get(profile_); |
| 129 event_router->RegisterObserver(observer_, OnDisplayStateChanged::kEventName); | 129 event_router->RegisterObserver(observer_, OnDisplayStateChanged::kEventName); |
| 130 event_router->RegisterObserver(observer_, OnKeyEvent::kEventName); | 130 event_router->RegisterObserver(observer_, OnKeyEvent::kEventName); |
| 131 } | 131 } |
| 132 | 132 |
| 133 BrailleDisplayPrivateAPI::DefaultEventDelegate::~DefaultEventDelegate() { | 133 BrailleDisplayPrivateAPI::DefaultEventDelegate::~DefaultEventDelegate() { |
| 134 EventRouter::Get(profile_)->UnregisterObserver(observer_); | 134 EventRouter::Get(profile_)->UnregisterObserver(observer_); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void BrailleDisplayPrivateAPI::DefaultEventDelegate::BroadcastEvent( | 137 void BrailleDisplayPrivateAPI::DefaultEventDelegate::BroadcastEvent( |
| 138 scoped_ptr<Event> event) { | 138 std::unique_ptr<Event> event) { |
| 139 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); | 139 EventRouter::Get(profile_)->BroadcastEvent(std::move(event)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool BrailleDisplayPrivateAPI::DefaultEventDelegate::HasListener() { | 142 bool BrailleDisplayPrivateAPI::DefaultEventDelegate::HasListener() { |
| 143 EventRouter* event_router = EventRouter::Get(profile_); | 143 EventRouter* event_router = EventRouter::Get(profile_); |
| 144 return (event_router->HasEventListener(OnDisplayStateChanged::kEventName) || | 144 return (event_router->HasEventListener(OnDisplayStateChanged::kEventName) || |
| 145 event_router->HasEventListener(OnKeyEvent::kEventName)); | 145 event_router->HasEventListener(OnKeyEvent::kEventName)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 namespace api { | 148 namespace api { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 175 | 175 |
| 176 void BrailleDisplayPrivateWriteDotsFunction::Work() { | 176 void BrailleDisplayPrivateWriteDotsFunction::Work() { |
| 177 BrailleController::GetInstance()->WriteDots(params_->cells); | 177 BrailleController::GetInstance()->WriteDots(params_->cells); |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool BrailleDisplayPrivateWriteDotsFunction::Respond() { | 180 bool BrailleDisplayPrivateWriteDotsFunction::Respond() { |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 } // namespace api | 183 } // namespace api |
| 184 } // namespace extensions | 184 } // namespace extensions |
| OLD | NEW |