| OLD | NEW |
| 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_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 5 #ifndef REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| 6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "extensions/browser/api/messaging/native_message_host.h" |
| 18 #include "extensions/browser/api/messaging/native_messaging_channel.h" | 19 #include "extensions/browser/api/messaging/native_messaging_channel.h" |
| 19 #include "remoting/host/native_messaging/log_message_handler.h" | |
| 20 #include "remoting/host/setup/daemon_controller.h" | 20 #include "remoting/host/setup/daemon_controller.h" |
| 21 #include "remoting/host/setup/oauth_client.h" | 21 #include "remoting/host/setup/oauth_client.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 class DictionaryValue; | 24 class DictionaryValue; |
| 25 class ListValue; | 25 class ListValue; |
| 26 class SingleThreadTaskRunner; |
| 26 } // namespace base | 27 } // namespace base |
| 27 | 28 |
| 28 namespace gaia { | 29 namespace gaia { |
| 29 class GaiaOAuthClient; | 30 class GaiaOAuthClient; |
| 30 } // namespace gaia | 31 } // namespace gaia |
| 31 | 32 |
| 32 namespace remoting { | 33 namespace remoting { |
| 33 | 34 |
| 34 namespace protocol { | 35 namespace protocol { |
| 35 class PairingRegistry; | 36 class PairingRegistry; |
| 36 } // namespace protocol | 37 } // namespace protocol |
| 37 | 38 |
| 39 class ChromotingHostContext; |
| 40 class LogMessageHandler; |
| 41 |
| 38 // Implementation of the me2me native messaging host. | 42 // Implementation of the me2me native messaging host. |
| 39 class Me2MeNativeMessagingHost | 43 class Me2MeNativeMessagingHost : public extensions::NativeMessageHost { |
| 40 : public extensions::NativeMessagingChannel::EventHandler { | |
| 41 public: | 44 public: |
| 42 Me2MeNativeMessagingHost( | 45 Me2MeNativeMessagingHost( |
| 43 bool needs_elevation, | 46 bool needs_elevation, |
| 44 intptr_t parent_window_handle, | 47 intptr_t parent_window_handle, |
| 45 std::unique_ptr<extensions::NativeMessagingChannel> channel, | 48 std::unique_ptr<ChromotingHostContext> host_context, |
| 46 scoped_refptr<DaemonController> daemon_controller, | 49 scoped_refptr<DaemonController> daemon_controller, |
| 47 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 50 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
| 48 std::unique_ptr<OAuthClient> oauth_client); | 51 std::unique_ptr<OAuthClient> oauth_client); |
| 49 ~Me2MeNativeMessagingHost() override; | 52 ~Me2MeNativeMessagingHost() override; |
| 50 | 53 |
| 51 void Start(const base::Closure& quit_closure); | 54 // extensions::NativeMessageHost implementation. |
| 52 | 55 void OnMessage(const std::string& message) override; |
| 53 // extensions::NativeMessagingChannel::EventHandler implementation | 56 void Start(extensions::NativeMessageHost::Client* client) override; |
| 54 void OnMessage(std::unique_ptr<base::Value> message) override; | 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override; |
| 55 void OnDisconnect() override; | |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 // These "Process.." methods handle specific request types. The |response| | 60 // These "Process.." methods handle specific request types. The |response| |
| 59 // dictionary is pre-filled by ProcessMessage() with the parts of the | 61 // dictionary is pre-filled by ProcessMessage() with the parts of the |
| 60 // response already known ("id" and "type" fields). | 62 // response already known ("id" and "type" fields). |
| 61 void ProcessHello(std::unique_ptr<base::DictionaryValue> message, | 63 void ProcessHello(std::unique_ptr<base::DictionaryValue> message, |
| 62 std::unique_ptr<base::DictionaryValue> response); | 64 std::unique_ptr<base::DictionaryValue> response); |
| 63 void ProcessClearPairedClients( | 65 void ProcessClearPairedClients( |
| 64 std::unique_ptr<base::DictionaryValue> message, | 66 std::unique_ptr<base::DictionaryValue> message, |
| 65 std::unique_ptr<base::DictionaryValue> response); | 67 std::unique_ptr<base::DictionaryValue> response); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void SendUsageStatsConsentResponse( | 109 void SendUsageStatsConsentResponse( |
| 108 std::unique_ptr<base::DictionaryValue> response, | 110 std::unique_ptr<base::DictionaryValue> response, |
| 109 const DaemonController::UsageStatsConsent& consent); | 111 const DaemonController::UsageStatsConsent& consent); |
| 110 void SendAsyncResult(std::unique_ptr<base::DictionaryValue> response, | 112 void SendAsyncResult(std::unique_ptr<base::DictionaryValue> response, |
| 111 DaemonController::AsyncResult result); | 113 DaemonController::AsyncResult result); |
| 112 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, | 114 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, |
| 113 bool result); | 115 bool result); |
| 114 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, | 116 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, |
| 115 const std::string& user_email, | 117 const std::string& user_email, |
| 116 const std::string& refresh_token); | 118 const std::string& refresh_token); |
| 119 void SendMessageToClient(std::unique_ptr<base::Value> message) const; |
| 117 | 120 |
| 118 void OnError(); | 121 void OnError(const std::string& error_message); |
| 119 | |
| 120 void Stop(); | |
| 121 | 122 |
| 122 // Returns true if the request was successfully delegated to the elevated | 123 // Returns true if the request was successfully delegated to the elevated |
| 123 // host and false otherwise. | 124 // host and false otherwise. |
| 124 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); | 125 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); |
| 125 | 126 |
| 126 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
| 127 class ElevatedChannelEventHandler | 128 class ElevatedChannelEventHandler |
| 128 : public extensions::NativeMessagingChannel::EventHandler { | 129 : public extensions::NativeMessagingChannel::EventHandler { |
| 129 public: | 130 public: |
| 130 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host); | 131 ElevatedChannelEventHandler(extensions::NativeMessageHost::Client* client); |
| 131 | 132 |
| 133 // extensions::NativeMessagingChannel::EventHandler implementation. |
| 132 void OnMessage(std::unique_ptr<base::Value> message) override; | 134 void OnMessage(std::unique_ptr<base::Value> message) override; |
| 133 void OnDisconnect() override; | 135 void OnDisconnect() override; |
| 136 |
| 134 private: | 137 private: |
| 135 Me2MeNativeMessagingHost* parent_; | 138 extensions::NativeMessageHost::Client* client_; |
| 139 |
| 140 base::ThreadChecker thread_checker_; |
| 136 }; | 141 }; |
| 137 | 142 |
| 138 // Create and connect to an elevated host process if necessary. | 143 // Create and connect to an elevated host process if necessary. |
| 139 // |elevated_channel_| will contain the native messaging channel to the | 144 // |elevated_channel_| will contain the native messaging channel to the |
| 140 // elevated host if the function succeeds. | 145 // elevated host if the function succeeds. |
| 141 void EnsureElevatedHostCreated(); | 146 void EnsureElevatedHostCreated(); |
| 142 | 147 |
| 143 // Disconnect and shut down the elevated host. | 148 // Disconnect and shut down the elevated host. |
| 144 void DisconnectElevatedHost(); | 149 void DisconnectElevatedHost(); |
| 145 | 150 |
| 146 // Native messaging channel used to communicate with the elevated host. | 151 // Native messaging channel used to communicate with the elevated host. |
| 147 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_; | 152 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_; |
| 148 | 153 |
| 149 // Native messaging event handler used to process responses from the elevated | 154 // Native messaging event handler used to process responses from the elevated |
| 150 // host. | 155 // host. |
| 151 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; | 156 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; |
| 152 | 157 |
| 153 // Timer to control the lifetime of the elevated host. | 158 // Timer to control the lifetime of the elevated host. |
| 154 base::OneShotTimer elevated_host_timer_; | 159 base::OneShotTimer elevated_host_timer_; |
| 155 #endif // defined(OS_WIN) | 160 #endif // defined(OS_WIN) |
| 156 | 161 |
| 157 bool needs_elevation_; | 162 bool needs_elevation_; |
| 158 | 163 |
| 159 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
| 160 // Handle of the parent window. | 165 // Handle of the parent window. |
| 161 intptr_t parent_window_handle_; | 166 intptr_t parent_window_handle_; |
| 162 #endif // defined(OS_WIN) | 167 #endif // defined(OS_WIN) |
| 163 | 168 |
| 164 base::Closure quit_closure_; | 169 extensions::NativeMessageHost::Client* client_; |
| 170 std::unique_ptr<ChromotingHostContext> host_context_; |
| 165 | 171 |
| 166 // Native messaging channel used to communicate with the native message | 172 std::unique_ptr<LogMessageHandler> log_message_handler_; |
| 167 // client. | |
| 168 std::unique_ptr<extensions::NativeMessagingChannel> channel_; | |
| 169 | |
| 170 LogMessageHandler log_message_handler_; | |
| 171 | 173 |
| 172 scoped_refptr<DaemonController> daemon_controller_; | 174 scoped_refptr<DaemonController> daemon_controller_; |
| 173 | 175 |
| 174 // Used to load and update the paired clients for this host. | 176 // Used to load and update the paired clients for this host. |
| 175 scoped_refptr<protocol::PairingRegistry> pairing_registry_; | 177 scoped_refptr<protocol::PairingRegistry> pairing_registry_; |
| 176 | 178 |
| 177 // Used to exchange the service account authorization code for credentials. | 179 // Used to exchange the service account authorization code for credentials. |
| 178 std::unique_ptr<OAuthClient> oauth_client_; | 180 std::unique_ptr<OAuthClient> oauth_client_; |
| 179 | 181 |
| 180 base::ThreadChecker thread_checker_; | |
| 181 | |
| 182 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; | 182 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; |
| 183 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; | 183 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; |
| 184 | 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); | 185 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 } // namespace remoting | 188 } // namespace remoting |
| 189 | 189 |
| 190 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 190 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |