OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GAIA_COOKIE_MANAGER_SERVICE_H | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H |
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 class Observer { | 81 class Observer { |
82 public: | 82 public: |
83 // Called whenever a merge session is completed. The account that was | 83 // Called whenever a merge session is completed. The account that was |
84 // merged is given by |account_id|. If |error| is equal to | 84 // merged is given by |account_id|. If |error| is equal to |
85 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. | 85 // GoogleServiceAuthError::AuthErrorNone() then the merge succeeeded. |
86 virtual void OnAddAccountToCookieCompleted( | 86 virtual void OnAddAccountToCookieCompleted( |
87 const std::string& account_id, | 87 const std::string& account_id, |
88 const GoogleServiceAuthError& error) = 0; | 88 const GoogleServiceAuthError& error) = 0; |
89 | 89 |
90 // Called when ExternalCcResultFetcher completes. From this moment | |
91 // forward calls to AddAccountToCookie() will use the result in merge | |
92 // session calls. If |succeeded| is false, not all connections were checked, | |
93 // but some may have been. AddAccountToCookie() will proceed with whatever | |
94 // partial results were retrieved. | |
95 virtual void GetCheckConnectionInfoCompleted(bool succeeded) {} | |
96 | |
97 protected: | 90 protected: |
98 virtual ~Observer() {} | 91 virtual ~Observer() {} |
99 }; | 92 }; |
100 | 93 |
101 // Class to retrieve the external connection check results from gaia. | 94 // Class to retrieve the external connection check results from gaia. |
102 // Declared publicly for unit tests. | 95 // Declared publicly for unit tests. |
103 class ExternalCcResultFetcher : public GaiaAuthConsumer, | 96 class ExternalCcResultFetcher : public GaiaAuthConsumer, |
104 public net::URLFetcherDelegate { | 97 public net::URLFetcherDelegate { |
105 public: | 98 public: |
106 // Maps connection URLs, as returned by StartGetCheckConnectionInfo() to | 99 // Maps connection URLs, as returned by StartGetCheckConnectionInfo() to |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 net::URLFetcher* CreateFetcher(const GURL& url); | 133 net::URLFetcher* CreateFetcher(const GURL& url); |
141 | 134 |
142 // Overridden from URLFetcherDelgate. | 135 // Overridden from URLFetcherDelgate. |
143 void OnURLFetchComplete(const net::URLFetcher* source) override; | 136 void OnURLFetchComplete(const net::URLFetcher* source) override; |
144 | 137 |
145 // Any fetches still ongoing after this call are considered timed out. | 138 // Any fetches still ongoing after this call are considered timed out. |
146 void Timeout(); | 139 void Timeout(); |
147 | 140 |
148 void CleanupTransientState(); | 141 void CleanupTransientState(); |
149 | 142 |
150 void FireGetCheckConnectionInfoCompleted(bool succeeded); | 143 void GetCheckConnectionInfoCompleted(bool succeeded); |
151 | 144 |
152 GaiaCookieManagerService* helper_; | 145 GaiaCookieManagerService* helper_; |
153 base::OneShotTimer<ExternalCcResultFetcher> timer_; | 146 base::OneShotTimer<ExternalCcResultFetcher> timer_; |
154 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
155 URLToTokenAndFetcher fetchers_; | 147 URLToTokenAndFetcher fetchers_; |
156 ResultMap results_; | 148 ResultMap results_; |
157 base::Time m_external_cc_result_start_time_; | 149 base::Time m_external_cc_result_start_time_; |
158 | 150 |
| 151 base::OneShotTimer<ExternalCcResultFetcher> gaia_auth_fetcher_timer_; |
| 152 |
159 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); | 153 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); |
160 }; | 154 }; |
161 | 155 |
162 GaiaCookieManagerService(OAuth2TokenService* token_service, | 156 GaiaCookieManagerService(OAuth2TokenService* token_service, |
163 const std::string& source, | 157 const std::string& source, |
164 SigninClient* signin_client); | 158 SigninClient* signin_client); |
165 ~GaiaCookieManagerService() override; | 159 ~GaiaCookieManagerService() override; |
166 | 160 |
167 void AddAccountToCookie(const std::string& account_id); | 161 void AddAccountToCookie(const std::string& account_id); |
168 | 162 |
(...skipping 11 matching lines...) Expand all Loading... |
180 | 174 |
181 // Call observers when merge session completes. This public so that callers | 175 // Call observers when merge session completes. This public so that callers |
182 // that know that a given account is already in the cookie jar can simply | 176 // that know that a given account is already in the cookie jar can simply |
183 // inform the observers. | 177 // inform the observers. |
184 void SignalComplete(const std::string& account_id, | 178 void SignalComplete(const std::string& account_id, |
185 const GoogleServiceAuthError& error); | 179 const GoogleServiceAuthError& error); |
186 | 180 |
187 // Returns true of there are pending log ins or outs. | 181 // Returns true of there are pending log ins or outs. |
188 bool is_running() const { return requests_.size() > 0; } | 182 bool is_running() const { return requests_.size() > 0; } |
189 | 183 |
190 // Start the process of fetching the external check connection result so that | 184 // Access the internal object during tests. |
191 // its ready when we try to perform a merge session. | 185 ExternalCcResultFetcher* external_cc_result_fetcher_for_testing() { |
192 void StartFetchingExternalCcResult(); | 186 return &external_cc_result_fetcher_; |
| 187 } |
193 | 188 |
194 private: | 189 private: |
195 net::URLRequestContextGetter* request_context() { | 190 net::URLRequestContextGetter* request_context() { |
196 return signin_client_->GetURLRequestContext(); | 191 return signin_client_->GetURLRequestContext(); |
197 } | 192 } |
198 | 193 |
199 // Overridden from UbertokenConsumer. | 194 // Overridden from UbertokenConsumer. |
200 void OnUbertokenSuccess(const std::string& token) override; | 195 void OnUbertokenSuccess(const std::string& token) override; |
201 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 196 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
202 | 197 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // executed at a time. | 234 // executed at a time. |
240 std::deque<GaiaCookieRequest> requests_; | 235 std::deque<GaiaCookieRequest> requests_; |
241 | 236 |
242 // List of observers to notify when merge session completes. | 237 // List of observers to notify when merge session completes. |
243 // Makes sure list is empty on destruction. | 238 // Makes sure list is empty on destruction. |
244 ObserverList<Observer, true> observer_list_; | 239 ObserverList<Observer, true> observer_list_; |
245 | 240 |
246 // Source to use with GAIA endpoints for accounting. | 241 // Source to use with GAIA endpoints for accounting. |
247 std::string source_; | 242 std::string source_; |
248 | 243 |
| 244 // True once the ExternalCCResultFetcher has completed once. |
| 245 bool external_cc_result_fetched_; |
| 246 |
249 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); | 247 DISALLOW_COPY_AND_ASSIGN(GaiaCookieManagerService); |
250 }; | 248 }; |
251 | 249 |
252 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H | 250 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_GAIA_COOKIE_MANAGER_SERVICE_H |
OLD | NEW |