Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 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 CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |
| 6 | #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |
| 7 | |
| 8 | #include <map> |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 9 | #include <set> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | #include <string> |
| 11 | |
| 12 | #include "base/basictypes.h" |
| 13 | #include "base/compiler_specific.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 14 | #include "base/memory/ref_counted.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
| 16 | #include "base/stl_util.h" |
| 17 | #include "content/browser/devtools/devtools_protocol.h" |
| 18 | |
| 19 | namespace base { |
| 20 | class DictionaryValue; |
| 21 | class MessageLoopProxy; |
| 22 | class Value; |
| 23 | } // namespace base |
| 24 | |
| 25 | namespace net { |
| 26 | class HttpServer; |
| 27 | } // namespace net |
| 28 | |
| 29 | namespace content { |
| 30 | |
| 31 | // This class handles the "Browser" target for remote debugging. |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 32 | class DevToolsBrowserTarget |
| 33 | : public base::RefCountedThreadSafe<DevToolsBrowserTarget> { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 34 | public: |
| 35 | DevToolsBrowserTarget(base::MessageLoopProxy* message_loop_proxy, |
| 36 | net::HttpServer* server, |
| 37 | int connection_id); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 38 | |
| 39 | int connection_id() const { return connection_id_; } |
| 40 | |
| 41 | // Takes ownership of |handler|. |
| 42 | void RegisterDomainHandler(const std::string& domain, |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 43 | DevToolsProtocol::Handler* handler, |
| 44 | bool handle_on_ui_thread); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 45 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 46 | void HandleMessage(const std::string& data); |
| 47 | |
| 48 | void Detach(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 49 | |
| 50 | private: |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 51 | friend class base::RefCountedThreadSafe<DevToolsBrowserTarget>; |
| 52 | ~DevToolsBrowserTarget(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 53 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 54 | void HandleCommandOnUIThread( |
| 55 | DevToolsProtocol::Handler*, |
| 56 | scoped_refptr<DevToolsProtocol::Command> command); |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 57 | |
| 58 | void DeleteHandlersOnUIThread( |
| 59 | std::vector<DevToolsProtocol::Handler*> handlers); |
| 60 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 61 | void Respond(const std::string& message); |
| 62 | void RespondFromUIThread(const std::string& message); |
| 63 | |
| 64 | base::MessageLoopProxy* message_loop_proxy_; |
| 65 | net::HttpServer* http_server_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 66 | const int connection_id_; |
| 67 | |
| 68 | typedef std::map<std::string, DevToolsProtocol::Handler*> DomainHandlerMap; |
| 69 | DomainHandlerMap handlers_; |
| 70 | STLValueDeleter<DomainHandlerMap> handlers_deleter_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 71 | std::set<std::string> handle_on_ui_thread_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 72 | base::WeakPtrFactory<DevToolsBrowserTarget> weak_factory_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget); |
| 75 | }; |
| 76 | |
| 77 | } // namespace content |
| 78 | |
| 79 | #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_ |