| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 5 #ifndef REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
| 6 #define REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 6 #define REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "extensions/browser/api/messaging/native_message_host.h" | 14 #include "extensions/browser/api/messaging/native_message_host.h" |
| 14 #include "remoting/base/auto_thread_task_runner.h" | 15 #include "remoting/base/auto_thread_task_runner.h" |
| 15 #include "remoting/host/chromoting_host_context.h" | 16 #include "remoting/host/chromoting_host_context.h" |
| 16 #include "remoting/host/it2me/it2me_host.h" | 17 #include "remoting/host/it2me/it2me_host.h" |
| 17 | 18 |
| 18 #if !defined(OS_CHROMEOS) | 19 #if !defined(OS_CHROMEOS) |
| 19 #include "remoting/host/native_messaging/log_message_handler.h" | 20 #include "remoting/host/native_messaging/log_message_handler.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class DictionaryValue; | 24 class DictionaryValue; |
| 24 class Value; | 25 class Value; |
| 25 } // namespace base | 26 } // namespace base |
| 26 | 27 |
| 27 namespace remoting { | 28 namespace remoting { |
| 28 | 29 |
| 29 // Implementation of the native messaging host process. | 30 // Implementation of the native messaging host process. |
| 30 class It2MeNativeMessagingHost : public It2MeHost::Observer, | 31 class It2MeNativeMessagingHost : public It2MeHost::Observer, |
| 31 public extensions::NativeMessageHost { | 32 public extensions::NativeMessageHost { |
| 32 public: | 33 public: |
| 33 It2MeNativeMessagingHost( | 34 It2MeNativeMessagingHost(std::unique_ptr<ChromotingHostContext> host_context, |
| 34 scoped_ptr<ChromotingHostContext> host_context, | 35 std::unique_ptr<It2MeHostFactory> host_factory); |
| 35 scoped_ptr<It2MeHostFactory> host_factory); | |
| 36 ~It2MeNativeMessagingHost() override; | 36 ~It2MeNativeMessagingHost() override; |
| 37 | 37 |
| 38 // extensions::NativeMessageHost implementation. | 38 // extensions::NativeMessageHost implementation. |
| 39 void OnMessage(const std::string& message) override; | 39 void OnMessage(const std::string& message) override; |
| 40 void Start(Client* client) override; | 40 void Start(Client* client) override; |
| 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner() | 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner() |
| 42 const override; | 42 const override; |
| 43 | 43 |
| 44 // It2MeHost::Observer implementation. | 44 // It2MeHost::Observer implementation. |
| 45 void OnClientAuthenticated(const std::string& client_username) | 45 void OnClientAuthenticated(const std::string& client_username) |
| 46 override; | 46 override; |
| 47 void OnStoreAccessCode(const std::string& access_code, | 47 void OnStoreAccessCode(const std::string& access_code, |
| 48 base::TimeDelta access_code_lifetime) override; | 48 base::TimeDelta access_code_lifetime) override; |
| 49 void OnNatPolicyChanged(bool nat_traversal_enabled) override; | 49 void OnNatPolicyChanged(bool nat_traversal_enabled) override; |
| 50 void OnStateChanged(It2MeHostState state, | 50 void OnStateChanged(It2MeHostState state, |
| 51 const std::string& error_message) override; | 51 const std::string& error_message) override; |
| 52 | 52 |
| 53 static std::string HostStateToString(It2MeHostState host_state); | 53 static std::string HostStateToString(It2MeHostState host_state); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 // These "Process.." methods handle specific request types. The |response| | 56 // These "Process.." methods handle specific request types. The |response| |
| 57 // dictionary is pre-filled by ProcessMessage() with the parts of the | 57 // dictionary is pre-filled by ProcessMessage() with the parts of the |
| 58 // response already known ("id" and "type" fields). | 58 // response already known ("id" and "type" fields). |
| 59 void ProcessHello(const base::DictionaryValue& message, | 59 void ProcessHello(const base::DictionaryValue& message, |
| 60 scoped_ptr<base::DictionaryValue> response) const; | 60 std::unique_ptr<base::DictionaryValue> response) const; |
| 61 void ProcessConnect(const base::DictionaryValue& message, | 61 void ProcessConnect(const base::DictionaryValue& message, |
| 62 scoped_ptr<base::DictionaryValue> response); | 62 std::unique_ptr<base::DictionaryValue> response); |
| 63 void ProcessDisconnect(const base::DictionaryValue& message, | 63 void ProcessDisconnect(const base::DictionaryValue& message, |
| 64 scoped_ptr<base::DictionaryValue> response); | 64 std::unique_ptr<base::DictionaryValue> response); |
| 65 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response, | 65 void SendErrorAndExit(std::unique_ptr<base::DictionaryValue> response, |
| 66 const std::string& description) const; | 66 const std::string& description) const; |
| 67 void SendMessageToClient(scoped_ptr<base::Value> message) const; | 67 void SendMessageToClient(std::unique_ptr<base::Value> message) const; |
| 68 | 68 |
| 69 Client* client_; | 69 Client* client_; |
| 70 scoped_ptr<ChromotingHostContext> host_context_; | 70 std::unique_ptr<ChromotingHostContext> host_context_; |
| 71 scoped_ptr<It2MeHostFactory> factory_; | 71 std::unique_ptr<It2MeHostFactory> factory_; |
| 72 scoped_refptr<It2MeHost> it2me_host_; | 72 scoped_refptr<It2MeHost> it2me_host_; |
| 73 | 73 |
| 74 #if !defined(OS_CHROMEOS) | 74 #if !defined(OS_CHROMEOS) |
| 75 // Don't install a log message handler on ChromeOS because we run in the | 75 // Don't install a log message handler on ChromeOS because we run in the |
| 76 // browser process and don't want to intercept all its log messages. | 76 // browser process and don't want to intercept all its log messages. |
| 77 scoped_ptr<LogMessageHandler> log_message_handler_; | 77 std::unique_ptr<LogMessageHandler> log_message_handler_; |
| 78 #endif | 78 #endif |
| 79 | 79 |
| 80 // Cached, read-only copies of |it2me_host_| session state. | 80 // Cached, read-only copies of |it2me_host_| session state. |
| 81 It2MeHostState state_; | 81 It2MeHostState state_; |
| 82 std::string access_code_; | 82 std::string access_code_; |
| 83 base::TimeDelta access_code_lifetime_; | 83 base::TimeDelta access_code_lifetime_; |
| 84 std::string client_username_; | 84 std::string client_username_; |
| 85 | 85 |
| 86 // IT2Me Talk server configuration used by |it2me_host_| to connect. | 86 // IT2Me Talk server configuration used by |it2me_host_| to connect. |
| 87 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 87 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
| 88 | 88 |
| 89 // Chromoting Bot JID used by |it2me_host_| to register the host. | 89 // Chromoting Bot JID used by |it2me_host_| to register the host. |
| 90 std::string directory_bot_jid_; | 90 std::string directory_bot_jid_; |
| 91 | 91 |
| 92 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; | 92 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; |
| 93 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; | 93 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); | 95 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 } // namespace remoting | 98 } // namespace remoting |
| 99 | 99 |
| 100 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 100 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |