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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "google_apis/google_api_keys.h" | 13 #include "google_apis/google_api_keys.h" |
14 #include "remoting/host/pin_hash.h" | 14 #include "remoting/host/pin_hash.h" |
15 #include "remoting/host/setup/oauth_helper.h" | 15 #include "remoting/host/setup/oauth_helper.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 const int kMaxGetTokensRetries = 3; | 18 const int kMaxGetTokensRetries = 3; |
19 } // namespace | 19 } // namespace |
20 | 20 |
21 namespace remoting { | 21 namespace remoting { |
22 | 22 |
23 HostStarter::HostStarter( | 23 HostStarter::HostStarter( |
24 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, | 24 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, |
25 scoped_ptr<remoting::ServiceClient> service_client, | 25 scoped_ptr<remoting::ServiceClient> service_client, |
26 scoped_refptr<remoting::DaemonController> daemon_controller) | 26 scoped_refptr<remoting::DaemonController> daemon_controller) |
27 : oauth_client_(oauth_client.Pass()), | 27 : oauth_client_(std::move(oauth_client)), |
28 service_client_(service_client.Pass()), | 28 service_client_(std::move(service_client)), |
29 daemon_controller_(daemon_controller), | 29 daemon_controller_(daemon_controller), |
30 consent_to_data_collection_(false), | 30 consent_to_data_collection_(false), |
31 unregistering_host_(false), | 31 unregistering_host_(false), |
32 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
33 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 33 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
34 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 34 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
35 } | 35 } |
36 | 36 |
37 HostStarter::~HostStarter() { | 37 HostStarter::~HostStarter() { |
38 } | 38 } |
39 | 39 |
40 scoped_ptr<HostStarter> HostStarter::Create( | 40 scoped_ptr<HostStarter> HostStarter::Create( |
41 const std::string& chromoting_hosts_url, | 41 const std::string& chromoting_hosts_url, |
42 net::URLRequestContextGetter* url_request_context_getter) { | 42 net::URLRequestContextGetter* url_request_context_getter) { |
43 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( | 43 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( |
44 new gaia::GaiaOAuthClient(url_request_context_getter)); | 44 new gaia::GaiaOAuthClient(url_request_context_getter)); |
45 scoped_ptr<remoting::ServiceClient> service_client( | 45 scoped_ptr<remoting::ServiceClient> service_client( |
46 new remoting::ServiceClient( | 46 new remoting::ServiceClient( |
47 chromoting_hosts_url, url_request_context_getter)); | 47 chromoting_hosts_url, url_request_context_getter)); |
48 scoped_refptr<remoting::DaemonController> daemon_controller( | 48 scoped_refptr<remoting::DaemonController> daemon_controller( |
49 remoting::DaemonController::Create()); | 49 remoting::DaemonController::Create()); |
50 return make_scoped_ptr(new HostStarter( | 50 return make_scoped_ptr(new HostStarter( |
51 oauth_client.Pass(), service_client.Pass(), daemon_controller)); | 51 std::move(oauth_client), std::move(service_client), daemon_controller)); |
52 } | 52 } |
53 | 53 |
54 void HostStarter::StartHost( | 54 void HostStarter::StartHost( |
55 const std::string& host_name, | 55 const std::string& host_name, |
56 const std::string& host_pin, | 56 const std::string& host_pin, |
57 bool consent_to_data_collection, | 57 bool consent_to_data_collection, |
58 const std::string& auth_code, | 58 const std::string& auth_code, |
59 const std::string& redirect_url, | 59 const std::string& redirect_url, |
60 CompletionCallback on_done) { | 60 CompletionCallback on_done) { |
61 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 61 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (host_owner_ != xmpp_login_) { | 163 if (host_owner_ != xmpp_login_) { |
164 config->SetString("host_owner", host_owner_); | 164 config->SetString("host_owner", host_owner_); |
165 } | 165 } |
166 config->SetString("xmpp_login", xmpp_login_); | 166 config->SetString("xmpp_login", xmpp_login_); |
167 config->SetString("oauth_refresh_token", refresh_token_); | 167 config->SetString("oauth_refresh_token", refresh_token_); |
168 config->SetString("host_id", host_id_); | 168 config->SetString("host_id", host_id_); |
169 config->SetString("host_name", host_name_); | 169 config->SetString("host_name", host_name_); |
170 config->SetString("private_key", key_pair_->ToString()); | 170 config->SetString("private_key", key_pair_->ToString()); |
171 config->SetString("host_secret_hash", host_secret_hash); | 171 config->SetString("host_secret_hash", host_secret_hash); |
172 daemon_controller_->SetConfigAndStart( | 172 daemon_controller_->SetConfigAndStart( |
173 config.Pass(), consent_to_data_collection_, | 173 std::move(config), consent_to_data_collection_, |
174 base::Bind(&HostStarter::OnHostStarted, base::Unretained(this))); | 174 base::Bind(&HostStarter::OnHostStarted, base::Unretained(this))); |
175 } | 175 } |
176 | 176 |
177 void HostStarter::OnHostStarted(DaemonController::AsyncResult result) { | 177 void HostStarter::OnHostStarted(DaemonController::AsyncResult result) { |
178 if (!main_task_runner_->BelongsToCurrentThread()) { | 178 if (!main_task_runner_->BelongsToCurrentThread()) { |
179 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 179 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
180 &HostStarter::OnHostStarted, weak_ptr_, result)); | 180 &HostStarter::OnHostStarted, weak_ptr_, result)); |
181 return; | 181 return; |
182 } | 182 } |
183 if (result != DaemonController::RESULT_OK) { | 183 if (result != DaemonController::RESULT_OK) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 void HostStarter::OnHostUnregistered() { | 219 void HostStarter::OnHostUnregistered() { |
220 if (!main_task_runner_->BelongsToCurrentThread()) { | 220 if (!main_task_runner_->BelongsToCurrentThread()) { |
221 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 221 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
222 &HostStarter::OnHostUnregistered, weak_ptr_)); | 222 &HostStarter::OnHostUnregistered, weak_ptr_)); |
223 return; | 223 return; |
224 } | 224 } |
225 base::ResetAndReturn(&on_done_).Run(START_ERROR); | 225 base::ResetAndReturn(&on_done_).Run(START_ERROR); |
226 } | 226 } |
227 | 227 |
228 } // namespace remoting | 228 } // namespace remoting |
OLD | NEW |