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 17 matching lines...) Expand all Loading... |
37 static const char kLastUpdatePref[]; | 35 static const char kLastUpdatePref[]; |
38 | 36 |
39 AccountFetcherService(); | 37 AccountFetcherService(); |
40 ~AccountFetcherService() override; | 38 ~AccountFetcherService() override; |
41 | 39 |
42 // Registers the preferences used by AccountFetcherService. | 40 // Registers the preferences used by AccountFetcherService. |
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); | |
49 | 46 |
50 // KeyedService implementation | 47 // KeyedService implementation |
51 void Shutdown() override; | 48 void Shutdown() override; |
52 | 49 |
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, | 50 // Indicates if all user information has been fetched. If the result is false, |
58 // there are still unfininshed fetchers. | 51 // there are still unfininshed fetchers. |
59 virtual bool IsAllUserInfoFetched() const; | 52 virtual bool IsAllUserInfoFetched() const; |
60 | 53 |
61 void FetchUserInfoBeforeSignin(const std::string& account_id); | 54 void FetchUserInfoBeforeSignin(const std::string& account_id); |
62 | 55 |
63 AccountTrackerService* account_tracker_service() const { | 56 AccountTrackerService* account_tracker_service() const { |
64 return account_tracker_service_; | 57 return account_tracker_service_; |
65 } | 58 } |
66 | 59 |
| 60 void SetupInvalidations( |
| 61 invalidation::InvalidationService* invalidation_service); |
| 62 |
67 // Called by ChildAccountInfoFetcher. | 63 // Called by ChildAccountInfoFetcher. |
68 void SetIsChildAccount(const std::string& account_id, bool is_child_account); | 64 void SetIsChildAccount(const std::string& account_id, bool is_child_account); |
69 | 65 |
| 66 // OAuth2TokenService::Observer implementation. |
| 67 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 68 void OnRefreshTokenRevoked(const std::string& account_id) override; |
| 69 void OnRefreshTokensLoaded() override; |
| 70 |
70 private: | 71 private: |
71 friend class AccountInfoFetcher; | 72 friend class AccountInfoFetcher; |
72 friend class ChildAccountInfoFetcherImpl; | 73 friend class ChildAccountInfoFetcherImpl; |
73 | 74 |
74 void RefreshAllAccountInfo(bool only_fetch_if_invalid); | 75 void RefreshAllAccountInfo(bool only_fetch_if_invalid); |
75 void RefreshAllAccountsAndScheduleNext(); | 76 void RefreshAllAccountsAndScheduleNext(); |
76 void ScheduleNextRefresh(); | 77 void ScheduleNextRefresh(); |
77 | 78 |
78 // Called on all account state changes. Decides whether to fetch new child | 79 // Called on all account state changes. Decides whether to fetch new child |
79 // status information or reset old values that aren't valid now. | 80 // status information or reset old values that aren't valid now. |
(...skipping 15 matching lines...) Expand all Loading... |
95 | 96 |
96 // Virtual so that tests can override the network fetching behaviour. | 97 // Virtual so that tests can override the network fetching behaviour. |
97 virtual void SendRefreshTokenAnnotationRequest(const std::string& account_id); | 98 virtual void SendRefreshTokenAnnotationRequest(const std::string& account_id); |
98 void RefreshTokenAnnotationRequestDone(const std::string& account_id); | 99 void RefreshTokenAnnotationRequestDone(const std::string& account_id); |
99 | 100 |
100 // Called by AccountInfoFetcher. | 101 // Called by AccountInfoFetcher. |
101 void OnUserInfoFetchSuccess(const std::string& account_id, | 102 void OnUserInfoFetchSuccess(const std::string& account_id, |
102 scoped_ptr<base::DictionaryValue> user_info); | 103 scoped_ptr<base::DictionaryValue> user_info); |
103 void OnUserInfoFetchFailure(const std::string& account_id); | 104 void OnUserInfoFetchFailure(const std::string& account_id); |
104 | 105 |
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. | 106 AccountTrackerService* account_tracker_service_; // Not owned. |
111 OAuth2TokenService* token_service_; // Not owned. | 107 OAuth2TokenService* token_service_; // Not owned. |
112 SigninClient* signin_client_; // Not owned. | 108 SigninClient* signin_client_; // Not owned. |
113 invalidation::InvalidationService* invalidation_service_; // Not owned. | 109 invalidation::InvalidationService* invalidation_service_; // Not owned. |
114 bool network_fetches_enabled_; | 110 bool network_fetches_enabled_; |
115 std::list<std::string> pending_user_info_fetches_; | |
116 base::Time last_updated_; | 111 base::Time last_updated_; |
117 base::OneShotTimer timer_; | 112 base::OneShotTimer timer_; |
118 bool shutdown_called_; | 113 bool shutdown_called_; |
119 | 114 |
120 std::string child_request_account_id_; | 115 std::string child_request_account_id_; |
121 scoped_ptr<ChildAccountInfoFetcher> child_info_request_; | 116 scoped_ptr<ChildAccountInfoFetcher> child_info_request_; |
122 | 117 |
123 // Holds references to account info fetchers keyed by account_id. | 118 // Holds references to account info fetchers keyed by account_id. |
124 base::ScopedPtrHashMap<std::string, scoped_ptr<AccountInfoFetcher>> | 119 base::ScopedPtrHashMap<std::string, scoped_ptr<AccountInfoFetcher>> |
125 user_info_requests_; | 120 user_info_requests_; |
126 // Holds references to refresh token annotation requests keyed by account_id. | 121 // Holds references to refresh token annotation requests keyed by account_id. |
127 base::ScopedPtrHashMap<std::string, scoped_ptr<RefreshTokenAnnotationRequest>> | 122 base::ScopedPtrHashMap<std::string, scoped_ptr<RefreshTokenAnnotationRequest>> |
128 refresh_token_annotation_requests_; | 123 refresh_token_annotation_requests_; |
129 | 124 |
130 DISALLOW_COPY_AND_ASSIGN(AccountFetcherService); | 125 DISALLOW_COPY_AND_ASSIGN(AccountFetcherService); |
131 }; | 126 }; |
132 | 127 |
133 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ | 128 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_FETCHER_SERVICE_H_ |
OLD | NEW |