#ifndef CHROME_TEST_CHROMEDRIVER_CHROME_DEVICE_MANAGER_H_
#define CHROME_TEST_CHROMEDRIVER_CHROME_DEVICE_MANAGER_H_
#include <list>
#include <string>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
class Adb;
class Status;
class DeviceManager;
class Device {
public:
~Device();
Status SetUp(const std::string& package,
const std::string& activity,
const std::string& process,
const std::string& args,
bool use_running_app,
int port);
Status TearDown();
private:
friend class DeviceManager;
Device(const std::string& device_serial,
Adb* adb,
base::Callback<void()> release_callback);
Status ForwardDevtoolsPort(const std::string& package,
const std::string& process,
std::string& device_socket,
int port);
const std::string serial_;
std::string active_package_;
Adb* adb_;
base::Callback<void()> release_callback_;
DISALLOW_COPY_AND_ASSIGN(Device);
};
class DeviceManager {
public:
explicit DeviceManager(Adb* adb);
~DeviceManager();
Status AcquireDevice(scoped_ptr<Device>* device);
Status AcquireSpecificDevice(const std::string& device_serial,
scoped_ptr<Device>* device);
private:
void ReleaseDevice(const std::string& device_serial);
Device* LockDevice(const std::string& device_serial);
bool IsDeviceLocked(const std::string& device_serial);
base::Lock devices_lock_;
std::list<std::string> active_devices_;
Adb* adb_;
DISALLOW_COPY_AND_ASSIGN(DeviceManager);
};
#endif