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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/stl_util.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "chrome/test/chromedriver/chrome/adb.h" | 17 #include "chrome/test/chromedriver/chrome/adb.h" |
17 #include "chrome/test/chromedriver/chrome/status.h" | 18 #include "chrome/test/chromedriver/chrome/status.h" |
18 | 19 |
19 // TODO(craigdh): Remove once Chromedriver no longer supports pre-m33 Chrome. | 20 // TODO(craigdh): Remove once Chromedriver no longer supports pre-m33 Chrome. |
20 const char kChromeCmdLineFileBeforeM33[] = "/data/local/chrome-command-line"; | 21 const char kChromeCmdLineFileBeforeM33[] = "/data/local/chrome-command-line"; |
21 const char kChromeCmdLineFile[] = "/data/local/tmp/chrome-command-line"; | 22 const char kChromeCmdLineFile[] = "/data/local/tmp/chrome-command-line"; |
22 | 23 |
23 Device::Device( | 24 Device::Device( |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return status; | 176 return status; |
176 } | 177 } |
177 | 178 |
178 Status DeviceManager::AcquireSpecificDevice( | 179 Status DeviceManager::AcquireSpecificDevice( |
179 const std::string& device_serial, scoped_ptr<Device>* device) { | 180 const std::string& device_serial, scoped_ptr<Device>* device) { |
180 std::vector<std::string> devices; | 181 std::vector<std::string> devices; |
181 Status status = adb_->GetDevices(&devices); | 182 Status status = adb_->GetDevices(&devices); |
182 if (status.IsError()) | 183 if (status.IsError()) |
183 return status; | 184 return status; |
184 | 185 |
185 if (std::find(devices.begin(), devices.end(), device_serial) == devices.end()) | 186 if (!ContainsValue(devices, device_serial)) |
186 return Status(kUnknownError, | 187 return Status(kUnknownError, |
187 "Device " + device_serial + " is not online"); | 188 "Device " + device_serial + " is not online"); |
188 | 189 |
189 base::AutoLock lock(devices_lock_); | 190 base::AutoLock lock(devices_lock_); |
190 if (IsDeviceLocked(device_serial)) { | 191 if (IsDeviceLocked(device_serial)) { |
191 status = Status(kUnknownError, | 192 status = Status(kUnknownError, |
192 "Device " + device_serial + " is already in use"); | 193 "Device " + device_serial + " is already in use"); |
193 } else { | 194 } else { |
194 device->reset(LockDevice(device_serial)); | 195 device->reset(LockDevice(device_serial)); |
195 status = Status(kOk); | 196 status = Status(kOk); |
196 } | 197 } |
197 return status; | 198 return status; |
198 } | 199 } |
199 | 200 |
200 void DeviceManager::ReleaseDevice(const std::string& device_serial) { | 201 void DeviceManager::ReleaseDevice(const std::string& device_serial) { |
201 base::AutoLock lock(devices_lock_); | 202 base::AutoLock lock(devices_lock_); |
202 active_devices_.remove(device_serial); | 203 active_devices_.remove(device_serial); |
203 } | 204 } |
204 | 205 |
205 Device* DeviceManager::LockDevice(const std::string& device_serial) { | 206 Device* DeviceManager::LockDevice(const std::string& device_serial) { |
206 active_devices_.push_back(device_serial); | 207 active_devices_.push_back(device_serial); |
207 return new Device(device_serial, adb_, | 208 return new Device(device_serial, adb_, |
208 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this), | 209 base::Bind(&DeviceManager::ReleaseDevice, base::Unretained(this), |
209 device_serial)); | 210 device_serial)); |
210 } | 211 } |
211 | 212 |
212 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) { | 213 bool DeviceManager::IsDeviceLocked(const std::string& device_serial) { |
213 return std::find(active_devices_.begin(), active_devices_.end(), | 214 return ContainsValue(active_devices_, device_serial); |
214 device_serial) != active_devices_.end(); | |
215 } | 215 } |
OLD | NEW |