| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" | 16 #include "content/browser/devtools/protocol/tethering.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 class ServerSocket; | 19 class ServerSocket; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 namespace devtools { | 23 namespace protocol { |
| 23 namespace tethering { | |
| 24 | 24 |
| 25 // This class implements reversed tethering handler. | 25 // This class implements reversed tethering handler. |
| 26 class TetheringHandler { | 26 class TetheringHandler : public Tethering::Backend { |
| 27 public: | 27 public: |
| 28 using Response = DevToolsProtocolClient::Response; | |
| 29 using CreateServerSocketCallback = | 28 using CreateServerSocketCallback = |
| 30 base::Callback<std::unique_ptr<net::ServerSocket>(std::string*)>; | 29 base::Callback<std::unique_ptr<net::ServerSocket>(std::string*)>; |
| 31 | 30 |
| 32 TetheringHandler(const CreateServerSocketCallback& socket_callback, | 31 TetheringHandler(const CreateServerSocketCallback& socket_callback, |
| 33 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 32 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 34 ~TetheringHandler(); | 33 ~TetheringHandler() override; |
| 35 | 34 |
| 36 void SetClient(std::unique_ptr<Client> client); | 35 void Wire(UberDispatcher*); |
| 36 Response Disable() override; |
| 37 | 37 |
| 38 Response Bind(DevToolsCommandId command_id, int port); | 38 void Bind(int port, std::unique_ptr<BindCallback> callback) override; |
| 39 Response Unbind(DevToolsCommandId command_id, int port); | 39 void Unbind(int port, std::unique_ptr<UnbindCallback> callback) override; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 class TetheringImpl; | 42 class TetheringImpl; |
| 43 | 43 |
| 44 void Accepted(uint16_t port, const std::string& name); | 44 void Accepted(uint16_t port, const std::string& name); |
| 45 bool Activate(); | 45 bool Activate(); |
| 46 | 46 |
| 47 void SendBindSuccess(DevToolsCommandId command_id); | 47 std::unique_ptr<Tethering::Frontend> frontend_; |
| 48 void SendUnbindSuccess(DevToolsCommandId command_id); | |
| 49 void SendInternalError(DevToolsCommandId command_id, | |
| 50 const std::string& message); | |
| 51 | |
| 52 std::unique_ptr<Client> client_; | |
| 53 CreateServerSocketCallback socket_callback_; | 48 CreateServerSocketCallback socket_callback_; |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 49 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 55 bool is_active_; | 50 bool is_active_; |
| 56 base::WeakPtrFactory<TetheringHandler> weak_factory_; | 51 base::WeakPtrFactory<TetheringHandler> weak_factory_; |
| 57 | 52 |
| 58 static TetheringImpl* impl_; | 53 static TetheringImpl* impl_; |
| 59 | 54 |
| 60 DISALLOW_COPY_AND_ASSIGN(TetheringHandler); | 55 DISALLOW_COPY_AND_ASSIGN(TetheringHandler); |
| 61 }; | 56 }; |
| 62 | 57 |
| 63 } // namespace tethering | 58 } // namespace protocol |
| 64 } // namespace devtools | |
| 65 } // namespace content | 59 } // namespace content |
| 66 | 60 |
| 67 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ | 61 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TETHERING_HANDLER_H_ |
| OLD | NEW |