OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/test/chromedriver/chrome/device_manager.h" | 5 #include "chrome/test/chromedriver/chrome/device_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return status; | 176 return status; |
177 } | 177 } |
178 | 178 |
179 Status DeviceManager::AcquireSpecificDevice(const std::string& device_serial, | 179 Status DeviceManager::AcquireSpecificDevice(const std::string& device_serial, |
180 std::unique_ptr<Device>* device) { | 180 std::unique_ptr<Device>* device) { |
181 std::vector<std::string> devices; | 181 std::vector<std::string> devices; |
182 Status status = adb_->GetDevices(&devices); | 182 Status status = adb_->GetDevices(&devices); |
183 if (status.IsError()) | 183 if (status.IsError()) |
184 return status; | 184 return status; |
185 | 185 |
186 if (!ContainsValue(devices, device_serial)) | 186 if (!base::ContainsValue(devices, device_serial)) |
187 return Status(kUnknownError, | 187 return Status(kUnknownError, |
188 "Device " + device_serial + " is not online"); | 188 "Device " + device_serial + " is not online"); |
189 | 189 |
190 base::AutoLock lock(devices_lock_); | 190 base::AutoLock lock(devices_lock_); |
191 if (IsDeviceLocked(device_serial)) { | 191 if (IsDeviceLocked(device_serial)) { |
192 status = Status(kUnknownError, | 192 status = Status(kUnknownError, |
193 "Device " + device_serial + " is already in use"); | 193 "Device " + device_serial + " is already in use"); |
194 } else { | 194 } else { |
195 device->reset(LockDevice(device_serial)); | 195 device->reset(LockDevice(device_serial)); |
196 status = Status(kOk); | 196 status = Status(kOk); |
197 } | 197 } |
198 return status; | 198 return status; |
199 } | 199 } |
200 | 200 |
201 void DeviceManager::ReleaseDevice(const std::string& device_serial) { | 201 void DeviceManager::ReleaseDevice(const std::string& device_serial) { |
202 base::AutoLock lock(devices_lock_); | 202 base::AutoLock lock(devices_lock_); |
203 active_devices_.remove(device_serial); | 203 active_devices_.remove(device_serial); |
204 } | 204 } |
205 | 205 |
206 Device* DeviceManager::LockDevice(const std::string& device_serial) { | 206 Device* DeviceManager::LockDevice(const std::string& device_serial) { |
207 active_devices_.push_back(device_serial); | 207 active_devices_.push_back(device_serial); |
208 return new Device(device_serial, adb_, | 208 return new Device(device_serial, adb_, |
209 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this), | 209 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this), |
210 device_serial)); | 210 device_serial)); |
211 } | 211 } |
212 | 212 |
213 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) { | 213 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) { |
214 return ContainsValue(active_devices_, device_serial); | 214 return base::ContainsValue(active_devices_, device_serial); |
215 } | 215 } |
OLD | NEW |