Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1266)

Unified Diff: chrome/browser/devtools/device/devtools_android_bridge.h

Issue 287643002: DevTools: Partially redesigned DevToolsAndroidBridge and AndroidDeviceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Encapsulated DeviceHandle::android_bridge_ Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/devtools/device/devtools_android_bridge.h
diff --git a/chrome/browser/devtools/device/devtools_android_bridge.h b/chrome/browser/devtools/device/devtools_android_bridge.h
index 6a0f781e8138db2e0c4df7204a4de1a33537ee0f..bb2435fdcbeace95aa61849ac5c4124bfd578c70 100644
--- a/chrome/browser/devtools/device/devtools_android_bridge.h
+++ b/chrome/browser/devtools/device/devtools_android_bridge.h
@@ -107,15 +107,44 @@ class DevToolsAndroidBridge
};
typedef base::Callback<void(RemotePage*)> RemotePageCallback;
+ typedef base::Callback<void(int, const std::string&)> JsonRequestCallback;
+
+ class DeviceHandle : public base::RefCounted<DeviceHandle> {
+ public:
+ DeviceHandle(scoped_refptr<DevToolsAndroidBridge> android_bridge,
+ const std::string& serial);
+
+ std::string serial() const { return serial_; }
+
+ void SendJsonRequest(const std::string& socket,
+ const std::string& request,
+ const JsonRequestCallback& callback);
+
+ void OpenSocket(const std::string& socket_name,
+ const AndroidDeviceManager::SocketCallback& callback);
+
+ scoped_refptr<AndroidWebSocket> CreateWebSocket(
+ const std::string& socket,
+ const std::string& url,
+ DevToolsAndroidBridge::AndroidWebSocket::Delegate* delegate);
+
+ private:
+ friend class base::RefCounted<DeviceHandle>;
+ virtual ~DeviceHandle();
+
+ scoped_refptr<DevToolsAndroidBridge> android_bridge_;
+ const std::string serial_;
+ };
+
+ typedef std::map<std::string, scoped_refptr<DeviceHandle> > DeviceHandleMap;
class RemoteBrowser : public base::RefCounted<RemoteBrowser> {
public:
RemoteBrowser(
- scoped_refptr<DevToolsAndroidBridge> android_bridge,
- const std::string& serial,
+ scoped_refptr<DeviceHandle> device_handle,
const AndroidDeviceManager::BrowserInfo& browser_info);
- std::string serial() { return serial_; }
+ std::string serial() { return device_handle_->serial(); }
std::string socket() { return socket_; }
std::string display_name() { return display_name_; }
@@ -133,7 +162,6 @@ class DevToolsAndroidBridge
std::vector<RemotePage*> CreatePages();
void SetPageDescriptors(const base::ListValue&);
- typedef base::Callback<void(int, const std::string&)> JsonRequestCallback;
void SendJsonRequest(const std::string& request,
const JsonRequestCallback& callback);
void SendProtocolCommand(const std::string& debug_url,
@@ -171,8 +199,7 @@ class DevToolsAndroidBridge
int result,
const std::string& response);
- scoped_refptr<DevToolsAndroidBridge> android_bridge_;
- const std::string serial_;
+ scoped_refptr<DeviceHandle> device_handle_;
const std::string socket_;
std::string display_name_;
const AndroidDeviceManager::BrowserInfo::Type type_;
@@ -186,12 +213,11 @@ class DevToolsAndroidBridge
class RemoteDevice : public base::RefCounted<RemoteDevice> {
public:
- RemoteDevice(scoped_refptr<DevToolsAndroidBridge> android_bridge,
- const std::string& serial,
+ RemoteDevice(scoped_refptr<DeviceHandle> device_handle,
const AndroidDeviceManager::DeviceInfo& device_info,
bool connected);
- std::string serial() { return serial_; }
+ std::string serial() { return device_handle_->serial(); }
std::string model() { return model_; }
bool is_connected() { return connected_; }
RemoteBrowsers& browsers() { return browsers_; }
@@ -204,8 +230,7 @@ class DevToolsAndroidBridge
friend class base::RefCounted<RemoteDevice>;
virtual ~RemoteDevice();
- scoped_refptr<DevToolsAndroidBridge> android_bridge_;
- std::string serial_;
+ scoped_refptr<DeviceHandle> device_handle_;
std::string model_;
bool connected_;
RemoteBrowsers browsers_;
@@ -244,6 +269,9 @@ class DevToolsAndroidBridge
static bool HasDevToolsWindow(const std::string& agent_id);
+ void IsConnectedForTest(const std::string& serial,
+ const base::Callback<void(bool)>& callback);
+
private:
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::UI>;
@@ -276,7 +304,8 @@ class DevToolsAndroidBridge
void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager);
void RequestDeviceList();
- void ReceivedDeviceList(RemoteDevices* devices);
+ void ReceivedDeviceList(RemoteDevices* devices,
+ DeviceHandleMap* device_handles);
void RequestDeviceCount();
void ReceivedDeviceCount(int count);
@@ -289,6 +318,7 @@ class DevToolsAndroidBridge
typedef std::vector<DeviceListListener*> DeviceListListeners;
DeviceListListeners device_list_listeners_;
+ DeviceHandleMap device_handles_;
typedef std::vector<DeviceCountListener*> DeviceCountListeners;
DeviceCountListeners device_count_listeners_;

Powered by Google App Engine
This is Rietveld 408576698