| 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/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "crypto/random.h" | 9 #include "crypto/random.h" |
| 10 #include "google_apis/google_api_keys.h" | 10 #include "google_apis/google_api_keys.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 scoped_ptr<remoting::ServiceClient> service_client, | 63 scoped_ptr<remoting::ServiceClient> service_client, |
| 64 scoped_ptr<remoting::DaemonController> daemon_controller) | 64 scoped_ptr<remoting::DaemonController> daemon_controller) |
| 65 : oauth_client_(oauth_client.Pass()), | 65 : oauth_client_(oauth_client.Pass()), |
| 66 user_email_fetcher_(user_email_fetcher.Pass()), | 66 user_email_fetcher_(user_email_fetcher.Pass()), |
| 67 service_client_(service_client.Pass()), | 67 service_client_(service_client.Pass()), |
| 68 daemon_controller_(daemon_controller.Pass()), | 68 daemon_controller_(daemon_controller.Pass()), |
| 69 in_progress_(false), | 69 in_progress_(false), |
| 70 consent_to_data_collection_(false), | 70 consent_to_data_collection_(false), |
| 71 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 71 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 72 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { | 72 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
| 73 oauth_client_info_.client_id = | |
| 74 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING); | |
| 75 oauth_client_info_.client_secret = | |
| 76 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING); | |
| 77 oauth_client_info_.redirect_uri = GetOauthRedirectUrl(); | |
| 78 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 73 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 79 } | 74 } |
| 80 | 75 |
| 81 HostStarter::~HostStarter() { | 76 HostStarter::~HostStarter() { |
| 82 } | 77 } |
| 83 | 78 |
| 84 scoped_ptr<HostStarter> HostStarter::Create( | 79 scoped_ptr<HostStarter> HostStarter::Create( |
| 85 net::URLRequestContextGetter* url_request_context_getter) { | 80 net::URLRequestContextGetter* url_request_context_getter) { |
| 86 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( | 81 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( |
| 87 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, | 82 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, |
| 88 url_request_context_getter)); | 83 url_request_context_getter)); |
| 89 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher( | 84 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher( |
| 90 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); | 85 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); |
| 91 scoped_ptr<remoting::ServiceClient> service_client( | 86 scoped_ptr<remoting::ServiceClient> service_client( |
| 92 new remoting::ServiceClient(url_request_context_getter)); | 87 new remoting::ServiceClient(url_request_context_getter)); |
| 93 scoped_ptr<remoting::DaemonController> daemon_controller( | 88 scoped_ptr<remoting::DaemonController> daemon_controller( |
| 94 remoting::DaemonController::Create()); | 89 remoting::DaemonController::Create()); |
| 95 return scoped_ptr<HostStarter>( | 90 return scoped_ptr<HostStarter>( |
| 96 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), | 91 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), |
| 97 service_client.Pass(), daemon_controller.Pass())); | 92 service_client.Pass(), daemon_controller.Pass())); |
| 98 } | 93 } |
| 99 | 94 |
| 100 void HostStarter::StartHost( | 95 void HostStarter::StartHost( |
| 101 const std::string& host_name, | 96 const std::string& host_name, |
| 102 const std::string& host_pin, | 97 const std::string& host_pin, |
| 103 bool consent_to_data_collection, | 98 bool consent_to_data_collection, |
| 104 const std::string& auth_code, | 99 const std::string& auth_code, |
| 100 const std::string& redirect_url, |
| 105 CompletionCallback on_done) { | 101 CompletionCallback on_done) { |
| 106 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 102 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 107 if (in_progress_) { | 103 if (in_progress_) { |
| 108 on_done.Run(START_IN_PROGRESS); | 104 on_done.Run(START_IN_PROGRESS); |
| 109 return; | 105 return; |
| 110 } | 106 } |
| 111 in_progress_ = true; | 107 in_progress_ = true; |
| 112 host_name_ = host_name; | 108 host_name_ = host_name; |
| 113 host_pin_ = host_pin; | 109 host_pin_ = host_pin; |
| 114 consent_to_data_collection_ = consent_to_data_collection; | 110 consent_to_data_collection_ = consent_to_data_collection; |
| 115 on_done_ = on_done; | 111 on_done_ = on_done; |
| 112 oauth_client_info_.client_id = |
| 113 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING); |
| 114 oauth_client_info_.client_secret = |
| 115 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING); |
| 116 oauth_client_info_.redirect_uri = redirect_url; |
| 116 // Map the authorization code to refresh and access tokens. | 117 // Map the authorization code to refresh and access tokens. |
| 117 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, auth_code, | 118 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, auth_code, |
| 118 kMaxGetTokensRetries, this); | 119 kMaxGetTokensRetries, this); |
| 119 } | 120 } |
| 120 | 121 |
| 121 void HostStarter::OnGetTokensResponse( | 122 void HostStarter::OnGetTokensResponse( |
| 122 const std::string& refresh_token, | 123 const std::string& refresh_token, |
| 123 const std::string& access_token, | 124 const std::string& access_token, |
| 124 int expires_in_seconds) { | 125 int expires_in_seconds) { |
| 125 if (!main_task_runner_->BelongsToCurrentThread()) { | 126 if (!main_task_runner_->BelongsToCurrentThread()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 211 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 211 &HostStarter::OnRefreshTokenResponse, weak_ptr_, | 212 &HostStarter::OnRefreshTokenResponse, weak_ptr_, |
| 212 access_token, expires_in_seconds)); | 213 access_token, expires_in_seconds)); |
| 213 return; | 214 return; |
| 214 } | 215 } |
| 215 on_done_.Run(OAUTH_ERROR); | 216 on_done_.Run(OAUTH_ERROR); |
| 216 in_progress_ = false; | 217 in_progress_ = false; |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace remoting | 220 } // namespace remoting |
| OLD | NEW |