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

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"
11 #include "remoting/host/setup/oauth_helper.h" 11 #include "remoting/host/setup/oauth_helper.h"
12 12
13 namespace { 13 namespace {
14 14
15 void AppendByte(std::string& s, uint8 byte) { 15 void AppendByte(std::string& s, uint8 byte) {
16 const char alphabet[] = "0123456789abcdef"; 16 const char alphabet[] = "0123456789abcdef";
17 s.push_back(alphabet[byte / 16]); 17 s.push_back(alphabet[byte / 16]);
18 s.push_back(alphabet[byte & 15]); 18 s.push_back(alphabet[byte & 15]);
19 } 19 }
20 20
21 std::string MakeHostId() { 21 std::string MakeHostId() {
Sergey Ulanov 2012/10/15 23:44:26 I think I already asked about it in a previous CL:
simonmorris 2012/10/16 17:23:03 I'll make such a change in a separate CL: it doesn
22 static const int random_byte_num = 16; 22 static const int random_byte_num = 16;
23 static const unsigned int id_len = 36; 23 static const unsigned int id_len = 36;
24 scoped_array<uint8> random_bytes(new uint8[random_byte_num]); 24 scoped_array<uint8> random_bytes(new uint8[random_byte_num]);
25 crypto::RandBytes(&random_bytes[0], random_byte_num); 25 crypto::RandBytes(&random_bytes[0], random_byte_num);
26 std::string id; 26 std::string id;
27 id.reserve(id_len); 27 id.reserve(id_len);
28 int byte_count = 0; 28 int byte_count = 0;
29 for (int i = 0; i < 4; i++) { 29 for (int i = 0; i < 4; i++) {
30 AppendByte(id, random_bytes[byte_count++]); 30 AppendByte(id, random_bytes[byte_count++]);
31 } 31 }
(...skipping 54 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,
Sergey Ulanov 2012/10/15 23:44:26 nit: One argument per line please (http://dev.chro
simonmorris 2012/10/16 17:23:03 Done.
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;
Sergey Ulanov 2012/10/15 23:44:26 Instead of passing on_done_runner here it would be
simonmorris 2012/10/16 17:23:03 Done.
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;
Sergey Ulanov 2012/10/15 23:44:26 Here and in all other callback methods: please add
simonmorris 2012/10/16 17:23:03 Many of the other callback methods are called from
120 access_token_ = access_token; 121 access_token_ = access_token;
121 // Get the email corresponding to the access token. 122 // Get the email corresponding to the access token.
122 user_email_fetcher_->GetUserEmail(access_token_, this); 123 user_email_fetcher_->GetUserEmail(access_token_, this);
123 } 124 }
124 125
125 void HostStarter::OnGetUserEmailResponse(const std::string& user_email) { 126 void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
126 user_email_ = user_email; 127 user_email_ = user_email;
127 // Register the host. 128 // Register the host.
128 host_id_ = MakeHostId(); 129 host_id_ = MakeHostId();
129 key_pair_.Generate(); 130 key_pair_.Generate();
(...skipping 11 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;
Sergey Ulanov 2012/10/15 23:44:26 This method is called on the thread that daemon co
simonmorris 2012/10/16 17:23:03 Done.
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