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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "remoting/base/auto_thread_task_runner.h" | 11 #include "remoting/base/auto_thread_task_runner.h" |
12 #include "remoting/host/it2me/it2me_host.h" | 12 #include "remoting/host/it2me/it2me_host.h" |
13 #include "remoting/host/native_messaging/native_messaging_channel.h" | 13 #include "remoting/host/native_messaging/native_messaging_channel.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 } // namespace base | 17 } // namespace base |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 | 20 |
21 // Implementation of the native messaging host process. | 21 // Implementation of the native messaging host process. |
22 class It2MeNativeMessagingHost : public NativeMessagingChannel::Delegate, | 22 class It2MeNativeMessagingHost : public It2MeHost::Observer { |
23 public It2MeHost::Observer { | |
24 public: | 23 public: |
25 typedef NativeMessagingChannel::SendMessageCallback SendMessageCallback; | 24 typedef NativeMessagingChannel::SendMessageCallback SendMessageCallback; |
26 | 25 |
27 It2MeNativeMessagingHost(scoped_refptr<AutoThreadTaskRunner> task_runner, | 26 It2MeNativeMessagingHost(scoped_refptr<AutoThreadTaskRunner> task_runner, |
28 scoped_ptr<It2MeHostFactory> factory); | 27 scoped_ptr<It2MeHostFactory> factory); |
29 virtual ~It2MeNativeMessagingHost(); | 28 virtual ~It2MeNativeMessagingHost(); |
30 | 29 |
31 // NativeMessagingChannel::Delegate interface. | 30 void Start( |
32 virtual void SetSendMessageCallback(const SendMessageCallback& send_message) | 31 base::PlatformFile input, |
Sergey Ulanov
2013/12/12 19:10:28
would it be better to pass the Channel object here
weitao
2013/12/12 23:33:48
Done.
| |
33 OVERRIDE; | 32 base::PlatformFile output, |
34 virtual void ProcessMessage(scoped_ptr<base::DictionaryValue> message) | 33 const base::Closure& quit_closure); |
35 OVERRIDE; | 34 |
35 void ShutDown(); | |
36 | 36 |
37 // It2MeHost::Observer implementation | 37 // It2MeHost::Observer implementation |
38 virtual void OnClientAuthenticated(const std::string& client_username) | 38 virtual void OnClientAuthenticated(const std::string& client_username) |
39 OVERRIDE; | 39 OVERRIDE; |
40 virtual void OnStoreAccessCode(const std::string& access_code, | 40 virtual void OnStoreAccessCode(const std::string& access_code, |
41 base::TimeDelta access_code_lifetime) OVERRIDE; | 41 base::TimeDelta access_code_lifetime) OVERRIDE; |
42 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) OVERRIDE; | 42 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) OVERRIDE; |
43 virtual void OnStateChanged(It2MeHostState state) OVERRIDE; | 43 virtual void OnStateChanged(It2MeHostState state) OVERRIDE; |
44 | 44 |
45 static void ShutDownHost(NativeMessagingChannel::Delegate* delegate) { | |
46 It2MeNativeMessagingHost* host = | |
47 static_cast<It2MeNativeMessagingHost*>(delegate); | |
48 host->ShutDown(); | |
49 } | |
50 | |
51 static std::string HostStateToString(It2MeHostState host_state); | 45 static std::string HostStateToString(It2MeHostState host_state); |
52 | 46 |
53 private: | 47 private: |
48 void ProcessMessage(scoped_ptr<base::DictionaryValue> message); | |
49 | |
54 // These "Process.." methods handle specific request types. The |response| | 50 // These "Process.." methods handle specific request types. The |response| |
55 // dictionary is pre-filled by ProcessMessage() with the parts of the | 51 // dictionary is pre-filled by ProcessMessage() with the parts of the |
56 // response already known ("id" and "type" fields). | 52 // response already known ("id" and "type" fields). |
57 void ProcessHello(const base::DictionaryValue& message, | 53 void ProcessHello(const base::DictionaryValue& message, |
58 scoped_ptr<base::DictionaryValue> response); | 54 scoped_ptr<base::DictionaryValue> response); |
59 void ProcessConnect(const base::DictionaryValue& message, | 55 void ProcessConnect(const base::DictionaryValue& message, |
60 scoped_ptr<base::DictionaryValue> response); | 56 scoped_ptr<base::DictionaryValue> response); |
61 void ProcessDisconnect(const base::DictionaryValue& message, | 57 void ProcessDisconnect(const base::DictionaryValue& message, |
62 scoped_ptr<base::DictionaryValue> response); | 58 scoped_ptr<base::DictionaryValue> response); |
63 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response, | 59 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response, |
64 const std::string& description); | 60 const std::string& description); |
65 | 61 |
66 scoped_refptr<AutoThreadTaskRunner> task_runner(); | 62 scoped_refptr<AutoThreadTaskRunner> task_runner(); |
67 | 63 |
68 void ShutDown(); | 64 base::Closure quit_closure_; |
69 | 65 scoped_ptr<NativeMessagingChannel> channel_; |
70 scoped_ptr<It2MeHostFactory> factory_; | 66 scoped_ptr<It2MeHostFactory> factory_; |
71 scoped_ptr<ChromotingHostContext> host_context_; | 67 scoped_ptr<ChromotingHostContext> host_context_; |
72 scoped_refptr<It2MeHost> it2me_host_; | 68 scoped_refptr<It2MeHost> it2me_host_; |
73 SendMessageCallback send_message_; | |
74 | 69 |
75 // Cached, read-only copies of |it2me_host_| session state. | 70 // Cached, read-only copies of |it2me_host_| session state. |
76 It2MeHostState state_; | 71 It2MeHostState state_; |
77 std::string access_code_; | 72 std::string access_code_; |
78 base::TimeDelta access_code_lifetime_; | 73 base::TimeDelta access_code_lifetime_; |
79 std::string client_username_; | 74 std::string client_username_; |
80 | 75 |
81 // IT2Me Talk server configuration used by |it2me_host_| to connect. | 76 // IT2Me Talk server configuration used by |it2me_host_| to connect. |
82 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; | 77 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; |
83 | 78 |
84 // Chromoting Bot JID used by |it2me_host_| to register the host. | 79 // Chromoting Bot JID used by |it2me_host_| to register the host. |
85 std::string directory_bot_jid_; | 80 std::string directory_bot_jid_; |
86 | 81 |
87 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; | 82 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; |
88 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; | 83 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; |
89 | 84 |
90 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); | 85 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); |
91 }; | 86 }; |
92 | 87 |
93 } // namespace remoting | 88 } // namespace remoting |
94 | 89 |
95 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ | 90 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ |
OLD | NEW |