Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / remoting / host / setup / me2me_native_messaging_host.h
blob1886f5112cd7722bccd20574ad7ee8a32d04d77a
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_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_
6 #define REMOTING_HOST_SETUP_ME2ME_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 "base/threading/thread_checker.h"
12 #include "base/timer/timer.h"
13 #include "extensions/browser/api/messaging/native_messaging_channel.h"
14 #include "remoting/host/setup/daemon_controller.h"
15 #include "remoting/host/setup/oauth_client.h"
17 namespace base {
18 class DictionaryValue;
19 class ListValue;
20 } // namespace base
22 namespace gaia {
23 class GaiaOAuthClient;
24 } // namespace gaia
26 namespace remoting {
28 const char kElevatingSwitchName[] = "elevate";
29 const char kInputSwitchName[] = "input";
30 const char kOutputSwitchName[] = "output";
32 namespace protocol {
33 class PairingRegistry;
34 } // namespace protocol
36 // Implementation of the me2me native messaging host.
37 class Me2MeNativeMessagingHost
38 : public extensions::NativeMessagingChannel::EventHandler {
39 public:
40 Me2MeNativeMessagingHost(
41 bool needs_elevation,
42 intptr_t parent_window_handle,
43 scoped_ptr<extensions::NativeMessagingChannel> channel,
44 scoped_refptr<DaemonController> daemon_controller,
45 scoped_refptr<protocol::PairingRegistry> pairing_registry,
46 scoped_ptr<OAuthClient> oauth_client);
47 ~Me2MeNativeMessagingHost() override;
49 void Start(const base::Closure& quit_closure);
51 // extensions::NativeMessagingChannel::EventHandler implementation
52 void OnMessage(scoped_ptr<base::Value> message) override;
53 void OnDisconnect() override;
55 private:
56 // These "Process.." methods handle specific request types. The |response|
57 // dictionary is pre-filled by ProcessMessage() with the parts of the
58 // response already known ("id" and "type" fields).
59 void ProcessHello(
60 scoped_ptr<base::DictionaryValue> message,
61 scoped_ptr<base::DictionaryValue> response);
62 void ProcessClearPairedClients(
63 scoped_ptr<base::DictionaryValue> message,
64 scoped_ptr<base::DictionaryValue> response);
65 void ProcessDeletePairedClient(
66 scoped_ptr<base::DictionaryValue> message,
67 scoped_ptr<base::DictionaryValue> response);
68 void ProcessGetHostName(
69 scoped_ptr<base::DictionaryValue> message,
70 scoped_ptr<base::DictionaryValue> response);
71 void ProcessGetPinHash(
72 scoped_ptr<base::DictionaryValue> message,
73 scoped_ptr<base::DictionaryValue> response);
74 void ProcessGenerateKeyPair(
75 scoped_ptr<base::DictionaryValue> message,
76 scoped_ptr<base::DictionaryValue> response);
77 void ProcessUpdateDaemonConfig(
78 scoped_ptr<base::DictionaryValue> message,
79 scoped_ptr<base::DictionaryValue> response);
80 void ProcessGetDaemonConfig(
81 scoped_ptr<base::DictionaryValue> message,
82 scoped_ptr<base::DictionaryValue> response);
83 void ProcessGetPairedClients(
84 scoped_ptr<base::DictionaryValue> message,
85 scoped_ptr<base::DictionaryValue> response);
86 void ProcessGetUsageStatsConsent(
87 scoped_ptr<base::DictionaryValue> message,
88 scoped_ptr<base::DictionaryValue> response);
89 void ProcessStartDaemon(
90 scoped_ptr<base::DictionaryValue> message,
91 scoped_ptr<base::DictionaryValue> response);
92 void ProcessStopDaemon(
93 scoped_ptr<base::DictionaryValue> message,
94 scoped_ptr<base::DictionaryValue> response);
95 void ProcessGetDaemonState(
96 scoped_ptr<base::DictionaryValue> message,
97 scoped_ptr<base::DictionaryValue> response);
98 void ProcessGetHostClientId(
99 scoped_ptr<base::DictionaryValue> message,
100 scoped_ptr<base::DictionaryValue> response);
101 void ProcessGetCredentialsFromAuthCode(
102 scoped_ptr<base::DictionaryValue> message,
103 scoped_ptr<base::DictionaryValue> response);
105 // These Send... methods get called on the DaemonController's internal thread,
106 // or on the calling thread if called by the PairingRegistry.
107 // These methods fill in the |response| dictionary from the other parameters,
108 // and pass it to SendResponse().
109 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response,
110 scoped_ptr<base::DictionaryValue> config);
111 void SendPairedClientsResponse(scoped_ptr<base::DictionaryValue> response,
112 scoped_ptr<base::ListValue> pairings);
113 void SendUsageStatsConsentResponse(
114 scoped_ptr<base::DictionaryValue> response,
115 const DaemonController::UsageStatsConsent& consent);
116 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response,
117 DaemonController::AsyncResult result);
118 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response,
119 bool result);
120 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response,
121 const std::string& user_email,
122 const std::string& refresh_token);
124 void OnError();
126 void Stop();
128 // Returns true if the request was successfully delegated to the elevated
129 // host and false otherwise.
130 bool DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message);
132 #if defined(OS_WIN)
133 class ElevatedChannelEventHandler
134 : public extensions::NativeMessagingChannel::EventHandler {
135 public:
136 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host);
138 virtual void OnMessage(scoped_ptr<base::Value> message) override;
139 virtual void OnDisconnect() override;
140 private:
141 Me2MeNativeMessagingHost* parent_;
144 // Create and connect to an elevated host process if necessary.
145 // |elevated_channel_| will contain the native messaging channel to the
146 // elevated host if the function succeeds.
147 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated();
149 // Disconnect and shut down the elevated host.
150 void DisconnectElevatedHost();
152 // Native messaging channel used to communicate with the elevated host.
153 scoped_ptr<extensions::NativeMessagingChannel> elevated_channel_;
155 // Native messaging event handler used to process responses from the elevated
156 // host.
157 scoped_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_;
159 // Timer to control the lifetime of the elevated host.
160 base::OneShotTimer<Me2MeNativeMessagingHost> elevated_host_timer_;
161 #endif // defined(OS_WIN)
163 bool needs_elevation_;
165 // Handle of the parent window.
166 intptr_t parent_window_handle_;
168 base::Closure quit_closure_;
170 // Native messaging channel used to communicate with the native message
171 // client.
172 scoped_ptr<extensions::NativeMessagingChannel> channel_;
173 scoped_refptr<DaemonController> daemon_controller_;
175 // Used to load and update the paired clients for this host.
176 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
178 // Used to exchange the service account authorization code for credentials.
179 scoped_ptr<OAuthClient> oauth_client_;
181 base::ThreadChecker thread_checker_;
183 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_;
184 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_;
186 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost);
189 } // namespace remoting
191 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_