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