Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / it2me / it2me_native_messaging_host.h
blob02379baee3deb9c43aff3720044f17559c3a7529
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 namespace base {
17 class DictionaryValue;
18 class Value;
19 } // namespace base
21 namespace remoting {
23 // Implementation of the native messaging host process.
24 class It2MeNativeMessagingHost : public It2MeHost::Observer,
25 public extensions::NativeMessageHost {
26 public:
27 It2MeNativeMessagingHost(
28 scoped_ptr<ChromotingHostContext> host_context,
29 scoped_ptr<It2MeHostFactory> host_factory);
30 ~It2MeNativeMessagingHost() override;
32 // extensions::NativeMessageHost implementation.
33 void OnMessage(const std::string& message) override;
34 void Start(Client* client) override;
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner()
36 const override;
38 // It2MeHost::Observer implementation.
39 void OnClientAuthenticated(const std::string& client_username)
40 override;
41 void OnStoreAccessCode(const std::string& access_code,
42 base::TimeDelta access_code_lifetime) override;
43 void OnNatPolicyChanged(bool nat_traversal_enabled) override;
44 void OnStateChanged(It2MeHostState state,
45 const std::string& error_message) override;
47 static std::string HostStateToString(It2MeHostState host_state);
49 private:
50 // These "Process.." methods handle specific request types. The |response|
51 // dictionary is pre-filled by ProcessMessage() with the parts of the
52 // response already known ("id" and "type" fields).
53 void ProcessHello(const base::DictionaryValue& message,
54 scoped_ptr<base::DictionaryValue> response) const;
55 void ProcessConnect(const base::DictionaryValue& message,
56 scoped_ptr<base::DictionaryValue> response);
57 void ProcessDisconnect(const base::DictionaryValue& message,
58 scoped_ptr<base::DictionaryValue> response);
59 void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response,
60 const std::string& description) const;
61 void SendMessageToClient(scoped_ptr<base::DictionaryValue> message) const;
63 Client* client_;
64 scoped_ptr<ChromotingHostContext> host_context_;
65 scoped_ptr<It2MeHostFactory> factory_;
66 scoped_refptr<It2MeHost> it2me_host_;
68 // Cached, read-only copies of |it2me_host_| session state.
69 It2MeHostState state_;
70 std::string access_code_;
71 base::TimeDelta access_code_lifetime_;
72 std::string client_username_;
74 // IT2Me Talk server configuration used by |it2me_host_| to connect.
75 XmppSignalStrategy::XmppServerConfig xmpp_server_config_;
77 // Chromoting Bot JID used by |it2me_host_| to register the host.
78 std::string directory_bot_jid_;
80 base::WeakPtr<It2MeNativeMessagingHost> weak_ptr_;
81 base::WeakPtrFactory<It2MeNativeMessagingHost> weak_factory_;
83 DISALLOW_COPY_AND_ASSIGN(It2MeNativeMessagingHost);
86 } // namespace remoting
88 #endif // REMOTING_HOST_IT2ME_IT2ME_NATIVE_MESSAGING_HOST_H_