Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_CLIENT_CORE_SESSION_IDENTITY_SOURCE_H_ | |
| 6 #define BLIMP_CLIENT_CORE_SESSION_IDENTITY_SOURCE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 | |
| 14 #include "blimp/client/public/blimp_client_context_delegate.h" | |
| 15 #include "google_apis/gaia/identity_provider.h" | |
| 16 #include "google_apis/gaia/oauth2_token_service.h" | |
| 17 | |
| 18 namespace blimp { | |
| 19 namespace client { | |
| 20 | |
| 21 // IdentitySource handles OAuth2 token request and forward user sign in state | |
| 22 // change to Blimp with ProfileIdentityProvider. | |
| 23 class IdentitySource : public OAuth2TokenService::Consumer, | |
| 24 public OAuth2TokenService::Observer, | |
| 25 public IdentityProvider::Observer { | |
| 26 public: | |
| 27 typedef base::Callback<void(const std::string&)> TokenCallback; | |
| 28 | |
| 29 explicit IdentitySource(std::unique_ptr<IdentityProvider> identity_provider); | |
| 30 ~IdentitySource() override; | |
| 31 | |
| 32 // Start Blimp authentication by requesting OAuth2 token from Google. | |
|
nyquist
2016/08/16 18:38:05
What happens if I call Connect() multiple times? P
xingliu
2016/08/17 00:32:24
This is a good point. Added a bool to filter dupli
| |
| 33 void Connect(const TokenCallback& token_callback); | |
| 34 | |
| 35 // Set the BlimpClientContextDelegate object, used to inform states change | |
| 36 // to the embedder. | |
| 37 void SetDelegate(BlimpClientContextDelegate* delegate); | |
| 38 | |
| 39 // OAuth2TokenService::Consumer implementation. | |
| 40 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 41 const std::string& access_token, | |
| 42 const base::Time& expiration_time) override; | |
| 43 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 44 const GoogleServiceAuthError& error) override; | |
| 45 | |
| 46 // OAuth2TokenService::Observer implementation. | |
| 47 void OnRefreshTokenAvailable(const std::string& account_id) override; | |
| 48 | |
| 49 private: | |
| 50 // Fetch OAuth token. | |
| 51 void FetchAuthToken(); | |
| 52 | |
| 53 // Provide OAuth2 token service and listen to Google account sign in state. | |
| 54 std::unique_ptr<IdentityProvider> identity_provider_; | |
| 55 | |
| 56 // OAuth2 token request. The request is created when we start to fetch the | |
| 57 // access token in OAuth2TokenService::StartRequest, and destroyed when | |
| 58 // OAuth2TokenService::Consumer callback get called. | |
| 59 std::unique_ptr<OAuth2TokenService::Request> token_request_; | |
| 60 | |
| 61 // Callback to BlimpClientContextImpl after OAuth2 token is fetched. | |
|
nyquist
2016/08/16 18:38:06
I don't think you need to mention BlimpClientConte
xingliu
2016/08/17 00:32:24
Done.
| |
| 62 TokenCallback token_callback_; | |
| 63 | |
| 64 // Account id of current active user, used during token request. | |
| 65 std::string account_id_; | |
| 66 | |
| 67 BlimpClientContextDelegate* delegate_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(IdentitySource); | |
| 70 }; | |
| 71 | |
| 72 } // namespace client | |
| 73 } // namespace blimp | |
| 74 | |
| 75 #endif // BLIMP_CLIENT_CORE_SESSION_IDENTITY_SOURCE_H_ | |
| OLD | NEW |