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

Unified 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: Fix non-standard resource header file. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/setup/host_starter.h ('k') | remoting/host/setup/pin_validator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/setup/host_starter.cc
diff --git a/remoting/host/setup/host_starter.cc b/remoting/host/setup/host_starter.cc
index 31847fe8eb069b7a70f15cce33e4f5bab139e197..ff7deb94f53d6aed0591424c4c711256c812a1ad 100644
--- a/remoting/host/setup/host_starter.cc
+++ b/remoting/host/setup/host_starter.cc
@@ -4,6 +4,7 @@
#include "remoting/host/setup/host_starter.h"
+#include "base/thread_task_runner_handle.h"
#include "base/values.h"
#include "crypto/random.h"
#include "google_apis/google_api_keys.h"
@@ -66,12 +67,15 @@ HostStarter::HostStarter(
service_client_(service_client.Pass()),
daemon_controller_(daemon_controller.Pass()),
in_progress_(false),
- consent_to_data_collection_(false) {
+ consent_to_data_collection_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ weak_ptr_(weak_ptr_factory_.GetWeakPtr()) {
oauth_client_info_.client_id =
google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING);
oauth_client_info_.client_secret =
google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING);
oauth_client_info_.redirect_uri = GetOauthRedirectUrl();
+ main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
}
HostStarter::~HostStarter() {
@@ -93,11 +97,13 @@ scoped_ptr<HostStarter> HostStarter::Create(
service_client.Pass(), daemon_controller.Pass()));
}
-void HostStarter::StartHost(const std::string& host_name,
- const std::string& host_pin,
- bool consent_to_data_collection,
- const std::string& auth_code,
- CompletionCallback on_done) {
+void HostStarter::StartHost(
+ const std::string& host_name,
+ const std::string& host_pin,
+ bool consent_to_data_collection,
+ const std::string& auth_code,
+ CompletionCallback on_done) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
if (in_progress_) {
on_done.Run(START_IN_PROGRESS);
return;
@@ -116,6 +122,12 @@ void HostStarter::OnGetTokensResponse(
const std::string& refresh_token,
const std::string& access_token,
int expires_in_seconds) {
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnGetTokensResponse, weak_ptr_,
+ refresh_token, access_token, expires_in_seconds));
+ return;
+ }
refresh_token_ = refresh_token;
access_token_ = access_token;
// Get the email corresponding to the access token.
@@ -123,6 +135,11 @@ void HostStarter::OnGetTokensResponse(
}
void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnGetUserEmailResponse, weak_ptr_, user_email));
+ return;
+ }
user_email_ = user_email;
// Register the host.
host_id_ = MakeHostId();
@@ -132,6 +149,11 @@ void HostStarter::OnGetUserEmailResponse(const std::string& user_email) {
}
void HostStarter::OnHostRegistered() {
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnHostRegistered, weak_ptr_));
+ return;
+ }
// Start the host.
std::string host_secret_hash = remoting::MakeHostPinHash(host_id_, host_pin_);
scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue());
@@ -143,23 +165,39 @@ void HostStarter::OnHostRegistered() {
config->SetString("host_secret_hash", host_secret_hash);
daemon_controller_->SetConfigAndStart(
config.Pass(), consent_to_data_collection_,
- base::Bind(&HostStarter::OnHostStarted,
- base::Unretained(this)));
+ base::Bind(&HostStarter::OnHostStarted, base::Unretained(this)));
}
void HostStarter::OnHostStarted(DaemonController::AsyncResult result) {
- on_done_.Run(
- (result == DaemonController::RESULT_OK) ? START_COMPLETE : START_ERROR);
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnHostStarted, weak_ptr_, result));
+ return;
+ }
+ Result done_result = START_ERROR;
+ if (result == DaemonController::RESULT_OK)
+ done_result = START_COMPLETE;
+ on_done_.Run(done_result);
// TODO(simonmorris): Unregister the host if we didn't start it.
in_progress_ = false;
}
void HostStarter::OnOAuthError() {
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnOAuthError, weak_ptr_));
+ return;
+ }
on_done_.Run(OAUTH_ERROR);
in_progress_ = false;
}
void HostStarter::OnNetworkError(int response_code) {
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnNetworkError, weak_ptr_, response_code));
+ return;
+ }
on_done_.Run(NETWORK_ERROR);
in_progress_ = false;
}
@@ -168,6 +206,12 @@ void HostStarter::OnRefreshTokenResponse(
const std::string& access_token,
int expires_in_seconds) {
NOTREACHED();
+ if (!main_task_runner_->BelongsToCurrentThread()) {
+ main_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &HostStarter::OnRefreshTokenResponse, weak_ptr_,
+ access_token, expires_in_seconds));
+ return;
+ }
on_done_.Run(OAUTH_ERROR);
in_progress_ = false;
}
« no previous file with comments | « remoting/host/setup/host_starter.h ('k') | remoting/host/setup/pin_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698