| 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 <memory> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "extensions/browser/api/messaging/native_messaging_channel.h" | 16 #include "extensions/browser/api/messaging/native_messaging_channel.h" |
| 16 #include "remoting/host/native_messaging/log_message_handler.h" | 17 #include "remoting/host/native_messaging/log_message_handler.h" |
| 17 #include "remoting/host/setup/daemon_controller.h" | 18 #include "remoting/host/setup/daemon_controller.h" |
| 18 #include "remoting/host/setup/oauth_client.h" | 19 #include "remoting/host/setup/oauth_client.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 class PairingRegistry; | 37 class PairingRegistry; |
| 37 } // namespace protocol | 38 } // namespace protocol |
| 38 | 39 |
| 39 // Implementation of the me2me native messaging host. | 40 // Implementation of the me2me native messaging host. |
| 40 class Me2MeNativeMessagingHost | 41 class Me2MeNativeMessagingHost |
| 41 : public extensions::NativeMessagingChannel::EventHandler { | 42 : public extensions::NativeMessagingChannel::EventHandler { |
| 42 public: | 43 public: |
| 43 Me2MeNativeMessagingHost( | 44 Me2MeNativeMessagingHost( |
| 44 bool needs_elevation, | 45 bool needs_elevation, |
| 45 intptr_t parent_window_handle, | 46 intptr_t parent_window_handle, |
| 46 scoped_ptr<extensions::NativeMessagingChannel> channel, | 47 std::unique_ptr<extensions::NativeMessagingChannel> channel, |
| 47 scoped_refptr<DaemonController> daemon_controller, | 48 scoped_refptr<DaemonController> daemon_controller, |
| 48 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 49 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
| 49 scoped_ptr<OAuthClient> oauth_client); | 50 std::unique_ptr<OAuthClient> oauth_client); |
| 50 ~Me2MeNativeMessagingHost() override; | 51 ~Me2MeNativeMessagingHost() override; |
| 51 | 52 |
| 52 void Start(const base::Closure& quit_closure); | 53 void Start(const base::Closure& quit_closure); |
| 53 | 54 |
| 54 // extensions::NativeMessagingChannel::EventHandler implementation | 55 // extensions::NativeMessagingChannel::EventHandler implementation |
| 55 void OnMessage(scoped_ptr<base::Value> message) override; | 56 void OnMessage(std::unique_ptr<base::Value> message) override; |
| 56 void OnDisconnect() override; | 57 void OnDisconnect() override; |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 // These "Process.." methods handle specific request types. The |response| | 60 // These "Process.." methods handle specific request types. The |response| |
| 60 // dictionary is pre-filled by ProcessMessage() with the parts of the | 61 // dictionary is pre-filled by ProcessMessage() with the parts of the |
| 61 // response already known ("id" and "type" fields). | 62 // response already known ("id" and "type" fields). |
| 62 void ProcessHello( | 63 void ProcessHello(std::unique_ptr<base::DictionaryValue> message, |
| 63 scoped_ptr<base::DictionaryValue> message, | 64 std::unique_ptr<base::DictionaryValue> response); |
| 64 scoped_ptr<base::DictionaryValue> response); | |
| 65 void ProcessClearPairedClients( | 65 void ProcessClearPairedClients( |
| 66 scoped_ptr<base::DictionaryValue> message, | 66 std::unique_ptr<base::DictionaryValue> message, |
| 67 scoped_ptr<base::DictionaryValue> response); | 67 std::unique_ptr<base::DictionaryValue> response); |
| 68 void ProcessDeletePairedClient( | 68 void ProcessDeletePairedClient( |
| 69 scoped_ptr<base::DictionaryValue> message, | 69 std::unique_ptr<base::DictionaryValue> message, |
| 70 scoped_ptr<base::DictionaryValue> response); | 70 std::unique_ptr<base::DictionaryValue> response); |
| 71 void ProcessGetHostName( | 71 void ProcessGetHostName(std::unique_ptr<base::DictionaryValue> message, |
| 72 scoped_ptr<base::DictionaryValue> message, | 72 std::unique_ptr<base::DictionaryValue> response); |
| 73 scoped_ptr<base::DictionaryValue> response); | 73 void ProcessGetPinHash(std::unique_ptr<base::DictionaryValue> message, |
| 74 void ProcessGetPinHash( | 74 std::unique_ptr<base::DictionaryValue> response); |
| 75 scoped_ptr<base::DictionaryValue> message, | 75 void ProcessGenerateKeyPair(std::unique_ptr<base::DictionaryValue> message, |
| 76 scoped_ptr<base::DictionaryValue> response); | 76 std::unique_ptr<base::DictionaryValue> response); |
| 77 void ProcessGenerateKeyPair( | |
| 78 scoped_ptr<base::DictionaryValue> message, | |
| 79 scoped_ptr<base::DictionaryValue> response); | |
| 80 void ProcessUpdateDaemonConfig( | 77 void ProcessUpdateDaemonConfig( |
| 81 scoped_ptr<base::DictionaryValue> message, | 78 std::unique_ptr<base::DictionaryValue> message, |
| 82 scoped_ptr<base::DictionaryValue> response); | 79 std::unique_ptr<base::DictionaryValue> response); |
| 83 void ProcessGetDaemonConfig( | 80 void ProcessGetDaemonConfig(std::unique_ptr<base::DictionaryValue> message, |
| 84 scoped_ptr<base::DictionaryValue> message, | 81 std::unique_ptr<base::DictionaryValue> response); |
| 85 scoped_ptr<base::DictionaryValue> response); | 82 void ProcessGetPairedClients(std::unique_ptr<base::DictionaryValue> message, |
| 86 void ProcessGetPairedClients( | 83 std::unique_ptr<base::DictionaryValue> response); |
| 87 scoped_ptr<base::DictionaryValue> message, | |
| 88 scoped_ptr<base::DictionaryValue> response); | |
| 89 void ProcessGetUsageStatsConsent( | 84 void ProcessGetUsageStatsConsent( |
| 90 scoped_ptr<base::DictionaryValue> message, | 85 std::unique_ptr<base::DictionaryValue> message, |
| 91 scoped_ptr<base::DictionaryValue> response); | 86 std::unique_ptr<base::DictionaryValue> response); |
| 92 void ProcessStartDaemon( | 87 void ProcessStartDaemon(std::unique_ptr<base::DictionaryValue> message, |
| 93 scoped_ptr<base::DictionaryValue> message, | 88 std::unique_ptr<base::DictionaryValue> response); |
| 94 scoped_ptr<base::DictionaryValue> response); | 89 void ProcessStopDaemon(std::unique_ptr<base::DictionaryValue> message, |
| 95 void ProcessStopDaemon( | 90 std::unique_ptr<base::DictionaryValue> response); |
| 96 scoped_ptr<base::DictionaryValue> message, | 91 void ProcessGetDaemonState(std::unique_ptr<base::DictionaryValue> message, |
| 97 scoped_ptr<base::DictionaryValue> response); | 92 std::unique_ptr<base::DictionaryValue> response); |
| 98 void ProcessGetDaemonState( | 93 void ProcessGetHostClientId(std::unique_ptr<base::DictionaryValue> message, |
| 99 scoped_ptr<base::DictionaryValue> message, | 94 std::unique_ptr<base::DictionaryValue> response); |
| 100 scoped_ptr<base::DictionaryValue> response); | |
| 101 void ProcessGetHostClientId( | |
| 102 scoped_ptr<base::DictionaryValue> message, | |
| 103 scoped_ptr<base::DictionaryValue> response); | |
| 104 void ProcessGetCredentialsFromAuthCode( | 95 void ProcessGetCredentialsFromAuthCode( |
| 105 scoped_ptr<base::DictionaryValue> message, | 96 std::unique_ptr<base::DictionaryValue> message, |
| 106 scoped_ptr<base::DictionaryValue> response, | 97 std::unique_ptr<base::DictionaryValue> response, |
| 107 bool need_user_email); | 98 bool need_user_email); |
| 108 | 99 |
| 109 // These Send... methods get called on the DaemonController's internal thread, | 100 // These Send... methods get called on the DaemonController's internal thread, |
| 110 // or on the calling thread if called by the PairingRegistry. | 101 // or on the calling thread if called by the PairingRegistry. |
| 111 // These methods fill in the |response| dictionary from the other parameters, | 102 // These methods fill in the |response| dictionary from the other parameters, |
| 112 // and pass it to SendResponse(). | 103 // and pass it to SendResponse(). |
| 113 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, | 104 void SendConfigResponse(std::unique_ptr<base::DictionaryValue> response, |
| 114 scoped_ptr<base::DictionaryValue> config); | 105 std::unique_ptr<base::DictionaryValue> config); |
| 115 void SendPairedClientsResponse(scoped_ptr<base::DictionaryValue> response, | 106 void SendPairedClientsResponse( |
| 116 scoped_ptr<base::ListValue> pairings); | 107 std::unique_ptr<base::DictionaryValue> response, |
| 108 std::unique_ptr<base::ListValue> pairings); |
| 117 void SendUsageStatsConsentResponse( | 109 void SendUsageStatsConsentResponse( |
| 118 scoped_ptr<base::DictionaryValue> response, | 110 std::unique_ptr<base::DictionaryValue> response, |
| 119 const DaemonController::UsageStatsConsent& consent); | 111 const DaemonController::UsageStatsConsent& consent); |
| 120 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, | 112 void SendAsyncResult(std::unique_ptr<base::DictionaryValue> response, |
| 121 DaemonController::AsyncResult result); | 113 DaemonController::AsyncResult result); |
| 122 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response, | 114 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, |
| 123 bool result); | 115 bool result); |
| 124 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response, | 116 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, |
| 125 const std::string& user_email, | 117 const std::string& user_email, |
| 126 const std::string& refresh_token); | 118 const std::string& refresh_token); |
| 127 | 119 |
| 128 void OnError(); | 120 void OnError(); |
| 129 | 121 |
| 130 void Stop(); | 122 void Stop(); |
| 131 | 123 |
| 132 // Returns true if the request was successfully delegated to the elevated | 124 // Returns true if the request was successfully delegated to the elevated |
| 133 // host and false otherwise. | 125 // host and false otherwise. |
| 134 bool DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message); | 126 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); |
| 135 | 127 |
| 136 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
| 137 class ElevatedChannelEventHandler | 129 class ElevatedChannelEventHandler |
| 138 : public extensions::NativeMessagingChannel::EventHandler { | 130 : public extensions::NativeMessagingChannel::EventHandler { |
| 139 public: | 131 public: |
| 140 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host); | 132 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host); |
| 141 | 133 |
| 142 void OnMessage(scoped_ptr<base::Value> message) override; | 134 void OnMessage(std::unique_ptr<base::Value> message) override; |
| 143 void OnDisconnect() override; | 135 void OnDisconnect() override; |
| 144 private: | 136 private: |
| 145 Me2MeNativeMessagingHost* parent_; | 137 Me2MeNativeMessagingHost* parent_; |
| 146 }; | 138 }; |
| 147 | 139 |
| 148 // Create and connect to an elevated host process if necessary. | 140 // Create and connect to an elevated host process if necessary. |
| 149 // |elevated_channel_| will contain the native messaging channel to the | 141 // |elevated_channel_| will contain the native messaging channel to the |
| 150 // elevated host if the function succeeds. | 142 // elevated host if the function succeeds. |
| 151 void EnsureElevatedHostCreated(); | 143 void EnsureElevatedHostCreated(); |
| 152 | 144 |
| 153 // Disconnect and shut down the elevated host. | 145 // Disconnect and shut down the elevated host. |
| 154 void DisconnectElevatedHost(); | 146 void DisconnectElevatedHost(); |
| 155 | 147 |
| 156 // Native messaging channel used to communicate with the elevated host. | 148 // Native messaging channel used to communicate with the elevated host. |
| 157 scoped_ptr<extensions::NativeMessagingChannel> elevated_channel_; | 149 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_; |
| 158 | 150 |
| 159 // Native messaging event handler used to process responses from the elevated | 151 // Native messaging event handler used to process responses from the elevated |
| 160 // host. | 152 // host. |
| 161 scoped_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; | 153 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; |
| 162 | 154 |
| 163 // Timer to control the lifetime of the elevated host. | 155 // Timer to control the lifetime of the elevated host. |
| 164 base::OneShotTimer elevated_host_timer_; | 156 base::OneShotTimer elevated_host_timer_; |
| 165 #endif // defined(OS_WIN) | 157 #endif // defined(OS_WIN) |
| 166 | 158 |
| 167 bool needs_elevation_; | 159 bool needs_elevation_; |
| 168 | 160 |
| 169 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 170 // Handle of the parent window. | 162 // Handle of the parent window. |
| 171 intptr_t parent_window_handle_; | 163 intptr_t parent_window_handle_; |
| 172 #endif // defined(OS_WIN) | 164 #endif // defined(OS_WIN) |
| 173 | 165 |
| 174 base::Closure quit_closure_; | 166 base::Closure quit_closure_; |
| 175 | 167 |
| 176 // Native messaging channel used to communicate with the native message | 168 // Native messaging channel used to communicate with the native message |
| 177 // client. | 169 // client. |
| 178 scoped_ptr<extensions::NativeMessagingChannel> channel_; | 170 std::unique_ptr<extensions::NativeMessagingChannel> channel_; |
| 179 | 171 |
| 180 LogMessageHandler log_message_handler_; | 172 LogMessageHandler log_message_handler_; |
| 181 | 173 |
| 182 scoped_refptr<DaemonController> daemon_controller_; | 174 scoped_refptr<DaemonController> daemon_controller_; |
| 183 | 175 |
| 184 // Used to load and update the paired clients for this host. | 176 // Used to load and update the paired clients for this host. |
| 185 scoped_refptr<protocol::PairingRegistry> pairing_registry_; | 177 scoped_refptr<protocol::PairingRegistry> pairing_registry_; |
| 186 | 178 |
| 187 // Used to exchange the service account authorization code for credentials. | 179 // Used to exchange the service account authorization code for credentials. |
| 188 scoped_ptr<OAuthClient> oauth_client_; | 180 std::unique_ptr<OAuthClient> oauth_client_; |
| 189 | 181 |
| 190 base::ThreadChecker thread_checker_; | 182 base::ThreadChecker thread_checker_; |
| 191 | 183 |
| 192 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; | 184 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; |
| 193 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; | 185 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; |
| 194 | 186 |
| 195 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); | 187 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); |
| 196 }; | 188 }; |
| 197 | 189 |
| 198 } // namespace remoting | 190 } // namespace remoting |
| 199 | 191 |
| 200 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 192 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |