| 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 #ifndef REMOTING_HOST_HOST_STARTER | 5 #ifndef REMOTING_HOST_HOST_STARTER |
| 6 #define REMOTING_HOST_HOST_STARTER | 6 #define REMOTING_HOST_HOST_STARTER |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "google_apis/gaia/gaia_oauth_client.h" | 11 #include "google_apis/gaia/gaia_oauth_client.h" |
| 12 #include "remoting/host/gaia_user_email_fetcher.h" | |
| 13 #include "remoting/host/host_key_pair.h" | 12 #include "remoting/host/host_key_pair.h" |
| 14 #include "remoting/host/service_client.h" | 13 #include "remoting/host/service_client.h" |
| 15 #include "remoting/host/setup/daemon_controller.h" | 14 #include "remoting/host/setup/daemon_controller.h" |
| 16 #include "remoting/host/url_request_context.h" | 15 #include "remoting/host/url_request_context.h" |
| 17 | 16 |
| 18 namespace remoting { | 17 namespace remoting { |
| 19 | 18 |
| 20 // A helper class that registers and starts a host. | 19 // A helper class that registers and starts a host. |
| 21 class HostStarter : public gaia::GaiaOAuthClient::Delegate, | 20 class HostStarter : public gaia::GaiaOAuthClient::Delegate, |
| 22 public remoting::GaiaUserEmailFetcher::Delegate, | |
| 23 public remoting::ServiceClient::Delegate { | 21 public remoting::ServiceClient::Delegate { |
| 24 public: | 22 public: |
| 25 enum Result { | 23 enum Result { |
| 26 START_COMPLETE, | 24 START_COMPLETE, |
| 27 NETWORK_ERROR, | 25 NETWORK_ERROR, |
| 28 OAUTH_ERROR, | 26 OAUTH_ERROR, |
| 29 START_ERROR, | 27 START_ERROR, |
| 30 }; | 28 }; |
| 31 | 29 |
| 32 typedef base::Callback<void(Result)> CompletionCallback; | 30 typedef base::Callback<void(Result)> CompletionCallback; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 46 const std::string& auth_code, | 44 const std::string& auth_code, |
| 47 const std::string& redirect_url, | 45 const std::string& redirect_url, |
| 48 CompletionCallback on_done); | 46 CompletionCallback on_done); |
| 49 | 47 |
| 50 // gaia::GaiaOAuthClient::Delegate | 48 // gaia::GaiaOAuthClient::Delegate |
| 51 virtual void OnGetTokensResponse(const std::string& refresh_token, | 49 virtual void OnGetTokensResponse(const std::string& refresh_token, |
| 52 const std::string& access_token, | 50 const std::string& access_token, |
| 53 int expires_in_seconds) OVERRIDE; | 51 int expires_in_seconds) OVERRIDE; |
| 54 virtual void OnRefreshTokenResponse(const std::string& access_token, | 52 virtual void OnRefreshTokenResponse(const std::string& access_token, |
| 55 int expires_in_seconds) OVERRIDE; | 53 int expires_in_seconds) OVERRIDE; |
| 56 | 54 virtual void OnGetUserInfoResponse(const std::string& user_email) OVERRIDE; |
| 57 // remoting::GaiaUserEmailFetcher::Delegate | |
| 58 virtual void OnGetUserEmailResponse(const std::string& user_email) OVERRIDE; | |
| 59 | 55 |
| 60 // remoting::ServiceClient::Delegate | 56 // remoting::ServiceClient::Delegate |
| 61 virtual void OnHostRegistered() OVERRIDE; | 57 virtual void OnHostRegistered() OVERRIDE; |
| 62 | 58 |
| 63 // TODO(sergeyu): Following methods are members of all three delegate | 59 // TODO(sergeyu): Following methods are members of all three delegate |
| 64 // interfaces implemented in this class. Fix ServiceClient and | 60 // interfaces implemented in this class. Fix ServiceClient and |
| 65 // GaiaUserEmailFetcher so that Delegate interfaces do not overlap (ideally | 61 // GaiaUserEmailFetcher so that Delegate interfaces do not overlap (ideally |
| 66 // they should be changed to use Callback<>). | 62 // they should be changed to use Callback<>). |
| 67 virtual void OnOAuthError() OVERRIDE; | 63 virtual void OnOAuthError() OVERRIDE; |
| 68 virtual void OnNetworkError(int response_code) OVERRIDE; | 64 virtual void OnNetworkError(int response_code) OVERRIDE; |
| 69 | 65 |
| 70 private: | 66 private: |
| 71 HostStarter(scoped_ptr<gaia::GaiaOAuthClient> oauth_client, | 67 HostStarter(scoped_ptr<gaia::GaiaOAuthClient> oauth_client, |
| 72 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher, | |
| 73 scoped_ptr<remoting::ServiceClient> service_client, | 68 scoped_ptr<remoting::ServiceClient> service_client, |
| 74 scoped_ptr<remoting::DaemonController> daemon_controller); | 69 scoped_ptr<remoting::DaemonController> daemon_controller); |
| 75 | 70 |
| 76 void OnHostStarted(DaemonController::AsyncResult result); | 71 void OnHostStarted(DaemonController::AsyncResult result); |
| 77 | 72 |
| 78 scoped_ptr<gaia::GaiaOAuthClient> oauth_client_; | 73 scoped_ptr<gaia::GaiaOAuthClient> oauth_client_; |
| 79 scoped_ptr<remoting::GaiaUserEmailFetcher> user_email_fetcher_; | |
| 80 scoped_ptr<remoting::ServiceClient> service_client_; | 74 scoped_ptr<remoting::ServiceClient> service_client_; |
| 81 scoped_ptr<remoting::DaemonController> daemon_controller_; | 75 scoped_ptr<remoting::DaemonController> daemon_controller_; |
| 82 gaia::OAuthClientInfo oauth_client_info_; | 76 gaia::OAuthClientInfo oauth_client_info_; |
| 83 std::string host_name_; | 77 std::string host_name_; |
| 84 std::string host_pin_; | 78 std::string host_pin_; |
| 85 bool consent_to_data_collection_; | 79 bool consent_to_data_collection_; |
| 86 CompletionCallback on_done_; | 80 CompletionCallback on_done_; |
| 87 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 81 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 88 std::string refresh_token_; | 82 std::string refresh_token_; |
| 89 std::string access_token_; | 83 std::string access_token_; |
| 90 std::string user_email_; | 84 std::string user_email_; |
| 91 remoting::HostKeyPair key_pair_; | 85 remoting::HostKeyPair key_pair_; |
| 92 std::string host_id_; | 86 std::string host_id_; |
| 93 | 87 |
| 94 base::WeakPtrFactory<HostStarter> weak_ptr_factory_; | 88 base::WeakPtrFactory<HostStarter> weak_ptr_factory_; |
| 95 base::WeakPtr<HostStarter> weak_ptr_; | 89 base::WeakPtr<HostStarter> weak_ptr_; |
| 96 | 90 |
| 97 DISALLOW_COPY_AND_ASSIGN(HostStarter); | 91 DISALLOW_COPY_AND_ASSIGN(HostStarter); |
| 98 }; | 92 }; |
| 99 | 93 |
| 100 } // namespace remoting | 94 } // namespace remoting |
| 101 | 95 |
| 102 #endif // REMOTING_HOST_HOST_STARTER | 96 #endif // REMOTING_HOST_HOST_STARTER |
| OLD | NEW |