| 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_api.h" | 5 #include "extensions/browser/api/serial/serial_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 const char kErrorGetControlSignalsFailed[] = "Failed to get control signals."; | 42 const char kErrorGetControlSignalsFailed[] = "Failed to get control signals."; |
| 43 | 43 |
| 44 template <class T> | 44 template <class T> |
| 45 void SetDefaultScopedPtrValue(scoped_ptr<T>& ptr, const T& value) { | 45 void SetDefaultScopedPtrValue(scoped_ptr<T>& ptr, const T& value) { |
| 46 if (!ptr.get()) | 46 if (!ptr.get()) |
| 47 ptr.reset(new T(value)); | 47 ptr.reset(new T(value)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 SerialAsyncApiFunction::SerialAsyncApiFunction() : manager_(NULL) { | 52 SerialAsyncApiFunction::SerialAsyncApiFunction() : manager_(nullptr) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 SerialAsyncApiFunction::~SerialAsyncApiFunction() { | 55 SerialAsyncApiFunction::~SerialAsyncApiFunction() { |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool SerialAsyncApiFunction::PrePrepare() { | 58 bool SerialAsyncApiFunction::PrePrepare() { |
| 59 manager_ = ApiResourceManager<SerialConnection>::Get(browser_context()); | 59 manager_ = ApiResourceManager<SerialConnection>::Get(browser_context()); |
| 60 DCHECK(manager_); | 60 DCHECK(manager_); |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 connection_ = CreateSerialConnection(params_->path, extension_->id()); | 132 connection_ = CreateSerialConnection(params_->path, extension_->id()); |
| 133 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); | 133 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void SerialConnectFunction::OnConnected(bool success) { | 136 void SerialConnectFunction::OnConnected(bool success) { |
| 137 DCHECK(connection_); | 137 DCHECK(connection_); |
| 138 | 138 |
| 139 if (success) { | 139 if (success) { |
| 140 if (!connection_->Configure(*params_->options.get())) { | 140 if (!connection_->Configure(*params_->options.get())) { |
| 141 delete connection_; | 141 delete connection_; |
| 142 connection_ = NULL; | 142 connection_ = nullptr; |
| 143 } | 143 } |
| 144 } else { | 144 } else { |
| 145 delete connection_; | 145 delete connection_; |
| 146 connection_ = NULL; | 146 connection_ = nullptr; |
| 147 } | 147 } |
| 148 | 148 |
| 149 BrowserThread::PostTask( | 149 BrowserThread::PostTask( |
| 150 BrowserThread::IO, | 150 BrowserThread::IO, |
| 151 FROM_HERE, | 151 FROM_HERE, |
| 152 base::Bind(&SerialConnectFunction::FinishConnect, this)); | 152 base::Bind(&SerialConnectFunction::FinishConnect, this)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void SerialConnectFunction::FinishConnect() { | 155 void SerialConnectFunction::FinishConnect() { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 if (device->has_vendor_id) | 443 if (device->has_vendor_id) |
| 444 info->vendor_id.reset(new int(static_cast<int>(device->vendor_id))); | 444 info->vendor_id.reset(new int(static_cast<int>(device->vendor_id))); |
| 445 if (device->has_product_id) | 445 if (device->has_product_id) |
| 446 info->product_id.reset(new int(static_cast<int>(device->product_id))); | 446 info->product_id.reset(new int(static_cast<int>(device->product_id))); |
| 447 if (device->display_name) | 447 if (device->display_name) |
| 448 info->display_name.reset(new std::string(device->display_name)); | 448 info->display_name.reset(new std::string(device->display_name)); |
| 449 return info; | 449 return info; |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace mojo | 452 } // namespace mojo |
| OLD | NEW |