| 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 "extensions/browser/api/serial/serial_event_dispatcher.h" | 5 #include "extensions/browser/api/serial/serial_event_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "extensions/browser/api/serial/serial_connection.h" | 8 #include "extensions/browser/api/serial/serial_connection.h" |
| 9 #include "extensions/browser/event_router.h" | 9 #include "extensions/browser/event_router.h" |
| 10 #include "extensions/browser/extensions_browser_client.h" | 10 #include "extensions/browser/extensions_browser_client.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 DCHECK(params.extension_id == connection->owner_extension_id()); | 80 DCHECK(params.extension_id == connection->owner_extension_id()); |
| 81 | 81 |
| 82 if (connection->paused()) | 82 if (connection->paused()) |
| 83 return; | 83 return; |
| 84 | 84 |
| 85 connection->Receive(base::Bind(&ReceiveCallback, params)); | 85 connection->Receive(base::Bind(&ReceiveCallback, params)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // static | 88 // static |
| 89 void SerialEventDispatcher::ReceiveCallback(const ReceiveParams& params, | 89 void SerialEventDispatcher::ReceiveCallback(const ReceiveParams& params, |
| 90 const std::string& data, | 90 const std::vector<char>& data, |
| 91 serial::ReceiveError error) { | 91 serial::ReceiveError error) { |
| 92 DCHECK_CURRENTLY_ON(params.thread_id); | 92 DCHECK_CURRENTLY_ON(params.thread_id); |
| 93 | 93 |
| 94 // Note that an error (e.g. timeout) does not necessarily mean that no data | 94 // Note that an error (e.g. timeout) does not necessarily mean that no data |
| 95 // was read, so we may fire an onReceive regardless of any error code. | 95 // was read, so we may fire an onReceive regardless of any error code. |
| 96 if (data.length() > 0) { | 96 if (data.size() > 0) { |
| 97 serial::ReceiveInfo receive_info; | 97 serial::ReceiveInfo receive_info; |
| 98 receive_info.connection_id = params.connection_id; | 98 receive_info.connection_id = params.connection_id; |
| 99 receive_info.data = data; | 99 receive_info.data = data; |
| 100 scoped_ptr<base::ListValue> args = serial::OnReceive::Create(receive_info); | 100 scoped_ptr<base::ListValue> args = serial::OnReceive::Create(receive_info); |
| 101 scoped_ptr<extensions::Event> event( | 101 scoped_ptr<extensions::Event> event( |
| 102 new extensions::Event(serial::OnReceive::kEventName, args.Pass())); | 102 new extensions::Event(serial::OnReceive::kEventName, args.Pass())); |
| 103 PostEvent(params, event.Pass()); | 103 PostEvent(params, event.Pass()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (error != serial::RECEIVE_ERROR_NONE) { | 106 if (error != serial::RECEIVE_ERROR_NONE) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 EventRouter* router = EventRouter::Get(context); | 152 EventRouter* router = EventRouter::Get(context); |
| 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 core_api | 157 } // namespace core_api |
| 158 | 158 |
| 159 } // namespace extensions | 159 } // namespace extensions |
| OLD | NEW |