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

Side by Side Diff: sync/engine/net/server_connection_manager.h

Issue 15421011: Use OAuth2 token for sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ 5 #ifndef SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_
6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ 6 #define SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool require_response); 157 bool require_response);
158 bool ReadDownloadResponse(HttpResponse* response, std::string* buffer_out); 158 bool ReadDownloadResponse(HttpResponse* response, std::string* buffer_out);
159 159
160 protected: 160 protected:
161 std::string MakeConnectionURL(const std::string& sync_server, 161 std::string MakeConnectionURL(const std::string& sync_server,
162 const std::string& path, 162 const std::string& path,
163 bool use_ssl) const; 163 bool use_ssl) const;
164 164
165 void GetServerParams(std::string* server, 165 void GetServerParams(std::string* server,
166 int* server_port, 166 int* server_port,
167 bool* use_ssl) const { 167 bool* use_ssl,
168 bool* use_oauth2_token) const {
168 server->assign(scm_->sync_server_); 169 server->assign(scm_->sync_server_);
169 *server_port = scm_->sync_server_port_; 170 *server_port = scm_->sync_server_port_;
170 *use_ssl = scm_->use_ssl_; 171 *use_ssl = scm_->use_ssl_;
172 *use_oauth2_token = scm_->use_oauth2_token_;
171 } 173 }
172 174
173 std::string buffer_; 175 std::string buffer_;
174 ServerConnectionManager* scm_; 176 ServerConnectionManager* scm_;
175 177
176 private: 178 private:
177 int ReadResponse(void* buffer, int length); 179 int ReadResponse(void* buffer, int length);
178 int ReadResponse(std::string* buffer, int length); 180 int ReadResponse(std::string* buffer, int length);
179 }; 181 };
180 182
181 ServerConnectionManager(const std::string& server, 183 ServerConnectionManager(const std::string& server,
182 int port, 184 int port,
183 bool use_ssl); 185 bool use_ssl,
186 bool use_oauth2_token);
184 187
185 virtual ~ServerConnectionManager(); 188 virtual ~ServerConnectionManager();
186 189
187 // POSTS buffer_in and reads a response into buffer_out. Uses our currently 190 // POSTS buffer_in and reads a response into buffer_out. Uses our currently
188 // set auth token in our headers. 191 // set auth token in our headers.
189 // 192 //
190 // Returns true if executed successfully. 193 // Returns true if executed successfully.
191 virtual bool PostBufferWithCachedAuth(PostBufferParams* params, 194 virtual bool PostBufferWithCachedAuth(PostBufferParams* params,
192 ScopedServerStatusWatcher* watcher); 195 ScopedServerStatusWatcher* watcher);
193 196
(...skipping 23 matching lines...) Expand all
217 // ThreadChecker thread, as we want to kill any pending http traffic without 220 // ThreadChecker thread, as we want to kill any pending http traffic without
218 // having to wait for the request to complete. 221 // having to wait for the request to complete.
219 void TerminateAllIO(); 222 void TerminateAllIO();
220 223
221 void set_client_id(const std::string& client_id) { 224 void set_client_id(const std::string& client_id) {
222 DCHECK(thread_checker_.CalledOnValidThread()); 225 DCHECK(thread_checker_.CalledOnValidThread());
223 DCHECK(client_id_.empty()); 226 DCHECK(client_id_.empty());
224 client_id_.assign(client_id); 227 client_id_.assign(client_id);
225 } 228 }
226 229
227 // Sets a new auth token and time. |auth_token_time| is an optional parameter 230 // Sets a new auth token and time.
228 // that contains the date the auth token was fetched/refreshed, and is used 231 bool SetAuthToken(const std::string& auth_token);
229 // for histogramms/logging only.
230 bool SetAuthToken(const std::string& auth_token,
231 const base::Time& auth_token_time);
232 232
233 // Our out-of-band invalidations channel can encounter auth errors, 233 // Our out-of-band invalidations channel can encounter auth errors,
234 // and when it does so it tells us via this method to prevent making more 234 // and when it does so it tells us via this method to prevent making more
235 // requests with known-bad tokens. This will put the 235 // requests with known-bad tokens. This will put the
236 // ServerConnectionManager in an auth error state as if it received an 236 // ServerConnectionManager in an auth error state as if it received an
237 // HTTP 401 from sync servers. 237 // HTTP 401 from sync servers.
238 void OnInvalidationCredentialsRejected(); 238 void OnInvalidationCredentialsRejected();
239 239
240 bool HasInvalidAuthToken() { 240 bool HasInvalidAuthToken() {
241 return auth_token_.empty(); 241 return auth_token_.empty();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 281
282 // The sync_server_port_ is the port that HTTP requests will be made on. 282 // The sync_server_port_ is the port that HTTP requests will be made on.
283 int sync_server_port_; 283 int sync_server_port_;
284 284
285 // The unique id of the user's client. 285 // The unique id of the user's client.
286 std::string client_id_; 286 std::string client_id_;
287 287
288 // Indicates whether or not requests should be made using HTTPS. 288 // Indicates whether or not requests should be made using HTTPS.
289 bool use_ssl_; 289 bool use_ssl_;
290 290
291 // Indicates if token should be handled as OAuth2 token. Connection should set
292 // auth header appropriately.
293 // TODO(pavely): Remove once sync on android switches to oauth2 tokens.
294 bool use_oauth2_token_;
295
291 // The paths we post to. 296 // The paths we post to.
292 std::string proto_sync_path_; 297 std::string proto_sync_path_;
293 298
294 // The auth token to use in authenticated requests. 299 // The auth token to use in authenticated requests.
295 std::string auth_token_; 300 std::string auth_token_;
296 301
297 // The time at which this auth token was last created/refreshed.
298 // Used for histogramming.
299 base::Time auth_token_time_;
300
301 // The previous auth token that is invalid now. 302 // The previous auth token that is invalid now.
302 std::string previously_invalidated_token; 303 std::string previously_invalidated_token;
303 304
304 ObserverList<ServerConnectionEventListener> listeners_; 305 ObserverList<ServerConnectionEventListener> listeners_;
305 306
306 HttpResponse::ServerConnectionCode server_status_; 307 HttpResponse::ServerConnectionCode server_status_;
307 308
308 base::ThreadChecker thread_checker_; 309 base::ThreadChecker thread_checker_;
309 310
310 // Protects all variables below to allow bailing out of active connections. 311 // Protects all variables below to allow bailing out of active connections.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 void NotifyStatusChanged(); 343 void NotifyStatusChanged();
343 344
344 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager); 345 DISALLOW_COPY_AND_ASSIGN(ServerConnectionManager);
345 }; 346 };
346 347
347 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr); 348 std::ostream& operator<<(std::ostream& s, const struct HttpResponse& hr);
348 349
349 } // namespace syncer 350 } // namespace syncer
350 351
351 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_ 352 #endif // SYNC_ENGINE_NET_SERVER_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « jingle/notifier/base/notifier_options_util.cc ('k') | sync/engine/net/server_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698