| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.size() > 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(extensions::events::UNKNOWN, |
| 103 serial::OnReceive::kEventName, args.Pass())); |
| 103 PostEvent(params, event.Pass()); | 104 PostEvent(params, event.Pass()); |
| 104 } | 105 } |
| 105 | 106 |
| 106 if (error != serial::RECEIVE_ERROR_NONE) { | 107 if (error != serial::RECEIVE_ERROR_NONE) { |
| 107 serial::ReceiveErrorInfo error_info; | 108 serial::ReceiveErrorInfo error_info; |
| 108 error_info.connection_id = params.connection_id; | 109 error_info.connection_id = params.connection_id; |
| 109 error_info.error = error; | 110 error_info.error = error; |
| 110 scoped_ptr<base::ListValue> args = | 111 scoped_ptr<base::ListValue> args = |
| 111 serial::OnReceiveError::Create(error_info); | 112 serial::OnReceiveError::Create(error_info); |
| 112 scoped_ptr<extensions::Event> event( | 113 scoped_ptr<extensions::Event> event( |
| 113 new extensions::Event(serial::OnReceiveError::kEventName, args.Pass())); | 114 new extensions::Event(extensions::events::UNKNOWN, |
| 115 serial::OnReceiveError::kEventName, args.Pass())); |
| 114 PostEvent(params, event.Pass()); | 116 PostEvent(params, event.Pass()); |
| 115 if (ShouldPauseOnReceiveError(error)) { | 117 if (ShouldPauseOnReceiveError(error)) { |
| 116 SerialConnection* connection = | 118 SerialConnection* connection = |
| 117 params.connections->Get(params.extension_id, params.connection_id); | 119 params.connections->Get(params.extension_id, params.connection_id); |
| 118 if (connection) | 120 if (connection) |
| 119 connection->set_paused(true); | 121 connection->set_paused(true); |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 | 124 |
| 123 // Queue up the next read operation. | 125 // Queue up the next read operation. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 150 return; | 152 return; |
| 151 | 153 |
| 152 EventRouter* router = EventRouter::Get(context); | 154 EventRouter* router = EventRouter::Get(context); |
| 153 if (router) | 155 if (router) |
| 154 router->DispatchEventToExtension(extension_id, event.Pass()); | 156 router->DispatchEventToExtension(extension_id, event.Pass()); |
| 155 } | 157 } |
| 156 | 158 |
| 157 } // namespace core_api | 159 } // namespace core_api |
| 158 | 160 |
| 159 } // namespace extensions | 161 } // namespace extensions |
| OLD | NEW |