summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools/protocol/tethering_handler.h
blob: 04bf6906d0fcc8cf4aaa28e1977f4bdf24ed28a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_

#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "content/browser/devtools/protocol/devtools_protocol_handler.h"

namespace net {
class ServerSocket;
}

namespace content {
namespace devtools {
namespace tethering {

// This class implements reversed tethering handler.
class TetheringHandler {
 public:
  using Response = DevToolsProtocolClient::Response;
  using CreateServerSocketCallback =
      base::Callback<scoped_ptr<net::ServerSocket>(std::string*)>;

  TetheringHandler(const CreateServerSocketCallback& socket_callback,
                   scoped_refptr<base::MessageLoopProxy> message_loop_proxy);
  ~TetheringHandler();

  void SetClient(scoped_ptr<Client> client);

  Response Bind(DevToolsCommandId command_id, int port);
  Response Unbind(DevToolsCommandId command_id, int port);

 private:
  class TetheringImpl;

  void Accepted(uint16 port, const std::string& name);
  bool Activate();

  void SendBindSuccess(DevToolsCommandId command_id);
  void SendUnbindSuccess(DevToolsCommandId command_id);
  void SendInternalError(DevToolsCommandId command_id,
                         const std::string& message);

  scoped_ptr<Client> client_;
  CreateServerSocketCallback socket_callback_;
  scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
  bool is_active_;
  base::WeakPtrFactory<TetheringHandler> weak_factory_;

  static TetheringImpl* impl_;

  DISALLOW_COPY_AND_ASSIGN(TetheringHandler);
};

}  // namespace tethering
}  // namespace devtools
}  // namespace content

#endif  // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_