| 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/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "google_apis/google_api_keys.h" | 10 #include "google_apis/google_api_keys.h" |
| 11 #include "remoting/host/pin_hash.h" | 11 #include "remoting/host/pin_hash.h" |
| 12 #include "remoting/host/setup/oauth_helper.h" | 12 #include "remoting/host/setup/oauth_helper.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 const int kMaxGetTokensRetries = 3; | 15 const int kMaxGetTokensRetries = 3; |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 HostStarter::HostStarter( | 20 HostStarter::HostStarter( |
| 21 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, | 21 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, |
| 22 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher, | |
| 23 scoped_ptr<remoting::ServiceClient> service_client, | 22 scoped_ptr<remoting::ServiceClient> service_client, |
| 24 scoped_ptr<remoting::DaemonController> daemon_controller) | 23 scoped_ptr<remoting::DaemonController> daemon_controller) |
| 25 : oauth_client_(oauth_client.Pass()), | 24 : oauth_client_(oauth_client.Pass()), |
| 26 user_email_fetcher_(user_email_fetcher.Pass()), | |
| 27 service_client_(service_client.Pass()), | 25 service_client_(service_client.Pass()), |
| 28 daemon_controller_(daemon_controller.Pass()), | 26 daemon_controller_(daemon_controller.Pass()), |
| 29 consent_to_data_collection_(false), | 27 consent_to_data_collection_(false), |
| 30 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 31 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { | 29 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
| 32 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 30 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 33 } | 31 } |
| 34 | 32 |
| 35 HostStarter::~HostStarter() { | 33 HostStarter::~HostStarter() { |
| 36 } | 34 } |
| 37 | 35 |
| 38 scoped_ptr<HostStarter> HostStarter::Create( | 36 scoped_ptr<HostStarter> HostStarter::Create( |
| 39 net::URLRequestContextGetter* url_request_context_getter) { | 37 net::URLRequestContextGetter* url_request_context_getter) { |
| 40 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( | 38 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( |
| 41 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, | 39 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, |
| 42 url_request_context_getter)); | 40 url_request_context_getter)); |
| 43 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher( | |
| 44 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); | |
| 45 scoped_ptr<remoting::ServiceClient> service_client( | 41 scoped_ptr<remoting::ServiceClient> service_client( |
| 46 new remoting::ServiceClient(url_request_context_getter)); | 42 new remoting::ServiceClient(url_request_context_getter)); |
| 47 scoped_ptr<remoting::DaemonController> daemon_controller( | 43 scoped_ptr<remoting::DaemonController> daemon_controller( |
| 48 remoting::DaemonController::Create()); | 44 remoting::DaemonController::Create()); |
| 49 return scoped_ptr<HostStarter>( | 45 return scoped_ptr<HostStarter>( |
| 50 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), | 46 new HostStarter(oauth_client.Pass(), service_client.Pass(), |
| 51 service_client.Pass(), daemon_controller.Pass())); | 47 daemon_controller.Pass())); |
| 52 } | 48 } |
| 53 | 49 |
| 54 void HostStarter::StartHost( | 50 void HostStarter::StartHost( |
| 55 const std::string& host_name, | 51 const std::string& host_name, |
| 56 const std::string& host_pin, | 52 const std::string& host_pin, |
| 57 bool consent_to_data_collection, | 53 bool consent_to_data_collection, |
| 58 const std::string& auth_code, | 54 const std::string& auth_code, |
| 59 const std::string& redirect_url, | 55 const std::string& redirect_url, |
| 60 CompletionCallback on_done) { | 56 CompletionCallback on_done) { |
| 61 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 57 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 int expires_in_seconds) { | 77 int expires_in_seconds) { |
| 82 if (!main_task_runner_->BelongsToCurrentThread()) { | 78 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 83 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 79 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 84 &HostStarter::OnGetTokensResponse, weak_ptr_, | 80 &HostStarter::OnGetTokensResponse, weak_ptr_, |
| 85 refresh_token, access_token, expires_in_seconds)); | 81 refresh_token, access_token, expires_in_seconds)); |
| 86 return; | 82 return; |
| 87 } | 83 } |
| 88 refresh_token_ = refresh_token; | 84 refresh_token_ = refresh_token; |
| 89 access_token_ = access_token; | 85 access_token_ = access_token; |
| 90 // Get the email corresponding to the access token. | 86 // Get the email corresponding to the access token. |
| 91 user_email_fetcher_->GetUserEmail(access_token_, this); | 87 oauth_client_->GetUserInfo(access_token_, 1, this); |
| 92 } | 88 } |
| 93 | 89 |
| 94 void HostStarter::OnRefreshTokenResponse( | 90 void HostStarter::OnRefreshTokenResponse( |
| 95 const std::string& access_token, | 91 const std::string& access_token, |
| 96 int expires_in_seconds) { | 92 int expires_in_seconds) { |
| 97 // We never request a refresh token, so this call is not expected. | 93 // We never request a refresh token, so this call is not expected. |
| 98 NOTREACHED(); | 94 NOTREACHED(); |
| 99 } | 95 } |
| 100 | 96 |
| 101 void HostStarter::OnGetUserEmailResponse(const std::string& user_email) { | 97 void HostStarter::OnGetUserInfoResponse(const std::string& user_email) { |
| 102 if (!main_task_runner_->BelongsToCurrentThread()) { | 98 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 103 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 99 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 104 &HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email)); | 100 &HostStarter::OnGetUserInfoResponse, weak_ptr_, user_email)); |
| 105 return; | 101 return; |
| 106 } | 102 } |
| 107 user_email_ = user_email; | 103 user_email_ = user_email; |
| 108 // Register the host. | 104 // Register the host. |
| 109 host_id_ = base::GenerateGUID(); | 105 host_id_ = base::GenerateGUID(); |
| 110 key_pair_.Generate(); | 106 key_pair_.Generate(); |
| 111 service_client_->RegisterHost( | 107 service_client_->RegisterHost( |
| 112 host_id_, host_name_, key_pair_.GetPublicKey(), access_token_, this); | 108 host_id_, host_name_, key_pair_.GetPublicKey(), access_token_, this); |
| 113 } | 109 } |
| 114 | 110 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 158 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 163 &HostStarter::OnNetworkError, weak_ptr_, response_code)); | 159 &HostStarter::OnNetworkError, weak_ptr_, response_code)); |
| 164 return; | 160 return; |
| 165 } | 161 } |
| 166 CompletionCallback cb = on_done_; | 162 CompletionCallback cb = on_done_; |
| 167 on_done_.Reset(); | 163 on_done_.Reset(); |
| 168 cb.Run(NETWORK_ERROR); | 164 cb.Run(NETWORK_ERROR); |
| 169 } | 165 } |
| 170 | 166 |
| 171 } // namespace remoting | 167 } // namespace remoting |
| OLD | NEW |