Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: remoting/host/setup/host_starter.cc

Issue 11090063: [Chromoting] Add a simple Windows app that registers and starts a host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 new remoting::GaiaUserEmailFetcher(url_request_context_getter)); 86 new remoting::GaiaUserEmailFetcher(url_request_context_getter));
87 scoped_ptr<remoting::ServiceClient> service_client( 87 scoped_ptr<remoting::ServiceClient> service_client(
88 new remoting::ServiceClient(url_request_context_getter)); 88 new remoting::ServiceClient(url_request_context_getter));
89 scoped_ptr<remoting::DaemonController> daemon_controller( 89 scoped_ptr<remoting::DaemonController> daemon_controller(
90 remoting::DaemonController::Create()); 90 remoting::DaemonController::Create());
91 return scoped_ptr<HostStarter>( 91 return scoped_ptr<HostStarter>(
92 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(), 92 new HostStarter(oauth_client.Pass(), user_email_fetcher.Pass(),
93 service_client.Pass(), daemon_controller.Pass())); 93 service_client.Pass(), daemon_controller.Pass()));
94 } 94 }
95 95
96 void HostStarter::StartHost(const std::string& host_name, 96 void HostStarter::StartHost(
97 const std::string& host_pin, 97 const std::string& host_name, const std::string& host_pin,
98 bool consent_to_data_collection, 98 bool consent_to_data_collection, const std::string& auth_code,
99 const std::string& auth_code, 99 CompletionCallback on_done,
100 CompletionCallback on_done) { 100 scoped_refptr<base::SingleThreadTaskRunner> on_done_runner) {
101 if (in_progress_) { 101 if (in_progress_) {
102 on_done.Run(START_IN_PROGRESS); 102 on_done.Run(START_IN_PROGRESS);
103 return; 103 return;
104 } 104 }
105 in_progress_ = true; 105 in_progress_ = true;
106 host_name_ = host_name; 106 host_name_ = host_name;
107 host_pin_ = host_pin; 107 host_pin_ = host_pin;
108 consent_to_data_collection_ = consent_to_data_collection; 108 consent_to_data_collection_ = consent_to_data_collection;
109 on_done_ = on_done; 109 on_done_ = on_done;
110 on_done_runner_ = on_done_runner;
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 21 matching lines...) Expand all
141 config->SetString("host_name", host_name_); 142 config->SetString("host_name", host_name_);
142 config->SetString("private_key", key_pair_.GetAsString()); 143 config->SetString("private_key", key_pair_.GetAsString());
143 config->SetString("host_secret_hash", host_secret_hash); 144 config->SetString("host_secret_hash", host_secret_hash);
144 daemon_controller_->SetConfigAndStart( 145 daemon_controller_->SetConfigAndStart(
145 config.Pass(), consent_to_data_collection_, 146 config.Pass(), consent_to_data_collection_,
146 base::Bind(&HostStarter::OnHostStarted, 147 base::Bind(&HostStarter::OnHostStarted,
147 base::Unretained(this))); 148 base::Unretained(this)));
148 } 149 }
149 150
150 void HostStarter::OnHostStarted(DaemonController::AsyncResult result) { 151 void HostStarter::OnHostStarted(DaemonController::AsyncResult result) {
151 on_done_.Run( 152 Result done_result = START_ERROR;
152 (result == DaemonController::RESULT_OK) ? START_COMPLETE : START_ERROR); 153 if (result == DaemonController::RESULT_OK)
154 done_result = START_COMPLETE;
155 on_done_runner_->PostTask(FROM_HERE, base::Bind(on_done_, done_result));
153 // TODO(simonmorris): Unregister the host if we didn't start it. 156 // TODO(simonmorris): Unregister the host if we didn't start it.
154 in_progress_ = false; 157 in_progress_ = false;
155 } 158 }
156 159
157 void HostStarter::OnOAuthError() { 160 void HostStarter::OnOAuthError() {
158 on_done_.Run(OAUTH_ERROR); 161 on_done_.Run(OAUTH_ERROR);
159 in_progress_ = false; 162 in_progress_ = false;
160 } 163 }
161 164
162 void HostStarter::OnNetworkError(int response_code) { 165 void HostStarter::OnNetworkError(int response_code) {
163 on_done_.Run(NETWORK_ERROR); 166 on_done_.Run(NETWORK_ERROR);
164 in_progress_ = false; 167 in_progress_ = false;
165 } 168 }
166 169
167 void HostStarter::OnRefreshTokenResponse( 170 void HostStarter::OnRefreshTokenResponse(
168 const std::string& access_token, 171 const std::string& access_token,
169 int expires_in_seconds) { 172 int expires_in_seconds) {
170 NOTREACHED(); 173 NOTREACHED();
171 on_done_.Run(OAUTH_ERROR); 174 on_done_.Run(OAUTH_ERROR);
172 in_progress_ = false; 175 in_progress_ = false;
173 } 176 }
174 177
175 } // namespace remoting 178 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698