OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "net/url_request/url_request.h" |
| 13 |
| 14 namespace base { |
| 15 class Thread; |
| 16 } |
| 17 |
| 18 class DevToolsAdbBridge |
| 19 : public base::RefCountedThreadSafe<DevToolsAdbBridge>, |
| 20 public net::URLRequest::Delegate { |
| 21 public: |
| 22 typedef base::Callback<void(const std::string& error, |
| 23 const std::string& data)> Callback; |
| 24 |
| 25 static DevToolsAdbBridge* Start(Profile* profile); |
| 26 void Query(const std::string query, const Callback& callback); |
| 27 void Fetch(const std::string url, const Callback& callback); |
| 28 void Stop(); |
| 29 |
| 30 private: |
| 31 friend class base::RefCountedThreadSafe<DevToolsAdbBridge>; |
| 32 struct RequestInfo; |
| 33 |
| 34 explicit DevToolsAdbBridge(Profile* profile); |
| 35 virtual ~DevToolsAdbBridge(); |
| 36 |
| 37 void StartHandlerOnFileThread(); |
| 38 void StopHandlerOnFileThread(); |
| 39 |
| 40 void ResetHandlerAndReleaseOnUIThread(); |
| 41 void ResetHandlerOnUIThread(); |
| 42 |
| 43 void InitOnHandlerThread(); |
| 44 void QueryOnHandlerThread(const std::string query, const Callback& callback); |
| 45 void FetchOnHandlerThread(const std::string query, const Callback& callback); |
| 46 void QueryResponseOnHandlerThread(const Callback& callback, |
| 47 const std::string& error, |
| 48 const std::string& response); |
| 49 void TeardownOnHandlerThread(); |
| 50 |
| 51 void RespondOnUIThread(const Callback& callback, |
| 52 const std::string& error, |
| 53 const std::string& response); |
| 54 |
| 55 // net::URLRequest::Delegate implementation. |
| 56 virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; |
| 57 virtual void OnReadCompleted(net::URLRequest* request, |
| 58 int bytes_read) OVERRIDE; |
| 59 |
| 60 // The thread used by the devtools to run client socket. |
| 61 scoped_ptr<base::Thread> thread_; |
| 62 |
| 63 std::map<net::URLRequest*, RequestInfo> request_info_; |
| 64 Profile* profile_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(DevToolsAdbBridge); |
| 67 }; |
| 68 |
| 69 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_ADB_BRIDGE_H_ |
OLD | NEW |