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