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

Side by Side Diff: chrome/browser/sync/engine/net/server_connection_manager.cc

Issue 9251035: Delete lots of sync ServerConnectionManager code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 5 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 if (post.get()->ReadBufferResponse( 260 if (post.get()->ReadBufferResponse(
261 &params->buffer_out, &params->response, true)) { 261 &params->buffer_out, &params->response, true)) {
262 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK; 262 params->response.server_status = HttpResponse::SERVER_CONNECTION_OK;
263 server_reachable_ = true; 263 server_reachable_ = true;
264 return true; 264 return true;
265 } 265 }
266 return false; 266 return false;
267 } 267 }
268 268
269 bool ServerConnectionManager::CheckTime(int32* out_time) {
270 DCHECK(thread_checker_.CalledOnValidThread());
271
272 // Verify that the server really is reachable by checking the time. We need
273 // to do this because of wifi interstitials that intercept messages from the
274 // client and return HTTP OK instead of a redirect.
275 HttpResponse response;
276 ScopedServerStatusWatcher watcher(this, &response);
277 string post_body = "command=get_time";
278
279 for (int i = 0 ; i < 3; i++) {
280 ScopedConnectionHelper post(this, MakeActiveConnection());
281 if (!post.get())
282 break;
283
284 // Note that the server's get_time path doesn't require authentication.
285 string get_time_path =
286 MakeSyncServerPath(kSyncServerGetTimePath, post_body);
287 DVLOG(1) << "Requesting get_time from:" << get_time_path;
288
289 string blank_post_body;
290 bool ok = post.get()->Init(get_time_path.c_str(), blank_post_body,
291 blank_post_body, &response);
292 if (!ok) {
293 DVLOG(1) << "Unable to check the time";
294 continue;
295 }
296 string time_response;
297 time_response.resize(
298 static_cast<string::size_type>(response.content_length));
299 ok = post.get()->ReadDownloadResponse(&response, &time_response);
300 if (!ok || string::npos !=
301 time_response.find_first_not_of("0123456789")) {
302 LOG(ERROR) << "unable to read a non-numeric response from get_time:"
303 << time_response;
304 continue;
305 }
306 *out_time = atoi(time_response.c_str());
307 DVLOG(1) << "Server was reachable.";
308 return true;
309 }
310 return false;
311 }
312
313 bool ServerConnectionManager::IsServerReachable() {
314 DCHECK(thread_checker_.CalledOnValidThread());
315 int32 time;
316 return CheckTime(&time);
317 }
318
319 bool ServerConnectionManager::IsUserAuthenticated() {
320 DCHECK(thread_checker_.CalledOnValidThread());
321 return IsGoodReplyFromServer(server_status_);
322 }
323
324 bool ServerConnectionManager::CheckServerReachable() {
325 DCHECK(thread_checker_.CalledOnValidThread());
326 const bool server_is_reachable = IsServerReachable();
327 if (server_reachable_ != server_is_reachable) {
328 server_reachable_ = server_is_reachable;
329 NotifyStatusChanged();
330 }
331 return server_is_reachable;
332 }
333
334 void ServerConnectionManager::SetServerParameters(const string& server_url,
335 int port,
336 bool use_ssl) {
337 DCHECK(thread_checker_.CalledOnValidThread());
338 sync_server_ = server_url;
339 sync_server_port_ = port;
340 use_ssl_ = use_ssl;
341 }
342
343 // Returns the current server parameters in server_url and port. 269 // Returns the current server parameters in server_url and port.
344 void ServerConnectionManager::GetServerParameters(string* server_url, 270 void ServerConnectionManager::GetServerParameters(string* server_url,
345 int* port, 271 int* port,
346 bool* use_ssl) const { 272 bool* use_ssl) const {
347 if (server_url != NULL) 273 if (server_url != NULL)
348 *server_url = sync_server_; 274 *server_url = sync_server_;
349 if (port != NULL) 275 if (port != NULL)
350 *port = sync_server_port_; 276 *port = sync_server_port_;
351 if (use_ssl != NULL) 277 if (use_ssl != NULL)
352 *use_ssl = use_ssl_; 278 *use_ssl = use_ssl_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 337 }
412 338
413 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) { 339 std::ostream& operator << (std::ostream& s, const struct HttpResponse& hr) {
414 s << " Response Code (bogus on error): " << hr.response_code; 340 s << " Response Code (bogus on error): " << hr.response_code;
415 s << " Content-Length (bogus on error): " << hr.content_length; 341 s << " Content-Length (bogus on error): " << hr.content_length;
416 s << " Server Status: " << hr.server_status; 342 s << " Server Status: " << hr.server_status;
417 return s; 343 return s;
418 } 344 }
419 345
420 } // namespace browser_sync 346 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698