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

Side by Side Diff: blimp/client/core/session/identity_source.h

Issue 2204223005: Blimp OAuth2 token retreival on application start up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some deps only for gn deps check script. Created 4 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
OLDNEW
(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/macros.h"
12
13 #include "blimp/client/public/blimp_client_context_delegate.h"
14 #include "google_apis/gaia/identity_provider.h"
15 #include "google_apis/gaia/oauth2_token_service.h"
16
17 namespace blimp {
18 namespace client {
19
20 // IdentitySource handles OAuth2 token request and forward user sign in state
21 // change to Blimp with ProfileIdentityProvider.
22 class IdentitySource : public OAuth2TokenService::Consumer,
23 public OAuth2TokenService::Observer,
24 public IdentityProvider::Observer {
25 public:
26 explicit IdentitySource(std::unique_ptr<IdentityProvider> identity_provider);
27 ~IdentitySource() override;
28
29 // Start Blimp authentication by requesting OAuth2 token from Google.
30 void Connect();
31
32 // Set the BlimpClientContextDelegate object, used to inform states change
33 // to the embedder.
34 void SetDelegate(BlimpClientContextDelegate* delegate);
35
36 // OAuth2TokenService::Consumer implementation.
37 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
38 const std::string& access_token,
39 const base::Time& expiration_time) override;
40 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
41 const GoogleServiceAuthError& error) override;
42
43 // OAuth2TokenService::Observer implementation.
44 void OnRefreshTokenAvailable(const std::string& account_id) override;
45
46 private:
47 // Fetch OAuth token.
48 void FetchAuthToken();
49
50 // Provide OAuth2 token service and listen to Google account sign in state.
51 std::unique_ptr<IdentityProvider> identity_provider_;
52
53 // OAuth2 token request. The request is created when we start to fetch the
54 // access token in OAuth2TokenService::StartRequest, and destroyed when
55 // OAuth2TokenService::Consumer callback get called.
56 std::unique_ptr<OAuth2TokenService::Request> token_request_;
57
58 // Account id of current active user, used during token request.
59 std::string account_id_;
60
61 BlimpClientContextDelegate* delegate_;
62
63 DISALLOW_COPY_AND_ASSIGN(IdentitySource);
64 };
65
66 } // namespace client
67 } // namespace blimp
68
69 #endif // BLIMP_CLIENT_CORE_SESSION_IDENTITY_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698