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

Side by Side Diff: components/signin/ios/browser/profile_oauth2_token_service_ios_delegate.h

Issue 1143323005: Refactor AO2TS to make it easier to componentize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address final comments Created 5 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_DELEGATE_ H_
5 #ifndef COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_ 5 #define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_DELEGATE_ H_
6 #define COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_
7 6
8 #include <string> 7 #include <string>
9 8
9 #include "base/memory/linked_ptr.h"
10 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
11 #include "components/signin/core/browser/profile_oauth2_token_service.h"
12 #include "components/signin/core/browser/signin_error_controller.h" 11 #include "components/signin/core/browser/signin_error_controller.h"
12 #include "google_apis/gaia/oauth2_token_service_delegate.h"
13 13
14 class OAuth2AccessTokenFetcher; 14 namespace ios {
15
16 namespace ios{
17 class ProfileOAuth2TokenServiceIOSProvider; 15 class ProfileOAuth2TokenServiceIOSProvider;
18 } 16 }
19 17
20 // A specialization of ProfileOAuth2TokenService that will be returned by 18 class ProfileOAuth2TokenServiceIOSDelegate : public OAuth2TokenServiceDelegate {
21 // ProfileOAuth2TokenServiceFactory for OS_IOS when iOS authentication service
22 // is used to lookup OAuth2 tokens.
23 //
24 // See |ProfileOAuth2TokenService| for usage details.
25 //
26 // Note: Requests should be started from the UI thread. To start a
27 // request from aother thread, please use OAuth2TokenServiceRequest.
28 class ProfileOAuth2TokenServiceIOS : public ProfileOAuth2TokenService {
29 public: 19 public:
20 ProfileOAuth2TokenServiceIOSDelegate(
21 SigninClient* client,
22 SigninErrorController* signin_error_controller);
23 ~ProfileOAuth2TokenServiceIOSDelegate() override;
24
25 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
26 const std::string& account_id,
27 net::URLRequestContextGetter* getter,
28 OAuth2AccessTokenConsumer* consumer) override;
29
30 // KeyedService 30 // KeyedService
31 void Shutdown() override; 31 void Shutdown() override;
32 32
33 // OAuth2TokenService
34 bool RefreshTokenIsAvailable(const std::string& account_id) const override; 33 bool RefreshTokenIsAvailable(const std::string& account_id) const override;
35 34
36 void InvalidateOAuth2Token(const std::string& account_id,
37 const std::string& client_id,
38 const ScopeSet& scopes,
39 const std::string& access_token) override;
40
41 // ProfileOAuth2TokenService
42 void Initialize(SigninClient* client,
43 SigninErrorController* signin_error_controller) override;
44 void LoadCredentials(const std::string& primary_account_id) override; 35 void LoadCredentials(const std::string& primary_account_id) override;
45 std::vector<std::string> GetAccounts() override; 36 std::vector<std::string> GetAccounts() override;
46 void UpdateAuthError(const std::string& account_id, 37 void UpdateAuthError(const std::string& account_id,
47 const GoogleServiceAuthError& error) override; 38 const GoogleServiceAuthError& error) override;
48 39
49 // This method should not be called when using shared authentication. 40 // This method should not be called when using shared authentication.
50 void UpdateCredentials(const std::string& account_id, 41 void UpdateCredentials(const std::string& account_id,
51 const std::string& refresh_token) override; 42 const std::string& refresh_token) override;
52 43
53 // Removes all credentials from this instance of |ProfileOAuth2TokenService|, 44 // Removes all credentials from this instance of |ProfileOAuth2TokenService|,
(...skipping 15 matching lines...) Expand all
69 // Sets the account that should be ignored by this token service. 60 // Sets the account that should be ignored by this token service.
70 // |ReloadCredentials| needs to be called for this change to be effective. 61 // |ReloadCredentials| needs to be called for this change to be effective.
71 void ExcludeSecondaryAccount(const std::string& account_id); 62 void ExcludeSecondaryAccount(const std::string& account_id);
72 void IncludeSecondaryAccount(const std::string& account_id); 63 void IncludeSecondaryAccount(const std::string& account_id);
73 void ExcludeSecondaryAccounts(const std::vector<std::string>& account_ids); 64 void ExcludeSecondaryAccounts(const std::vector<std::string>& account_ids);
74 65
75 // Excludes all secondary accounts. |ReloadCredentials| needs to be called for 66 // Excludes all secondary accounts. |ReloadCredentials| needs to be called for
76 // this change to be effective. 67 // this change to be effective.
77 void ExcludeAllSecondaryAccounts(); 68 void ExcludeAllSecondaryAccounts();
78 69
79 protected: 70 private:
80 friend class ProfileOAuth2TokenServiceFactory; 71 friend class ProfileOAuth2TokenServiceIOSDelegateTest;
81 friend class ProfileOAuth2TokenServiceIOSTest; 72 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceIOSDelegateTest,
82 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceIOSTest,
83 ExcludeSecondaryAccounts);
84 FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceIOSTest,
85 LoadRevokeCredentialsClearsExcludedAccounts); 73 LoadRevokeCredentialsClearsExcludedAccounts);
86 74
87 ProfileOAuth2TokenServiceIOS();
88 ~ProfileOAuth2TokenServiceIOS() override;
89
90 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
91 const std::string& account_id,
92 net::URLRequestContextGetter* getter,
93 OAuth2AccessTokenConsumer* consumer) override;
94
95 // Protected and virtual to be overriden by fake for testing.
96
97 // Adds |account_id| to |accounts_| if it does not exist or udpates
98 // the auth error state of |account_id| if it exists. Fires
99 // |OnRefreshTokenAvailable| if the account info is updated.
100 virtual void AddOrUpdateAccount(const std::string& account_id);
101
102 // Removes |account_id| from |accounts_|. Fires |OnRefreshTokenRevoked|
103 // if the account info is removed.
104 virtual void RemoveAccount(const std::string& account_id);
105
106 private:
107 class AccountInfo : public SigninErrorController::AuthStatusProvider { 75 class AccountInfo : public SigninErrorController::AuthStatusProvider {
108 public: 76 public:
109 AccountInfo(SigninErrorController* signin_error_controller, 77 AccountInfo(SigninErrorController* signin_error_controller,
110 const std::string& account_id); 78 const std::string& account_id);
111 ~AccountInfo() override; 79 ~AccountInfo() override;
112 80
113 void SetLastAuthError(const GoogleServiceAuthError& error); 81 void SetLastAuthError(const GoogleServiceAuthError& error);
114 82
115 // SigninErrorController::AuthStatusProvider implementation. 83 // SigninErrorController::AuthStatusProvider implementation.
116 std::string GetAccountId() const override; 84 std::string GetAccountId() const override;
117 GoogleServiceAuthError GetAuthStatus() const override; 85 GoogleServiceAuthError GetAuthStatus() const override;
118 86
119 bool marked_for_removal() const { return marked_for_removal_; } 87 bool marked_for_removal() const { return marked_for_removal_; }
120 void set_marked_for_removal(bool marked_for_removal) { 88 void set_marked_for_removal(bool marked_for_removal) {
121 marked_for_removal_ = marked_for_removal; 89 marked_for_removal_ = marked_for_removal;
122 } 90 }
123 91
124 private: 92 private:
125 SigninErrorController* signin_error_controller_; 93 SigninErrorController* signin_error_controller_;
126 std::string account_id_; 94 std::string account_id_;
127 GoogleServiceAuthError last_auth_error_; 95 GoogleServiceAuthError last_auth_error_;
128 bool marked_for_removal_; 96 bool marked_for_removal_;
129 97
130 DISALLOW_COPY_AND_ASSIGN(AccountInfo); 98 DISALLOW_COPY_AND_ASSIGN(AccountInfo);
131 }; 99 };
132 100
101 // Adds |account_id| to |accounts_| if it does not exist or udpates
102 // the auth error state of |account_id| if it exists. Fires
103 // |OnRefreshTokenAvailable| if the account info is updated.
104 void AddOrUpdateAccount(const std::string& account_id);
105
106 // Removes |account_id| from |accounts_|. Fires |OnRefreshTokenRevoked|
107 // if the account info is removed.
108 void RemoveAccount(const std::string& account_id);
109
133 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService 110 // Maps the |account_id| of accounts known to ProfileOAuth2TokenService
134 // to information about the account. 111 // to information about the account.
135 typedef std::map<std::string, linked_ptr<AccountInfo> > AccountInfoMap; 112 typedef std::map<std::string, linked_ptr<AccountInfo>> AccountInfoMap;
136 113
137 // Returns the iOS provider; 114 // Returns the iOS provider;
138 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider(); 115 ios::ProfileOAuth2TokenServiceIOSProvider* GetProvider();
139 116
140 // Returns the account ids that should be ignored by this token service. 117 // Returns the account ids that should be ignored by this token service.
141 std::set<std::string> GetExcludedSecondaryAccounts(); 118 std::set<std::string> GetExcludedSecondaryAccounts();
142 119
143 // Returns true if this token service should exclude all secondary accounts. 120 // Returns true if this token service should exclude all secondary accounts.
144 bool GetExcludeAllSecondaryAccounts(); 121 bool GetExcludeAllSecondaryAccounts();
145 122
146 // Clears exclude secondary accounts preferences. 123 // Clears exclude secondary accounts preferences.
147 void ClearExcludedSecondaryAccounts(); 124 void ClearExcludedSecondaryAccounts();
148 125
149 // The primary account id. 126 // The primary account id.
150 std::string primary_account_id_; 127 std::string primary_account_id_;
151 128
152 // Info about the existing accounts. 129 // Info about the existing accounts.
153 AccountInfoMap accounts_; 130 AccountInfoMap accounts_;
154 131
155 // Calls to this class are expected to be made from the browser UI thread. 132 // Calls to this class are expected to be made from the browser UI thread.
156 // The purpose of this checker is to detect access to 133 // The purpose of this checker is to detect access to
157 // ProfileOAuth2TokenService from multiple threads in upstream code. 134 // ProfileOAuth2TokenService from multiple threads in upstream code.
158 base::ThreadChecker thread_checker_; 135 base::ThreadChecker thread_checker_;
159 136
160 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOS); 137 // The client with which this instance was initialied, or NULL.
138 SigninClient* client_;
139
140 // The error controller with which this instance was initialized, or NULL.
141 SigninErrorController* signin_error_controller_;
142
143 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenServiceIOSDelegate);
161 }; 144 };
162 145 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_DELEGA TE_H_
163 #endif // COMPONENTS_SIGNIN_IOS_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_IOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698