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