OLD | NEW |
1 // Copyright 2015 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 |
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ |
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ |
7 | 7 |
8 #include <list> | |
9 | |
10 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
11 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
12 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
13 #include "components/keyed_service/core/keyed_service.h" | 11 #include "components/keyed_service/core/keyed_service.h" |
14 #include "google_apis/gaia/oauth2_token_service.h" | 12 #include "google_apis/gaia/oauth2_token_service.h" |
15 | 13 |
16 class AccountInfoFetcher; | 14 class AccountInfoFetcher; |
17 class AccountTrackerService; | 15 class AccountTrackerService; |
18 class ChildAccountInfoFetcher; | 16 class ChildAccountInfoFetcher; |
19 class OAuth2TokenService; | 17 class OAuth2TokenService; |
(...skipping 23 matching lines...) Expand all Loading... |
43 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* user_prefs); | 41 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* user_prefs); |
44 | 42 |
45 void Initialize(SigninClient* signin_client, | 43 void Initialize(SigninClient* signin_client, |
46 OAuth2TokenService* token_service, | 44 OAuth2TokenService* token_service, |
47 AccountTrackerService* account_tracker_service, | 45 AccountTrackerService* account_tracker_service, |
48 invalidation::InvalidationService* invalidation_service); | 46 invalidation::InvalidationService* invalidation_service); |
49 | 47 |
50 // KeyedService implementation | 48 // KeyedService implementation |
51 void Shutdown() override; | 49 void Shutdown() override; |
52 | 50 |
53 // To be called after the Profile is fully initialized; permits network | |
54 // calls to be executed. | |
55 void EnableNetworkFetches(); | |
56 | |
57 // Indicates if all user information has been fetched. If the result is false, | 51 // Indicates if all user information has been fetched. If the result is false, |
58 // there are still unfininshed fetchers. | 52 // there are still unfininshed fetchers. |
59 virtual bool IsAllUserInfoFetched() const; | 53 virtual bool IsAllUserInfoFetched() const; |
60 | 54 |
61 void FetchUserInfoBeforeSignin(const std::string& account_id); | 55 void FetchUserInfoBeforeSignin(const std::string& account_id); |
62 | 56 |
63 AccountTrackerService* account_tracker_service() const { | 57 AccountTrackerService* account_tracker_service() const { |
64 return account_tracker_service_; | 58 return account_tracker_service_; |
65 } | 59 } |
66 | 60 |
67 // Called by ChildAccountInfoFetcher. | 61 // Called by ChildAccountInfoFetcher. |
68 void SetIsChildAccount(const std::string& account_id, bool is_child_account); | 62 void SetIsChildAccount(const std::string& account_id, bool is_child_account); |
69 | 63 |
| 64 // OAuth2TokenService::Observer implementation. |
| 65 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 66 void OnRefreshTokenRevoked(const std::string& account_id) override; |
| 67 void OnRefreshTokensLoaded() override; |
| 68 |
70 private: | 69 private: |
71 friend class AccountInfoFetcher; | 70 friend class AccountInfoFetcher; |
72 friend class ChildAccountInfoFetcherImpl; | 71 friend class ChildAccountInfoFetcherImpl; |
73 | 72 |
74 void RefreshAllAccountInfo(bool only_fetch_if_invalid); | 73 void RefreshAllAccountInfo(bool only_fetch_if_invalid); |
75 void RefreshAllAccountsAndScheduleNext(); | 74 void RefreshAllAccountsAndScheduleNext(); |
76 void ScheduleNextRefresh(); | 75 void ScheduleNextRefresh(); |
77 | 76 |
78 // Called on all account state changes. Decides whether to fetch new child | 77 // Called on all account state changes. Decides whether to fetch new child |
79 // status information or reset old values that aren't valid now. | 78 // status information or reset old values that aren't valid now. |
(...skipping 15 matching lines...) Expand all Loading... |
95 | 94 |
96 // Virtual so that tests can override the network fetching behaviour. | 95 // Virtual so that tests can override the network fetching behaviour. |
97 virtual void SendRefreshTokenAnnotationRequest(const std::string& account_id); | 96 virtual void SendRefreshTokenAnnotationRequest(const std::string& account_id); |
98 void RefreshTokenAnnotationRequestDone(const std::string& account_id); | 97 void RefreshTokenAnnotationRequestDone(const std::string& account_id); |
99 | 98 |
100 // Called by AccountInfoFetcher. | 99 // Called by AccountInfoFetcher. |
101 void OnUserInfoFetchSuccess(const std::string& account_id, | 100 void OnUserInfoFetchSuccess(const std::string& account_id, |
102 scoped_ptr<base::DictionaryValue> user_info); | 101 scoped_ptr<base::DictionaryValue> user_info); |
103 void OnUserInfoFetchFailure(const std::string& account_id); | 102 void OnUserInfoFetchFailure(const std::string& account_id); |
104 | 103 |
105 // OAuth2TokenService::Observer implementation. | |
106 void OnRefreshTokenAvailable(const std::string& account_id) override; | |
107 void OnRefreshTokenRevoked(const std::string& account_id) override; | |
108 void OnRefreshTokensLoaded() override; | |
109 | |
110 AccountTrackerService* account_tracker_service_; // Not owned. | 104 AccountTrackerService* account_tracker_service_; // Not owned. |
111 OAuth2TokenService* token_service_; // Not owned. | 105 OAuth2TokenService* token_service_; // Not owned. |
112 SigninClient* signin_client_; // Not owned. | 106 SigninClient* signin_client_; // Not owned. |
113 invalidation::InvalidationService* invalidation_service_; // Not owned. | 107 invalidation::InvalidationService* invalidation_service_; // Not owned. |
114 bool network_fetches_enabled_; | 108 bool network_fetches_enabled_; |
115 std::list<std::string> pending_user_info_fetches_; | |
116 base::Time last_updated_; | 109 base::Time last_updated_; |
117 base::OneShotTimer timer_; | 110 base::OneShotTimer timer_; |
118 bool shutdown_called_; | 111 bool shutdown_called_; |
119 | 112 |
120 std::string child_request_account_id_; | 113 std::string child_request_account_id_; |
121 scoped_ptr<ChildAccountInfoFetcher> child_info_request_; | 114 scoped_ptr<ChildAccountInfoFetcher> child_info_request_; |
122 | 115 |
123 // Holds references to account info fetchers keyed by account_id. | 116 // Holds references to account info fetchers keyed by account_id. |
124 base::ScopedPtrHashMap<std::string, scoped_ptr<AccountInfoFetcher>> | 117 base::ScopedPtrHashMap<std::string, scoped_ptr<AccountInfoFetcher>> |
125 user_info_requests_; | 118 user_info_requests_; |
126 // Holds references to refresh token annotation requests keyed by account_id. | 119 // Holds references to refresh token annotation requests keyed by account_id. |
127 base::ScopedPtrHashMap<std::string, scoped_ptr<RefreshTokenAnnotationRequest>> | 120 base::ScopedPtrHashMap<std::string, scoped_ptr<RefreshTokenAnnotationRequest>> |
128 refresh_token_annotation_requests_; | 121 refresh_token_annotation_requests_; |
129 | 122 |
130 DISALLOW_COPY_AND_ASSIGN(AccountFetcherService); | 123 DISALLOW_COPY_AND_ASSIGN(AccountFetcherService); |
131 }; | 124 }; |
132 | 125 |
133 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ | 126 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ |
OLD | NEW |