OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "remoting/host/setup/host_starter.h" | 5 #include "remoting/host/setup/host_starter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "google_apis/google_api_keys.h" | 16 #include "google_apis/google_api_keys.h" |
16 #include "remoting/host/pin_hash.h" | 17 #include "remoting/host/pin_hash.h" |
17 #include "remoting/host/setup/oauth_helper.h" | 18 #include "remoting/host/setup/oauth_helper.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 const int kMaxGetTokensRetries = 3; | 21 const int kMaxGetTokensRetries = 3; |
21 } // namespace | 22 } // namespace |
22 | 23 |
23 namespace remoting { | 24 namespace remoting { |
24 | 25 |
25 HostStarter::HostStarter( | 26 HostStarter::HostStarter( |
26 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, | 27 std::unique_ptr<gaia::GaiaOAuthClient> oauth_client, |
27 scoped_ptr<remoting::ServiceClient> service_client, | 28 std::unique_ptr<remoting::ServiceClient> service_client, |
28 scoped_refptr<remoting::DaemonController> daemon_controller) | 29 scoped_refptr<remoting::DaemonController> daemon_controller) |
29 : oauth_client_(std::move(oauth_client)), | 30 : oauth_client_(std::move(oauth_client)), |
30 service_client_(std::move(service_client)), | 31 service_client_(std::move(service_client)), |
31 daemon_controller_(daemon_controller), | 32 daemon_controller_(daemon_controller), |
32 consent_to_data_collection_(false), | 33 consent_to_data_collection_(false), |
33 unregistering_host_(false), | 34 unregistering_host_(false), |
34 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
35 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 36 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
36 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 37 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
37 } | 38 } |
38 | 39 |
39 HostStarter::~HostStarter() {} | 40 HostStarter::~HostStarter() {} |
40 | 41 |
41 scoped_ptr<HostStarter> HostStarter::Create( | 42 std::unique_ptr<HostStarter> HostStarter::Create( |
42 const std::string& chromoting_hosts_url, | 43 const std::string& chromoting_hosts_url, |
43 net::URLRequestContextGetter* url_request_context_getter) { | 44 net::URLRequestContextGetter* url_request_context_getter) { |
44 return make_scoped_ptr(new HostStarter( | 45 return base::WrapUnique(new HostStarter( |
45 make_scoped_ptr(new gaia::GaiaOAuthClient(url_request_context_getter)), | 46 base::WrapUnique(new gaia::GaiaOAuthClient(url_request_context_getter)), |
46 make_scoped_ptr(new remoting::ServiceClient(chromoting_hosts_url, | 47 base::WrapUnique(new remoting::ServiceClient(chromoting_hosts_url, |
47 url_request_context_getter)), | 48 url_request_context_getter)), |
48 remoting::DaemonController::Create())); | 49 remoting::DaemonController::Create())); |
49 } | 50 } |
50 | 51 |
51 void HostStarter::StartHost( | 52 void HostStarter::StartHost( |
52 const std::string& host_name, | 53 const std::string& host_name, |
53 const std::string& host_pin, | 54 const std::string& host_pin, |
54 bool consent_to_data_collection, | 55 bool consent_to_data_collection, |
55 const std::string& auth_code, | 56 const std::string& auth_code, |
56 const std::string& redirect_url, | 57 const std::string& redirect_url, |
57 CompletionCallback on_done) { | 58 CompletionCallback on_done) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 google_apis::GetOAuth2ClientSecret( | 150 google_apis::GetOAuth2ClientSecret( |
150 google_apis::CLIENT_REMOTING_HOST); | 151 google_apis::CLIENT_REMOTING_HOST); |
151 oauth_client_info_.redirect_uri = "oob"; | 152 oauth_client_info_.redirect_uri = "oob"; |
152 oauth_client_->GetTokensFromAuthCode( | 153 oauth_client_->GetTokensFromAuthCode( |
153 oauth_client_info_, authorization_code, kMaxGetTokensRetries, this); | 154 oauth_client_info_, authorization_code, kMaxGetTokensRetries, this); |
154 } | 155 } |
155 | 156 |
156 void HostStarter::StartHostProcess() { | 157 void HostStarter::StartHostProcess() { |
157 // Start the host. | 158 // Start the host. |
158 std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_); | 159 std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_); |
159 scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue()); | 160 std::unique_ptr<base::DictionaryValue> config(new base::DictionaryValue()); |
160 if (host_owner_ != xmpp_login_) { | 161 if (host_owner_ != xmpp_login_) { |
161 config->SetString("host_owner", host_owner_); | 162 config->SetString("host_owner", host_owner_); |
162 } | 163 } |
163 config->SetString("xmpp_login", xmpp_login_); | 164 config->SetString("xmpp_login", xmpp_login_); |
164 config->SetString("oauth_refresh_token", refresh_token_); | 165 config->SetString("oauth_refresh_token", refresh_token_); |
165 config->SetString("host_id", host_id_); | 166 config->SetString("host_id", host_id_); |
166 config->SetString("host_name", host_name_); | 167 config->SetString("host_name", host_name_); |
167 config->SetString("private_key", key_pair_->ToString()); | 168 config->SetString("private_key", key_pair_->ToString()); |
168 config->SetString("host_secret_hash", host_secret_hash); | 169 config->SetString("host_secret_hash", host_secret_hash); |
169 daemon_controller_->SetConfigAndStart( | 170 daemon_controller_->SetConfigAndStart( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void HostStarter::OnHostUnregistered() { | 217 void HostStarter::OnHostUnregistered() { |
217 if (!main_task_runner_->BelongsToCurrentThread()) { | 218 if (!main_task_runner_->BelongsToCurrentThread()) { |
218 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 219 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
219 &HostStarter::OnHostUnregistered, weak_ptr_)); | 220 &HostStarter::OnHostUnregistered, weak_ptr_)); |
220 return; | 221 return; |
221 } | 222 } |
222 base::ResetAndReturn(&on_done_).Run(START_ERROR); | 223 base::ResetAndReturn(&on_done_).Run(START_ERROR); |
223 } | 224 } |
224 | 225 |
225 } // namespace remoting | 226 } // namespace remoting |
OLD | NEW |