Chromium Code Reviews| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "crypto/random.h" | 8 #include "crypto/random.h" |
| 9 #include "google_apis/google_api_keys.h" | 9 #include "google_apis/google_api_keys.h" |
| 10 #include "remoting/host/pin_hash.h" | 10 #include "remoting/host/pin_hash.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, | 60 scoped_ptr<gaia::GaiaOAuthClient> oauth_client, |
| 61 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher, | 61 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher, |
| 62 scoped_ptr<remoting::ServiceClient> service_client, | 62 scoped_ptr<remoting::ServiceClient> service_client, |
| 63 scoped_ptr<remoting::DaemonController> daemon_controller) | 63 scoped_ptr<remoting::DaemonController> daemon_controller) |
| 64 : oauth_client_(oauth_client.Pass()), | 64 : oauth_client_(oauth_client.Pass()), |
| 65 user_email_fetcher_(user_email_fetcher.Pass()), | 65 user_email_fetcher_(user_email_fetcher.Pass()), |
| 66 service_client_(service_client.Pass()), | 66 service_client_(service_client.Pass()), |
| 67 daemon_controller_(daemon_controller.Pass()), | 67 daemon_controller_(daemon_controller.Pass()), |
| 68 in_progress_(false), | 68 in_progress_(false), |
| 69 consent_to_data_collection_(false) { | 69 consent_to_data_collection_(false) { |
| 70 oauth_client_info_.client_id = | |
| 71 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING); | |
| 72 oauth_client_info_.client_secret = | |
| 73 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING); | |
| 74 oauth_client_info_.redirect_uri = GetOauthRedirectUrl(); | |
| 75 } | 70 } |
| 76 | 71 |
| 77 HostStarter::~HostStarter() { | 72 HostStarter::~HostStarter() { |
| 78 } | 73 } |
| 79 | 74 |
| 80 scoped_ptr<HostStarter> HostStarter::Create( | 75 scoped_ptr<HostStarter> HostStarter::Create( |
| 81 net::URLRequestContextGetter* url_request_context_getter) { | 76 net::URLRequestContextGetter* url_request_context_getter) { |
| 82 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( | 77 scoped_ptr<gaia::GaiaOAuthClient> oauth_client( |
| 83 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, | 78 new gaia::GaiaOAuthClient(gaia::kGaiaOAuth2Url, |
| 84 url_request_context_getter)); | 79 url_request_context_getter)); |
| 85 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher( | 80 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher( |
| 86 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); | 81 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); |
| 87 scoped_ptr<remoting::ServiceClient> service_client( | 82 scoped_ptr<remoting::ServiceClient> service_client( |
| 88 new remoting::ServiceClient(url_request_context_getter)); | 83 new remoting::ServiceClient(url_request_context_getter)); |
| 89 scoped_ptr<remoting::DaemonController> daemon_controller( | 84 scoped_ptr<remoting::DaemonController> daemon_controller( |
| 90 remoting::DaemonController::Create()); | 85 remoting::DaemonController::Create()); |
| 91 return scoped_ptr<HostStarter>( | 86 return scoped_ptr<HostStarter>( |
| 92 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), | 87 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), |
| 93 service_client.Pass(), daemon_controller.Pass())); | 88 service_client.Pass(), daemon_controller.Pass())); |
| 94 } | 89 } |
| 95 | 90 |
| 96 void HostStarter::StartHost(const std::string& host_name, | 91 void HostStarter::StartHost(const std::string& host_name, |
| 97 const std::string& host_pin, | 92 const std::string& host_pin, |
| 98 bool consent_to_data_collection, | 93 bool consent_to_data_collection, |
| 99 const std::string& auth_code, | 94 const std::string& auth_code, |
| 95 const std::string& redirect_url, | |
| 100 CompletionCallback on_done) { | 96 CompletionCallback on_done) { |
| 101 if (in_progress_) { | 97 if (in_progress_) { |
| 102 on_done.Run(START_IN_PROGRESS); | 98 on_done.Run(START_IN_PROGRESS); |
| 103 return; | 99 return; |
| 104 } | 100 } |
| 105 in_progress_ = true; | 101 in_progress_ = true; |
| 106 host_name_ = host_name; | 102 host_name_ = host_name; |
| 107 host_pin_ = host_pin; | 103 host_pin_ = host_pin; |
| 108 consent_to_data_collection_ = consent_to_data_collection; | 104 consent_to_data_collection_ = consent_to_data_collection; |
| 109 on_done_ = on_done; | 105 on_done_ = on_done; |
| 106 oauth_client_info_.client_id = | |
| 107 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING); | |
|
Sergey Ulanov
2012/10/17 23:41:36
nit: 4-space indent here and below.
simonmorris
2012/10/18 00:10:09
Done.
| |
| 108 oauth_client_info_.client_secret = | |
| 109 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING); | |
| 110 oauth_client_info_.redirect_uri = redirect_url; | |
| 110 // Map the authorization code to refresh and access tokens. | 111 // Map the authorization code to refresh and access tokens. |
| 111 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, auth_code, | 112 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, auth_code, |
| 112 kMaxGetTokensRetries, this); | 113 kMaxGetTokensRetries, this); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void HostStarter::OnGetTokensResponse( | 116 void HostStarter::OnGetTokensResponse( |
| 116 const std::string& refresh_token, | 117 const std::string& refresh_token, |
| 117 const std::string& access_token, | 118 const std::string& access_token, |
| 118 int expires_in_seconds) { | 119 int expires_in_seconds) { |
| 119 refresh_token_ = refresh_token; | 120 refresh_token_ = refresh_token; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 | 167 |
| 167 void HostStarter::OnRefreshTokenResponse( | 168 void HostStarter::OnRefreshTokenResponse( |
| 168 const std::string& access_token, | 169 const std::string& access_token, |
| 169 int expires_in_seconds) { | 170 int expires_in_seconds) { |
| 170 NOTREACHED(); | 171 NOTREACHED(); |
| 171 on_done_.Run(OAUTH_ERROR); | 172 on_done_.Run(OAUTH_ERROR); |
| 172 in_progress_ = false; | 173 in_progress_ = false; |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace remoting | 176 } // namespace remoting |
| OLD | NEW |