| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 8 #include "base/guid.h" | 9 #include "base/guid.h" |
| 9 #include "base/location.h" | 10 #include "base/location.h" |
| 10 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "google_apis/google_api_keys.h" | 13 #include "google_apis/google_api_keys.h" |
| 13 #include "remoting/host/pin_hash.h" | 14 #include "remoting/host/pin_hash.h" |
| 14 #include "remoting/host/setup/oauth_helper.h" | 15 #include "remoting/host/setup/oauth_helper.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 const int kMaxGetTokensRetries = 3; | 18 const int kMaxGetTokensRetries = 3; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (!main_task_runner_->BelongsToCurrentThread()) { | 178 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 178 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 179 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 179 &HostStarter::OnHostStarted, weak_ptr_, result)); | 180 &HostStarter::OnHostStarted, weak_ptr_, result)); |
| 180 return; | 181 return; |
| 181 } | 182 } |
| 182 if (result != DaemonController::RESULT_OK) { | 183 if (result != DaemonController::RESULT_OK) { |
| 183 unregistering_host_ = true; | 184 unregistering_host_ = true; |
| 184 service_client_->UnregisterHost(host_id_, access_token_, this); | 185 service_client_->UnregisterHost(host_id_, access_token_, this); |
| 185 return; | 186 return; |
| 186 } | 187 } |
| 187 CompletionCallback cb = on_done_; | 188 base::ResetAndReturn(&on_done_).Run(START_COMPLETE); |
| 188 on_done_.Reset(); | |
| 189 cb.Run(START_COMPLETE); | |
| 190 } | 189 } |
| 191 | 190 |
| 192 void HostStarter::OnOAuthError() { | 191 void HostStarter::OnOAuthError() { |
| 193 if (!main_task_runner_->BelongsToCurrentThread()) { | 192 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 194 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 193 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 195 &HostStarter::OnOAuthError, weak_ptr_)); | 194 &HostStarter::OnOAuthError, weak_ptr_)); |
| 196 return; | 195 return; |
| 197 } | 196 } |
| 198 CompletionCallback cb = on_done_; | |
| 199 on_done_.Reset(); | |
| 200 if (unregistering_host_) { | 197 if (unregistering_host_) { |
| 201 LOG(ERROR) << "OAuth error occurred when unregistering host."; | 198 LOG(ERROR) << "OAuth error occurred when unregistering host."; |
| 202 cb.Run(START_ERROR); | |
| 203 } else { | |
| 204 cb.Run(OAUTH_ERROR); | |
| 205 } | 199 } |
| 200 |
| 201 base::ResetAndReturn(&on_done_) |
| 202 .Run(unregistering_host_ ? START_ERROR : OAUTH_ERROR); |
| 206 } | 203 } |
| 207 | 204 |
| 208 void HostStarter::OnNetworkError(int response_code) { | 205 void HostStarter::OnNetworkError(int response_code) { |
| 209 if (!main_task_runner_->BelongsToCurrentThread()) { | 206 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 210 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 207 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 211 &HostStarter::OnNetworkError, weak_ptr_, response_code)); | 208 &HostStarter::OnNetworkError, weak_ptr_, response_code)); |
| 212 return; | 209 return; |
| 213 } | 210 } |
| 214 CompletionCallback cb = on_done_; | |
| 215 on_done_.Reset(); | |
| 216 if (unregistering_host_) { | 211 if (unregistering_host_) { |
| 217 LOG(ERROR) << "Network error occurred when unregistering host."; | 212 LOG(ERROR) << "Network error occurred when unregistering host."; |
| 218 cb.Run(START_ERROR); | |
| 219 } else { | |
| 220 cb.Run(NETWORK_ERROR); | |
| 221 } | 213 } |
| 214 |
| 215 base::ResetAndReturn(&on_done_) |
| 216 .Run(unregistering_host_ ? START_ERROR : NETWORK_ERROR); |
| 222 } | 217 } |
| 223 | 218 |
| 224 void HostStarter::OnHostUnregistered() { | 219 void HostStarter::OnHostUnregistered() { |
| 225 if (!main_task_runner_->BelongsToCurrentThread()) { | 220 if (!main_task_runner_->BelongsToCurrentThread()) { |
| 226 main_task_runner_->PostTask(FROM_HERE, base::Bind( | 221 main_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 227 &HostStarter::OnHostUnregistered, weak_ptr_)); | 222 &HostStarter::OnHostUnregistered, weak_ptr_)); |
| 228 return; | 223 return; |
| 229 } | 224 } |
| 230 CompletionCallback cb = on_done_; | 225 base::ResetAndReturn(&on_done_).Run(START_ERROR); |
| 231 on_done_.Reset(); | |
| 232 cb.Run(START_ERROR); | |
| 233 } | 226 } |
| 234 | 227 |
| 235 } // namespace remoting | 228 } // namespace remoting |
| OLD | NEW |