| 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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 bool needs_elevation, | 41 bool needs_elevation, |
| 42 scoped_ptr<NativeMessagingChannel> channel, | 42 scoped_ptr<NativeMessagingChannel> channel, |
| 43 scoped_refptr<DaemonController> daemon_controller, | 43 scoped_refptr<DaemonController> daemon_controller, |
| 44 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 44 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
| 45 scoped_ptr<OAuthClient> oauth_client); | 45 scoped_ptr<OAuthClient> oauth_client); |
| 46 virtual ~Me2MeNativeMessagingHost(); | 46 virtual ~Me2MeNativeMessagingHost(); |
| 47 | 47 |
| 48 void Start(const base::Closure& quit_closure); | 48 void Start(const base::Closure& quit_closure); |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 // Callback to process messages from the native messaging client through |
| 52 // |channel_|. |
| 51 void ProcessRequest(scoped_ptr<base::DictionaryValue> message); | 53 void ProcessRequest(scoped_ptr<base::DictionaryValue> message); |
| 52 | 54 |
| 53 // These "Process.." methods handle specific request types. The |response| | 55 // These "Process.." methods handle specific request types. The |response| |
| 54 // dictionary is pre-filled by ProcessMessage() with the parts of the | 56 // dictionary is pre-filled by ProcessMessage() with the parts of the |
| 55 // response already known ("id" and "type" fields). | 57 // response already known ("id" and "type" fields). |
| 56 void ProcessHello( | 58 void ProcessHello( |
| 57 scoped_ptr<base::DictionaryValue> message, | 59 scoped_ptr<base::DictionaryValue> message, |
| 58 scoped_ptr<base::DictionaryValue> response); | 60 scoped_ptr<base::DictionaryValue> response); |
| 59 void ProcessClearPairedClients( | 61 void ProcessClearPairedClients( |
| 60 scoped_ptr<base::DictionaryValue> message, | 62 scoped_ptr<base::DictionaryValue> message, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response, | 117 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response, |
| 116 bool result); | 118 bool result); |
| 117 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response, | 119 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response, |
| 118 const std::string& user_email, | 120 const std::string& user_email, |
| 119 const std::string& refresh_token); | 121 const std::string& refresh_token); |
| 120 | 122 |
| 121 void OnError(); | 123 void OnError(); |
| 122 | 124 |
| 123 void Stop(); | 125 void Stop(); |
| 124 | 126 |
| 125 void DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message, | 127 // Returns true if the request was successfully delegated to the elevated |
| 126 scoped_ptr<base::DictionaryValue> response); | 128 // host and false otherwise. |
| 129 bool DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message); |
| 127 | 130 |
| 128 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
| 132 // Create and connect to an elevated host process if necessary. |
| 133 // |elevated_channel_| will contain the native messaging channel to the |
| 134 // elevated host if the function succeeds. |
| 129 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated(); | 135 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated(); |
| 136 |
| 137 // Callback to process messages from the elevated host through |
| 138 // |elevated_channel_|. |
| 130 void ProcessDelegateResponse(scoped_ptr<base::DictionaryValue> message); | 139 void ProcessDelegateResponse(scoped_ptr<base::DictionaryValue> message); |
| 131 | 140 |
| 132 // input/output handles for the channel to the elevated host. | 141 // Native messaging channel used to communicate with the elevated host. |
| 133 base::win::ScopedHandle delegate_write_handle_; | |
| 134 base::win::ScopedHandle delegate_read_handle_; | |
| 135 scoped_ptr<NativeMessagingChannel> elevated_channel_; | 142 scoped_ptr<NativeMessagingChannel> elevated_channel_; |
| 136 #endif // defined(OS_WIN) | 143 #endif // defined(OS_WIN) |
| 137 | 144 |
| 138 bool needs_elevation_; | 145 bool needs_elevation_; |
| 139 base::Closure quit_closure_; | 146 base::Closure quit_closure_; |
| 147 |
| 148 // Native messaging channel used to communicate with the native message |
| 149 // client. |
| 140 scoped_ptr<NativeMessagingChannel> channel_; | 150 scoped_ptr<NativeMessagingChannel> channel_; |
| 141 scoped_refptr<DaemonController> daemon_controller_; | 151 scoped_refptr<DaemonController> daemon_controller_; |
| 142 | 152 |
| 143 // Used to load and update the paired clients for this host. | 153 // Used to load and update the paired clients for this host. |
| 144 scoped_refptr<protocol::PairingRegistry> pairing_registry_; | 154 scoped_refptr<protocol::PairingRegistry> pairing_registry_; |
| 145 | 155 |
| 146 // Used to exchange the service account authorization code for credentials. | 156 // Used to exchange the service account authorization code for credentials. |
| 147 scoped_ptr<OAuthClient> oauth_client_; | 157 scoped_ptr<OAuthClient> oauth_client_; |
| 148 | 158 |
| 149 base::ThreadChecker thread_checker_; | 159 base::ThreadChecker thread_checker_; |
| 150 | 160 |
| 151 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; | 161 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; |
| 152 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; | 162 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; |
| 153 | 163 |
| 154 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); | 164 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); |
| 155 }; | 165 }; |
| 156 | 166 |
| 157 // Creates a Me2MeNativeMessagingHost instance, attaches it to stdin/stdout and | 167 // Creates a Me2MeNativeMessagingHost instance, attaches it to stdin/stdout and |
| 158 // runs the message loop until Me2MeNativeMessagingHost signals shutdown. | 168 // runs the message loop until Me2MeNativeMessagingHost signals shutdown. |
| 159 int Me2MeNativeMessagingHostMain(); | 169 int Me2MeNativeMessagingHostMain(); |
| 160 | 170 |
| 161 } // namespace remoting | 171 } // namespace remoting |
| 162 | 172 |
| 163 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 173 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |