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

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

Issue 591463003: Remote Assistance on Chrome OS Part III - NativeMessageHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_messaging
Patch Set: 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_messaging_channel.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 } // namespace base 18 } // namespace base
18 19
19 namespace remoting { 20 namespace remoting {
20 21
21 // Implementation of the native messaging host process. 22 // Implementation of the native messaging host process.
22 class It2MeNativeMessagingHost 23 class It2MeNativeMessagingHost : public It2MeHost::Observer,
23 : public It2MeHost::Observer, 24 public extensions::NativeMessageHost {
24 public extensions::NativeMessagingChannel::EventHandler {
25 public: 25 public:
26 It2MeNativeMessagingHost( 26 It2MeNativeMessagingHost(scoped_refptr<AutoThreadTaskRunner> task_runner,
27 scoped_refptr<AutoThreadTaskRunner> task_runner, 27 scoped_ptr<It2MeHostFactory> factory);
28 scoped_ptr<extensions::NativeMessagingChannel> channel,
29 scoped_ptr<It2MeHostFactory> factory);
30 virtual ~It2MeNativeMessagingHost(); 28 virtual ~It2MeNativeMessagingHost();
31 29
32 void Start(const base::Closure& quit_closure); 30 // extensions::NativeMessageHost implementation.
33 31 // Called when a message is received from the client.
Sergey Ulanov 2014/09/27 00:24:10 This comment wouldn't be necessary if you rename S
kelvinp 2014/09/29 22:59:40 Done.
34 // extensions::NativeMessagingChannel::EventHandler implementation. 32 virtual void Send(const std::string& json) OVERRIDE;
35 virtual void OnMessage(scoped_ptr<base::Value> message) OVERRIDE; 33 virtual void set_client(base::WeakPtr<Client> client) OVERRIDE;
36 virtual void OnDisconnect() OVERRIDE;
37 34
38 // It2MeHost::Observer implementation. 35 // It2MeHost::Observer implementation.
39 virtual void OnClientAuthenticated(const std::string& client_username) 36 virtual void OnClientAuthenticated(const std::string& client_username)
40 OVERRIDE; 37 OVERRIDE;
41 virtual void OnStoreAccessCode(const std::string& access_code, 38 virtual void OnStoreAccessCode(const std::string& access_code,
42 base::TimeDelta access_code_lifetime) OVERRIDE; 39 base::TimeDelta access_code_lifetime) OVERRIDE;
43 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) OVERRIDE; 40 virtual void OnNatPolicyChanged(bool nat_traversal_enabled) OVERRIDE;
44 virtual void OnStateChanged(It2MeHostState state) OVERRIDE; 41 virtual void OnStateChanged(It2MeHostState state) OVERRIDE;
45 42
46 static std::string HostStateToString(It2MeHostState host_state); 43 static std::string HostStateToString(It2MeHostState host_state);
47 44
48 private: 45 private:
49 // These "Process.." methods handle specific request types. The |response| 46 // These "Process.." methods handle specific request types. The |response|
50 // dictionary is pre-filled by ProcessMessage() with the parts of the 47 // dictionary is pre-filled by ProcessMessage() with the parts of the
51 // response already known ("id" and "type" fields). 48 // response already known ("id" and "type" fields).
49 void OnMessageFromClient(scoped_ptr<base::Value> message);
52 void ProcessHello(const base::DictionaryValue& message, 50 void ProcessHello(const base::DictionaryValue& message,
53 scoped_ptr<base::DictionaryValue> response) const; 51 scoped_ptr<base::DictionaryValue> response) const;
54 void ProcessConnect(const base::DictionaryValue& message, 52 void ProcessConnect(const base::DictionaryValue& message,
55 scoped_ptr<base::DictionaryValue> response); 53 scoped_ptr<base::DictionaryValue> response);
56 void ProcessDisconnect(const base::DictionaryValue& message, 54 void ProcessDisconnect(const base::DictionaryValue& message,
57 scoped_ptr<base::DictionaryValue> response); 55 scoped_ptr<base::DictionaryValue> response);
58 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response, 56 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response,
59 const std::string& description) const; 57 const std::string& description) const;
60 58 void SendMessageToClient(scoped_ptr<base::DictionaryValue> message) const;
61 base::Closure quit_closure_;
62 59
63 scoped_refptr<AutoThreadTaskRunner> task_runner() const; 60 scoped_refptr<AutoThreadTaskRunner> task_runner() const;
64 61
65 scoped_ptr<extensions::NativeMessagingChannel> channel_; 62 base::WeakPtr<Client> client_;
66 scoped_ptr<It2MeHostFactory> factory_; 63 scoped_ptr<It2MeHostFactory> factory_;
67 scoped_ptr<ChromotingHostContext> host_context_; 64 scoped_ptr<ChromotingHostContext> host_context_;
68 scoped_refptr<It2MeHost> it2me_host_; 65 scoped_refptr<It2MeHost> it2me_host_;
69 66
70 // Cached, read-only copies of |it2me_host_| session state. 67 // Cached, read-only copies of |it2me_host_| session state.
71 It2MeHostState state_; 68 It2MeHostState state_;
72 std::string access_code_; 69 std::string access_code_;
73 base::TimeDelta access_code_lifetime_; 70 base::TimeDelta access_code_lifetime_;
74 std::string client_username_; 71 std::string client_username_;
75 72
76 // IT2Me Talk server configuration used by |it2me_host_| to connect. 73 // IT2Me Talk server configuration used by |it2me_host_| to connect.
77 XmppSignalStrategy::XmppServerConfig xmpp_server_config_; 74 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
78 75
79 // Chromoting Bot JID used by |it2me_host_| to register the host. 76 // Chromoting Bot JID used by |it2me_host_| to register the host.
80 std::string directory_bot_jid_; 77 std::string directory_bot_jid_;
81 78
82 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_; 79 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_;
83 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_; 80 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_;
84 81
85 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost); 82 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost);
86 }; 83 };
87 84
88 } // namespace remoting 85 } // namespace remoting
89 86
90 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_ 87 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_
91 88
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698