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 GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ | 5 #ifndef GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ |
6 #define GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ | 6 #define GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 public: | 50 public: |
51 // Maps connection URLs, as returned by StartGetCheckConnectionInfo() to | 51 // Maps connection URLs, as returned by StartGetCheckConnectionInfo() to |
52 // token and URLFetcher used to fetch the URL. | 52 // token and URLFetcher used to fetch the URL. |
53 typedef std::map<GURL, std::pair<std::string, net::URLFetcher*> > | 53 typedef std::map<GURL, std::pair<std::string, net::URLFetcher*> > |
54 URLToTokenAndFetcher; | 54 URLToTokenAndFetcher; |
55 | 55 |
56 // Maps tokens to the fetched result for that token. | 56 // Maps tokens to the fetched result for that token. |
57 typedef std::map<std::string, std::string> ResultMap; | 57 typedef std::map<std::string, std::string> ResultMap; |
58 | 58 |
59 ExternalCcResultFetcher(MergeSessionHelper* helper); | 59 ExternalCcResultFetcher(MergeSessionHelper* helper); |
60 virtual ~ExternalCcResultFetcher(); | 60 ~ExternalCcResultFetcher() override; |
61 | 61 |
62 // Gets the current value of the external connection check result string. | 62 // Gets the current value of the external connection check result string. |
63 std::string GetExternalCcResult(); | 63 std::string GetExternalCcResult(); |
64 | 64 |
65 // Start fetching the external CC result. If a fetch is already in progress | 65 // Start fetching the external CC result. If a fetch is already in progress |
66 // it is canceled. | 66 // it is canceled. |
67 void Start(); | 67 void Start(); |
68 | 68 |
69 // Are external URLs still being checked? | 69 // Are external URLs still being checked? |
70 bool IsRunning(); | 70 bool IsRunning(); |
71 | 71 |
72 // Returns a copy of the internal token to fetcher map. | 72 // Returns a copy of the internal token to fetcher map. |
73 URLToTokenAndFetcher get_fetcher_map_for_testing() { | 73 URLToTokenAndFetcher get_fetcher_map_for_testing() { |
74 return fetchers_; | 74 return fetchers_; |
75 } | 75 } |
76 | 76 |
77 // Simulate a timeout for tests. | 77 // Simulate a timeout for tests. |
78 void TimeoutForTests(); | 78 void TimeoutForTests(); |
79 | 79 |
80 private: | 80 private: |
81 // Overridden from GaiaAuthConsumer. | 81 // Overridden from GaiaAuthConsumer. |
82 virtual void OnGetCheckConnectionInfoSuccess( | 82 void OnGetCheckConnectionInfoSuccess(const std::string& data) override; |
83 const std::string& data) override; | |
84 | 83 |
85 // Creates and initializes a URL fetcher for doing a connection check. | 84 // Creates and initializes a URL fetcher for doing a connection check. |
86 net::URLFetcher* CreateFetcher(const GURL& url); | 85 net::URLFetcher* CreateFetcher(const GURL& url); |
87 | 86 |
88 // Overridden from URLFetcherDelgate. | 87 // Overridden from URLFetcherDelgate. |
89 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 88 void OnURLFetchComplete(const net::URLFetcher* source) override; |
90 | 89 |
91 // Any fetches still ongoing after this call are considered timed out. | 90 // Any fetches still ongoing after this call are considered timed out. |
92 void Timeout(); | 91 void Timeout(); |
93 | 92 |
94 void CleanupTransientState(); | 93 void CleanupTransientState(); |
95 | 94 |
96 MergeSessionHelper* helper_; | 95 MergeSessionHelper* helper_; |
97 base::OneShotTimer<ExternalCcResultFetcher> timer_; | 96 base::OneShotTimer<ExternalCcResultFetcher> timer_; |
98 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 97 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
99 URLToTokenAndFetcher fetchers_; | 98 URLToTokenAndFetcher fetchers_; |
100 ResultMap results_; | 99 ResultMap results_; |
101 | 100 |
102 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); | 101 DISALLOW_COPY_AND_ASSIGN(ExternalCcResultFetcher); |
103 }; | 102 }; |
104 | 103 |
105 MergeSessionHelper(OAuth2TokenService* token_service, | 104 MergeSessionHelper(OAuth2TokenService* token_service, |
106 const std::string& source, | 105 const std::string& source, |
107 net::URLRequestContextGetter* request_context, | 106 net::URLRequestContextGetter* request_context, |
108 Observer* observer); | 107 Observer* observer); |
109 virtual ~MergeSessionHelper(); | 108 ~MergeSessionHelper() override; |
110 | 109 |
111 void LogIn(const std::string& account_id); | 110 void LogIn(const std::string& account_id); |
112 | 111 |
113 // Add or remove observers of this helper. | 112 // Add or remove observers of this helper. |
114 void AddObserver(Observer* observer); | 113 void AddObserver(Observer* observer); |
115 void RemoveObserver(Observer* observer); | 114 void RemoveObserver(Observer* observer); |
116 | 115 |
117 // Cancel all login requests. | 116 // Cancel all login requests. |
118 void CancelAll(); | 117 void CancelAll(); |
119 | 118 |
(...skipping 21 matching lines...) Expand all Loading... |
141 void StartFetchingExternalCcResult(); | 140 void StartFetchingExternalCcResult(); |
142 | 141 |
143 // Returns true if the helper is still fetching external check connection | 142 // Returns true if the helper is still fetching external check connection |
144 // results. | 143 // results. |
145 bool StillFetchingExternalCcResult(); | 144 bool StillFetchingExternalCcResult(); |
146 | 145 |
147 private: | 146 private: |
148 net::URLRequestContextGetter* request_context() { return request_context_; } | 147 net::URLRequestContextGetter* request_context() { return request_context_; } |
149 | 148 |
150 // Overridden from UbertokenConsumer. | 149 // Overridden from UbertokenConsumer. |
151 virtual void OnUbertokenSuccess(const std::string& token) override; | 150 void OnUbertokenSuccess(const std::string& token) override; |
152 virtual void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 151 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
153 | 152 |
154 // Overridden from GaiaAuthConsumer. | 153 // Overridden from GaiaAuthConsumer. |
155 virtual void OnMergeSessionSuccess(const std::string& data) override; | 154 void OnMergeSessionSuccess(const std::string& data) override; |
156 virtual void OnMergeSessionFailure(const GoogleServiceAuthError& error) | 155 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
157 override; | |
158 | 156 |
159 void LogOutInternal(const std::string& account_id, | 157 void LogOutInternal(const std::string& account_id, |
160 const std::vector<std::string>& accounts); | 158 const std::vector<std::string>& accounts); |
161 | 159 |
162 // Starts the proess of fetching the uber token and performing a merge session | 160 // Starts the proess of fetching the uber token and performing a merge session |
163 // for the next account. Virtual so that it can be overriden in tests. | 161 // for the next account. Virtual so that it can be overriden in tests. |
164 virtual void StartFetching(); | 162 virtual void StartFetching(); |
165 | 163 |
166 // Virtual for testing purpose. | 164 // Virtual for testing purpose. |
167 virtual void StartLogOutUrlFetch(); | 165 virtual void StartLogOutUrlFetch(); |
168 | 166 |
169 // Start the next merge session, if needed. | 167 // Start the next merge session, if needed. |
170 void HandleNextAccount(); | 168 void HandleNextAccount(); |
171 | 169 |
172 // Overridden from URLFetcherDelgate. | 170 // Overridden from URLFetcherDelgate. |
173 virtual void OnURLFetchComplete(const net::URLFetcher* source) override; | 171 void OnURLFetchComplete(const net::URLFetcher* source) override; |
174 | 172 |
175 OAuth2TokenService* token_service_; | 173 OAuth2TokenService* token_service_; |
176 net::URLRequestContextGetter* request_context_; | 174 net::URLRequestContextGetter* request_context_; |
177 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 175 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
178 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; | 176 scoped_ptr<UbertokenFetcher> uber_token_fetcher_; |
179 ExternalCcResultFetcher result_fetcher_; | 177 ExternalCcResultFetcher result_fetcher_; |
180 | 178 |
181 // A worklist for this class. Accounts names are stored here if | 179 // A worklist for this class. Accounts names are stored here if |
182 // we are pending a signin action for that account. Empty strings | 180 // we are pending a signin action for that account. Empty strings |
183 // represent a signout request. | 181 // represent a signout request. |
184 std::deque<std::string> accounts_; | 182 std::deque<std::string> accounts_; |
185 | 183 |
186 // List of observers to notify when merge session completes. | 184 // List of observers to notify when merge session completes. |
187 // Makes sure list is empty on destruction. | 185 // Makes sure list is empty on destruction. |
188 ObserverList<Observer, true> observer_list_; | 186 ObserverList<Observer, true> observer_list_; |
189 | 187 |
190 // Source to use with GAIA endpoints for accounting. | 188 // Source to use with GAIA endpoints for accounting. |
191 std::string source_; | 189 std::string source_; |
192 | 190 |
193 DISALLOW_COPY_AND_ASSIGN(MergeSessionHelper); | 191 DISALLOW_COPY_AND_ASSIGN(MergeSessionHelper); |
194 }; | 192 }; |
195 | 193 |
196 #endif // GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ | 194 #endif // GOOGLE_APIS_GAIA_MERGE_SESSION_HELPER_H_ |
OLD | NEW |