| 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/serial/serial_event_dispatcher.h" | 5 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 8 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "extensions/browser/event_router.h" | 11 #include "extensions/browser/event_router.h" |
| 12 #include "extensions/browser/extension_system.h" | 12 #include "extensions/browser/extension_system.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace api { | 16 namespace api { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 bool ShouldPauseOnReceiveError(serial::ReceiveError error) { | 20 bool ShouldPauseOnReceiveError(serial::ReceiveError error) { |
| 21 return error == serial::RECEIVE_ERROR_DEVICE_LOST || | 21 return error == serial::RECEIVE_ERROR_DEVICE_LOST || |
| 22 error == serial::RECEIVE_ERROR_SYSTEM_ERROR || | 22 error == serial::RECEIVE_ERROR_SYSTEM_ERROR || |
| 23 error == serial::RECEIVE_ERROR_DISCONNECTED; | 23 error == serial::RECEIVE_ERROR_DISCONNECTED; |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 static base::LazyInstance<ProfileKeyedAPIFactory<SerialEventDispatcher> > | 28 static base::LazyInstance<BrowserContextKeyedAPIFactory<SerialEventDispatcher> > |
| 29 g_factory = LAZY_INSTANCE_INITIALIZER; | 29 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 ProfileKeyedAPIFactory<SerialEventDispatcher>* | 32 BrowserContextKeyedAPIFactory<SerialEventDispatcher>* |
| 33 SerialEventDispatcher::GetFactoryInstance() { | 33 SerialEventDispatcher::GetFactoryInstance() { |
| 34 return g_factory.Pointer(); | 34 return g_factory.Pointer(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 SerialEventDispatcher* SerialEventDispatcher::Get( | 38 SerialEventDispatcher* SerialEventDispatcher::Get( |
| 39 content::BrowserContext* context) { | 39 content::BrowserContext* context) { |
| 40 return ProfileKeyedAPIFactory<SerialEventDispatcher>::GetForProfile(context); | 40 return BrowserContextKeyedAPIFactory<SerialEventDispatcher>::Get(context); |
| 41 } | 41 } |
| 42 | 42 |
| 43 SerialEventDispatcher::SerialEventDispatcher(content::BrowserContext* context) | 43 SerialEventDispatcher::SerialEventDispatcher(content::BrowserContext* context) |
| 44 : thread_id_(SerialConnection::kThreadId), | 44 : thread_id_(SerialConnection::kThreadId), |
| 45 profile_(Profile::FromBrowserContext(context)) { | 45 profile_(Profile::FromBrowserContext(context)) { |
| 46 ApiResourceManager<SerialConnection>* manager = | 46 ApiResourceManager<SerialConnection>* manager = |
| 47 ApiResourceManager<SerialConnection>::Get(profile_); | 47 ApiResourceManager<SerialConnection>::Get(profile_); |
| 48 DCHECK(manager) << "No serial connection manager."; | 48 DCHECK(manager) << "No serial connection manager."; |
| 49 connections_ = manager->data_; | 49 connections_ = manager->data_; |
| 50 } | 50 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 EventRouter* router = ExtensionSystem::Get(profile)->event_router(); | 152 EventRouter* router = ExtensionSystem::Get(profile)->event_router(); |
| 153 if (router) | 153 if (router) |
| 154 router->DispatchEventToExtension(extension_id, event.Pass()); | 154 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace api | 157 } // namespace api |
| 158 | 158 |
| 159 } // namespace extensions | 159 } // namespace extensions |
| OLD | NEW |