Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Side by Side Diff: remoting/host/it2me/it2me_native_messaging_host.h

Issue 639233002: Remote assistance on Chrome OS Part IV - It2MeHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedbacks Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "extensions/browser/api/messaging/native_message_host.h" 11 #include "extensions/browser/api/messaging/native_message_host.h"
12 #include "remoting/base/auto_thread_task_runner.h" 12 #include "remoting/base/auto_thread_task_runner.h"
13 #include "remoting/host/it2me/it2me_host.h" 13 #include "remoting/host/it2me/it2me_host.h"
14 14
15 namespace base { 15 namespace base {
16 class DictionaryValue; 16 class DictionaryValue;
17 class Value; 17 class Value;
18 } // namespace base 18 } // namespace base
19 19
20 namespace policy {
21 class PolicyService;
22 } // namespace policy
23
20 namespace remoting { 24 namespace remoting {
21 25
22 // Implementation of the native messaging host process. 26 // Implementation of the native messaging host process.
23 class It2MeNativeMessagingHost : public It2MeHost::Observer, 27 class It2MeNativeMessagingHost : public It2MeHost::Observer,
24 public extensions::NativeMessageHost { 28 public extensions::NativeMessageHost {
25 public: 29 public:
26 It2MeNativeMessagingHost(scoped_refptr<AutoThreadTaskRunner> task_runner, 30 static scoped_ptr<NativeMessageHost> CreateForChromeOS(
27 scoped_ptr<It2MeHostFactory> factory); 31 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
32 policy::PolicyService* policy_service);
33
34 static scoped_ptr<NativeMessageHost> Create(
35 scoped_ptr<ChromotingHostContext> context,
36 scoped_ptr<It2MeHostFactory> factory);
37
28 virtual ~It2MeNativeMessagingHost(); 38 virtual ~It2MeNativeMessagingHost();
29 39
30 // extensions::NativeMessageHost implementation. 40 // extensions::NativeMessageHost implementation.
31 virtual void OnMessage(const std::string& message) override; 41 virtual void OnMessage(const std::string& message) override;
32 virtual void Start(Client* client) override; 42 virtual void Start(Client* client) override;
33 virtual scoped_refptr<base::SingleThreadTaskRunner> task_runner() 43 virtual scoped_refptr<base::SingleThreadTaskRunner> task_runner()
34 const override; 44 const override;
35 45
36 // It2MeHost::Observer implementation. 46 // It2MeHost::Observer implementation.
37 virtual void OnClientAuthenticated(const std::string& client_username) 47 virtual void OnClientAuthenticated(const std::string& client_username)
38 override; 48 override;
39 virtual void OnStoreAccessCode(const std::string& access_code, 49 virtual void OnStoreAccessCode(const std::string& access_code,
40 base::TimeDelta access_code_lifetime) override; 50 base::TimeDelta access_code_lifetime) override;
41 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) override; 51 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) override;
42 virtual void OnStateChanged(It2MeHostState state) override; 52 virtual void OnStateChanged(It2MeHostState state) override;
43 53
44 static std::string HostStateToString(It2MeHostState host_state); 54 static std::string HostStateToString(It2MeHostState host_state);
45 55
46 private: 56 private:
57 It2MeNativeMessagingHost(
58 scoped_ptr<ChromotingHostContext> context,
59 scoped_ptr<It2MeHostFactory> factory);
60
47 // These "Process.." methods handle specific request types. The |response| 61 // These "Process.." methods handle specific request types. The |response|
48 // dictionary is pre-filled by ProcessMessage() with the parts of the 62 // dictionary is pre-filled by ProcessMessage() with the parts of the
49 // response already known ("id" and "type" fields). 63 // response already known ("id" and "type" fields).
50 void ProcessHello(const base::DictionaryValue& message, 64 void ProcessHello(const base::DictionaryValue& message,
51 scoped_ptr<base::DictionaryValue> response) const; 65 scoped_ptr<base::DictionaryValue> response) const;
52 void ProcessConnect(const base::DictionaryValue& message, 66 void ProcessConnect(const base::DictionaryValue& message,
53 scoped_ptr<base::DictionaryValue> response); 67 scoped_ptr<base::DictionaryValue> response);
54 void ProcessDisconnect(const base::DictionaryValue& message, 68 void ProcessDisconnect(const base::DictionaryValue& message,
55 scoped_ptr<base::DictionaryValue> response); 69 scoped_ptr<base::DictionaryValue> response);
56 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response, 70 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response,
57 const std::string& description) const; 71 const std::string& description) const;
58 void SendMessageToClient(scoped_ptr<base::DictionaryValue> message) const; 72 void SendMessageToClient(scoped_ptr<base::DictionaryValue> message) const;
59 73
60 Client* client_; 74 Client* client_;
61 scoped_ptr<It2MeHostFactory> factory_; 75 scoped_ptr<It2MeHostFactory> factory_;
62 scoped_ptr<ChromotingHostContext> host_context_; 76 scoped_ptr<ChromotingHostContext> host_context_;
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
63 scoped_refptr<It2MeHost> it2me_host_; 78 scoped_refptr<It2MeHost> it2me_host_;
64 79
65 // Cached, read-only copies of |it2me_host_| session state. 80 // Cached, read-only copies of |it2me_host_| session state.
66 It2MeHostState state_; 81 It2MeHostState state_;
67 std::string access_code_; 82 std::string access_code_;
68 base::TimeDelta access_code_lifetime_; 83 base::TimeDelta access_code_lifetime_;
69 std::string client_username_; 84 std::string client_username_;
70 85
71 // IT2Me Talk server configuration used by |it2me_host_| to connect. 86 // IT2Me Talk server configuration used by |it2me_host_| to connect.
72 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 87 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
73 88
74 // Chromoting Bot JID used by |it2me_host_| to register the host. 89 // Chromoting Bot JID used by |it2me_host_| to register the host.
75 std::string directory_bot_jid_; 90 std::string directory_bot_jid_;
76 91
77 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; 92 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_;
78 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; 93 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_;
79 94
80 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); 95 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost);
81 }; 96 };
82 97
83 } // namespace remoting 98 } // namespace remoting
84 99
85 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ 100 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_
86 101
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698