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

Side by Side Diff: chrome/browser/devtools/devtools_adb_bridge.h

Issue 12586010: DevTools: extract ADB command classes, change objects' lifetimes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Win build fixed. Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
13 #include "net/socket/tcp_client_socket.h" 15 #include "net/socket/tcp_client_socket.h"
14 16
15 namespace base { 17 namespace base {
16 class Thread; 18 class Thread;
17 class DictionaryValue; 19 class DictionaryValue;
18 } 20 }
19 21
22 class MessageLoop;
23 class Profile;
24
20 class DevToolsAdbBridge { 25 class DevToolsAdbBridge {
21 public: 26 public:
22 typedef base::Callback<void(int result, 27 typedef base::Callback<void(int result,
23 const std::string& response)> Callback; 28 const std::string& response)> Callback;
24 29
25 class AgentHost : public base::RefCounted<AgentHost> { 30 class RemotePage : public base::RefCounted<RemotePage> {
26 public: 31 public:
27 AgentHost(const std::string& serial, 32 RemotePage(const std::string& serial,
28 const std::string& model, 33 const std::string& model,
29 const base::DictionaryValue& value); 34 const base::DictionaryValue& value);
30 35
31 std::string serial() { return serial_; } 36 std::string serial() { return serial_; }
32 std::string model() { return model_; } 37 std::string model() { return model_; }
33 std::string id() { return id_; } 38 std::string id() { return id_; }
39 std::string url() { return url_; }
34 std::string title() { return title_; } 40 std::string title() { return title_; }
35 std::string description() { return description_; } 41 std::string description() { return description_; }
36 std::string favicon_url() { return favicon_url_; } 42 std::string favicon_url() { return favicon_url_; }
37 std::string debug_url() { return debug_url_; } 43 std::string debug_url() { return debug_url_; }
44 std::string frontend_url() { return frontend_url_; }
38 45
39 private: 46 private:
40 friend class base::RefCounted<AgentHost>; 47 friend class base::RefCounted<RemotePage>;
41 48 virtual ~RemotePage();
42 virtual ~AgentHost();
43 std::string serial_; 49 std::string serial_;
44 std::string model_; 50 std::string model_;
45 std::string id_; 51 std::string id_;
52 std::string url_;
46 std::string title_; 53 std::string title_;
47 std::string description_; 54 std::string description_;
48 std::string favicon_url_; 55 std::string favicon_url_;
49 std::string debug_url_; 56 std::string debug_url_;
50 DISALLOW_COPY_AND_ASSIGN(AgentHost); 57 std::string frontend_url_;
58 DISALLOW_COPY_AND_ASSIGN(RemotePage);
51 }; 59 };
52 60
53 typedef std::vector<scoped_refptr<AgentHost> > AgentHosts; 61 typedef std::vector<scoped_refptr<RemotePage> > RemotePages;
54 typedef base::Callback<void(int, AgentHosts*)> HostsCallback; 62 typedef base::Callback<void(int, RemotePages*)> PagesCallback;
55 63
56 static DevToolsAdbBridge* Start(); 64 explicit DevToolsAdbBridge(Profile* profile);
65 ~DevToolsAdbBridge();
66
57 void Query(const std::string query, const Callback& callback); 67 void Query(const std::string query, const Callback& callback);
58 void Devices(); 68 void Pages(const PagesCallback& callback);
59 void Stop(); 69 void Attach(scoped_refptr<RemotePage> page);
60 70
61 private: 71 private:
62 friend class base::RefCountedThreadSafe<DevToolsAdbBridge>; 72 friend class AdbWebSocket;
63 73
74 class RefCountedAdbThread : public base::RefCounted<RefCountedAdbThread> {
75 public:
76 static scoped_refptr<RefCountedAdbThread> GetInstance();
77 RefCountedAdbThread();
78 MessageLoop* message_loop();
64 79
65 explicit DevToolsAdbBridge(); 80 private:
66 virtual ~DevToolsAdbBridge(); 81 friend class base::RefCounted<RefCountedAdbThread>;
82 static DevToolsAdbBridge::RefCountedAdbThread* instance_;
83 static void StopThread(base::Thread* thread);
67 84
68 void StopHandlerOnFileThread(); 85 virtual ~RefCountedAdbThread();
86 base::Thread* thread_;
87 };
69 88
70 void ResetHandlerAndReleaseOnUIThread(); 89 Profile* profile_;
71 void ResetHandlerOnUIThread(); 90 scoped_refptr<RefCountedAdbThread> adb_thread_;
72 91 base::WeakPtrFactory<DevToolsAdbBridge> weak_factory_;
73 void QueryOnHandlerThread(const std::string query, const Callback& callback); 92 bool has_message_loop_;
74 void QueryResponseOnHandlerThread(const Callback& callback,
75 int result,
76 const std::string& response);
77
78 void DevicesOnHandlerThread(const HostsCallback& callback);
79 void ReceivedDevices(const HostsCallback& callback,
80 int result,
81 const std::string& response);
82 void ProcessSerials(const HostsCallback& callback,
83 AgentHosts* hosts,
84 std::vector<std::string>* serials);
85 void ReceivedModel(const HostsCallback& callback,
86 AgentHosts* hosts,
87 std::vector<std::string>* serials,
88 int result,
89 const std::string& response);
90 void ReceivedPages(const HostsCallback& callback,
91 AgentHosts* hosts,
92 std::vector<std::string>* serials,
93 const std::string& model,
94 int result,
95 const std::string& response);
96
97 void RespondOnUIThread(const Callback& callback,
98 int result,
99 const std::string& response);
100
101 void PrintHosts(int result, AgentHosts* hosts);
102
103 // The thread used by the devtools to run client socket.
104 scoped_ptr<base::Thread> thread_;
105
106 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); 93 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge);
107 }; 94 };
108 95
109 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ 96 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_
OLDNEW
« no previous file with comments | « chrome/browser/devtools/adb_client_socket.cc ('k') | chrome/browser/devtools/devtools_adb_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698