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

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

Issue 22992002: Service account setup for headless Linux hosts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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/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"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // We never request a refresh token, so this call is not expected. 94 // We never request a refresh token, so this call is not expected.
95 NOTREACHED(); 95 NOTREACHED();
96 } 96 }
97 97
98 void HostStarter::OnGetUserEmailResponse(const std::string& user_email) { 98 void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
99 if (!main_task_runner_->BelongsToCurrentThread()) { 99 if (!main_task_runner_->BelongsToCurrentThread()) {
100 main_task_runner_->PostTask(FROM_HERE, base::Bind( 100 main_task_runner_->PostTask(FROM_HERE, base::Bind(
101 &HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email)); 101 &HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email));
102 return; 102 return;
103 } 103 }
104 user_email_ = user_email; 104
105 // Register the host. 105 if (host_id_.empty()) {
Sergey Ulanov 2013/08/13 23:33:38 Add a comment that this function is used for both
rmsousa 2013/08/14 02:13:12 Done.
106 host_id_ = base::GenerateGUID(); 106 // Register the host.
107 key_pair_ = RsaKeyPair::Generate(); 107 xmpp_login_ = user_email;
Sergey Ulanov 2013/08/13 23:33:38 I think it's better to set host_owner_ here and co
rmsousa 2013/08/14 02:13:12 Done.
108 service_client_->RegisterHost( 108 host_id_ = base::GenerateGUID();
109 host_id_, host_name_, key_pair_->GetPublicKey(), access_token_, this); 109 key_pair_ = RsaKeyPair::Generate();
110
111 std::string host_client_id;
112 host_client_id = google_apis::GetOAuth2ClientID(
113 google_apis::CLIENT_REMOTING_HOST);
114
115 service_client_->RegisterHost(
116 host_id_, host_name_, key_pair_->GetPublicKey(), host_client_id,
117 access_token_, this);
118 } else {
119 // Host is already registered, this response is for the service account.
120 // The previous value of xmpp_login is the host owner's email.
121 host_owner_ = xmpp_login_;
122 xmpp_login_ = user_email;
123 StartHostProcess();
124 }
110 } 125 }
111 126
112 void HostStarter::OnHostRegistered() { 127 void HostStarter::OnHostRegistered(const std::string& authorization_code) {
113 if (!main_task_runner_->BelongsToCurrentThread()) { 128 if (!main_task_runner_->BelongsToCurrentThread()) {
114 main_task_runner_->PostTask(FROM_HERE, base::Bind( 129 main_task_runner_->PostTask(FROM_HERE, base::Bind(
115 &HostStarter::OnHostRegistered, weak_ptr_)); 130 &HostStarter::OnHostRegistered, weak_ptr_, authorization_code));
116 return; 131 return;
117 } 132 }
133
134 if (authorization_code.empty()) {
135 // No service account code, start the host with the user's credentials.
136 StartHostProcess();
137 } else {
Sergey Ulanov 2013/08/13 23:33:38 add return in the case above and remove else. The
rmsousa 2013/08/14 02:13:12 Done.
138 // Received a service account authorization code, update oauth_client_info_
139 // to use the service account client keys, and get service account tokens.
140 oauth_client_info_.client_id =
141 google_apis::GetOAuth2ClientID(
142 google_apis::CLIENT_REMOTING_HOST);
143 oauth_client_info_.client_secret =
144 google_apis::GetOAuth2ClientSecret(
145 google_apis::CLIENT_REMOTING_HOST);
146 oauth_client_info_.redirect_uri = "oob";
147 oauth_client_->GetTokensFromAuthCode(
148 oauth_client_info_, authorization_code, kMaxGetTokensRetries, this);
149 }
150 }
151
152 void HostStarter::StartHostProcess() {
118 // Start the host. 153 // Start the host.
119 std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_); 154 std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_);
120 scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue()); 155 scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue());
121 config->SetString("xmpp_login", user_email_); 156 if (!host_owner_.empty()) {
Sergey Ulanov 2013/08/13 23:33:38 Can we always set host_owner, even when using user
rmsousa 2013/08/14 02:13:12 https://codereview.chromium.org/19796006/ uses the
157 config->SetString("host_owner", host_owner_);
158 }
159 config->SetString("xmpp_login", xmpp_login_);
122 config->SetString("oauth_refresh_token", refresh_token_); 160 config->SetString("oauth_refresh_token", refresh_token_);
123 config->SetString("host_id", host_id_); 161 config->SetString("host_id", host_id_);
124 config->SetString("host_name", host_name_); 162 config->SetString("host_name", host_name_);
125 config->SetString("private_key", key_pair_->ToString()); 163 config->SetString("private_key", key_pair_->ToString());
126 config->SetString("host_secret_hash", host_secret_hash); 164 config->SetString("host_secret_hash", host_secret_hash);
127 daemon_controller_->SetConfigAndStart( 165 daemon_controller_->SetConfigAndStart(
128 config.Pass(), consent_to_data_collection_, 166 config.Pass(), consent_to_data_collection_,
129 base::Bind(&HostStarter::OnHostStarted, base::Unretained(this))); 167 base::Bind(&HostStarter::OnHostStarted, base::Unretained(this)));
130 } 168 }
131 169
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 main_task_runner_->PostTask(FROM_HERE, base::Bind( 211 main_task_runner_->PostTask(FROM_HERE, base::Bind(
174 &HostStarter::OnHostUnregistered, weak_ptr_)); 212 &HostStarter::OnHostUnregistered, weak_ptr_));
175 return; 213 return;
176 } 214 }
177 CompletionCallback cb = on_done_; 215 CompletionCallback cb = on_done_;
178 on_done_.Reset(); 216 on_done_.Reset();
179 cb.Run(START_ERROR); 217 cb.Run(START_ERROR);
180 } 218 }
181 219
182 } // namespace remoting 220 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698