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
3 // found in the LICENSE file.
5 #ifndef CHROME_TEST_CHROMEDRIVER_CHROME_DEVICE_MANAGER_H_
6 #define CHROME_TEST_CHROMEDRIVER_CHROME_DEVICE_MANAGER_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/synchronization/lock.h"
25 Status SetUp(const std::string& package,
26 const std::string& activity,
27 const std::string& process,
28 const std::string& args,
35 friend class DeviceManager;
37 Device(const std::string& device_serial,
39 base::Callback<void()> release_callback);
41 Status ForwardDevtoolsPort(const std::string& package,
42 const std::string& process,
44 std::string* device_socket);
46 const std::string serial_;
47 std::string active_package_;
49 base::Callback<void()> release_callback_;
51 DISALLOW_COPY_AND_ASSIGN(Device);
56 explicit DeviceManager(Adb* adb);
59 // Returns a device which will not be reassigned during its lifetime.
60 Status AcquireDevice(scoped_ptr<Device>* device);
62 // Returns a device with the same guarantees as AcquireDevice, but fails
63 // if the device with the given serial number is not avaliable.
64 Status AcquireSpecificDevice(const std::string& device_serial,
65 scoped_ptr<Device>* device);
68 void ReleaseDevice(const std::string& device_serial);
70 Device* LockDevice(const std::string& device_serial);
71 bool IsDeviceLocked(const std::string& device_serial);
73 base::Lock devices_lock_;
74 std::list<std::string> active_devices_;
77 DISALLOW_COPY_AND_ASSIGN(DeviceManager);
80 #endif // CHROME_TEST_CHROMEDRIVER_CHROME_DEVICE_MANAGER_H_