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

Side by Side Diff: chrome/service/cloud_print/cloud_print_proxy_backend.cc

Issue 4194001: Implement exponential back-off mechanism and enforce it at the URLRequestHttpJob level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/service/cloud_print/cloud_print_proxy_backend.h" 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/md5.h" 11 #include "base/md5.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_split.h" 14 #include "base/string_split.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/net/url_fetcher_protect.h"
19 #include "chrome/service/cloud_print/cloud_print_consts.h" 18 #include "chrome/service/cloud_print/cloud_print_consts.h"
20 #include "chrome/service/cloud_print/cloud_print_helpers.h" 19 #include "chrome/service/cloud_print/cloud_print_helpers.h"
21 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" 20 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h"
22 #include "chrome/service/cloud_print/printer_job_handler.h" 21 #include "chrome/service/cloud_print/printer_job_handler.h"
23 #include "chrome/service/gaia/service_gaia_authenticator.h" 22 #include "chrome/service/gaia/service_gaia_authenticator.h"
24 #include "chrome/service/service_process.h" 23 #include "chrome/service/service_process.h"
25 #include "googleurl/src/gurl.h" 24 #include "googleurl/src/gurl.h"
26 #include "jingle/notifier/base/notifier_options.h" 25 #include "jingle/notifier/base/notifier_options.h"
27 #include "jingle/notifier/listener/push_notifications_thread.h" 26 #include "jingle/notifier/listener/push_notifications_thread.h"
28 #include "jingle/notifier/listener/talk_mediator_impl.h" 27 #include "jingle/notifier/listener/talk_mediator_impl.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // NotifyXXX is how the Core communicates with the frontend across 111 // NotifyXXX is how the Core communicates with the frontend across
113 // threads. 112 // threads.
114 void NotifyPrinterListAvailable( 113 void NotifyPrinterListAvailable(
115 const printing::PrinterList& printer_list); 114 const printing::PrinterList& printer_list);
116 void NotifyAuthenticated( 115 void NotifyAuthenticated(
117 const std::string& cloud_print_token, 116 const std::string& cloud_print_token,
118 const std::string& cloud_print_xmpp_token, 117 const std::string& cloud_print_xmpp_token,
119 const std::string& email); 118 const std::string& email);
120 void NotifyAuthenticationFailed(); 119 void NotifyAuthenticationFailed();
121 120
122 URLFetcherProtectEntry* CreateDefaultRetryPolicy();
123
124 // Starts a new printer registration process. 121 // Starts a new printer registration process.
125 void StartRegistration(); 122 void StartRegistration();
126 // Ends the printer registration process. 123 // Ends the printer registration process.
127 void EndRegistration(); 124 void EndRegistration();
128 // Registers printer capabilities and defaults for the next printer in the 125 // Registers printer capabilities and defaults for the next printer in the
129 // list with the cloud print server. 126 // list with the cloud print server.
130 void RegisterNextPrinter(); 127 void RegisterNextPrinter();
131 // Retrieves the list of registered printers for this user/proxy combination 128 // Retrieves the list of registered printers for this user/proxy combination
132 // from the cloud print server. 129 // from the cloud print server.
133 void GetRegisteredPrinters(); 130 void GetRegisteredPrinters();
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 talk_mediator_->SetDelegate(this); 344 talk_mediator_->SetDelegate(this);
348 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, 345 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token,
349 kSyncGaiaServiceId); 346 kSyncGaiaServiceId);
350 talk_mediator_->Login(); 347 talk_mediator_->Login();
351 348
352 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); 349 print_server_watcher_ = print_system_->CreatePrintServerWatcher();
353 print_server_watcher_->StartWatching(this); 350 print_server_watcher_->StartWatching(this);
354 351
355 proxy_id_ = proxy_id; 352 proxy_id_ = proxy_id;
356 353
357 // Register the request retry policies for cloud print APIs and job data
358 // requests.
359 URLFetcherProtectManager::GetInstance()->Register(
360 kCloudPrintAPIRetryPolicy, CreateDefaultRetryPolicy());
361 URLFetcherProtectManager::GetInstance()->Register(
362 kJobDataRetryPolicy, CreateDefaultRetryPolicy())->SetMaxRetries(
363 kJobDataMaxRetryCount);
364
365 StartRegistration(); 354 StartRegistration();
366 } 355 }
367 356
368 URLFetcherProtectEntry*
369 CloudPrintProxyBackend::Core::CreateDefaultRetryPolicy() {
370 // Times are in milliseconds.
371 const int kSlidingWindowPeriod = 2000;
372 const int kMaxSendThreshold = 20;
373 const int kMaxRetries = -1;
374 const int kInitialTimeout = 100;
375 const double kMultiplier = 2.0;
376 const int kConstantFactor = 100;
377 const int kMaximumTimeout = 5*60*1000;
378 return new URLFetcherProtectEntry(kSlidingWindowPeriod,
379 kMaxSendThreshold,
380 kMaxRetries,
381 kInitialTimeout,
382 kMultiplier,
383 kConstantFactor,
384 kMaximumTimeout);
385 }
386
387 void CloudPrintProxyBackend::Core::StartRegistration() { 357 void CloudPrintProxyBackend::Core::StartRegistration() {
388 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 358 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
389 printer_list_.clear(); 359 printer_list_.clear();
390 print_system_->EnumeratePrinters(&printer_list_); 360 print_system_->EnumeratePrinters(&printer_list_);
391 // Now we need to ask the server about printers that were registered on the 361 // Now we need to ask the server about printers that were registered on the
392 // server so that we can trim this list. 362 // server so that we can trim this list.
393 GetRegisteredPrinters(); 363 GetRegisteredPrinters();
394 } 364 }
395 365
396 void CloudPrintProxyBackend::Core::EndRegistration() { 366 void CloudPrintProxyBackend::Core::EndRegistration() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 404
435 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { 405 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() {
436 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 406 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
437 GURL printer_list_url = 407 GURL printer_list_url =
438 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, 408 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_,
439 proxy_id_); 409 proxy_id_);
440 next_response_handler_ = 410 next_response_handler_ =
441 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; 411 &CloudPrintProxyBackend::Core::HandlePrinterListResponse;
442 request_ = new CloudPrintURLFetcher; 412 request_ = new CloudPrintURLFetcher;
443 request_->StartGetRequest(printer_list_url, this, auth_token_, 413 request_->StartGetRequest(printer_list_url, this, auth_token_,
444 kCloudPrintAPIRetryPolicy); 414 kCloudPrintAPIMaxRetryCount);
445 } 415 }
446 416
447 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { 417 void CloudPrintProxyBackend::Core::RegisterNextPrinter() {
448 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 418 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
449 // For the next printer to be uploaded, create a multi-part post request to 419 // For the next printer to be uploaded, create a multi-part post request to
450 // upload the printer capabilities and the printer defaults. 420 // upload the printer capabilities and the printer defaults.
451 if (next_upload_index_ < printer_list_.size()) { 421 if (next_upload_index_ < printer_list_.size()) {
452 const printing::PrinterBasicInfo& info = 422 const printing::PrinterBasicInfo& info =
453 printer_list_.at(next_upload_index_); 423 printer_list_.at(next_upload_index_);
454 bool have_printer_info = true; 424 bool have_printer_info = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 post_data.append("--" + mime_boundary + "--\r\n"); 471 post_data.append("--" + mime_boundary + "--\r\n");
502 std::string mime_type("multipart/form-data; boundary="); 472 std::string mime_type("multipart/form-data; boundary=");
503 mime_type += mime_boundary; 473 mime_type += mime_boundary;
504 GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration( 474 GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration(
505 cloud_print_server_url_); 475 cloud_print_server_url_);
506 476
507 next_response_handler_ = 477 next_response_handler_ =
508 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; 478 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse;
509 request_ = new CloudPrintURLFetcher; 479 request_ = new CloudPrintURLFetcher;
510 request_->StartPostRequest(register_url, this, auth_token_, 480 request_->StartPostRequest(register_url, this, auth_token_,
511 kCloudPrintAPIRetryPolicy, mime_type, 481 kCloudPrintAPIMaxRetryCount, mime_type,
512 post_data); 482 post_data);
513 483
514 } else { 484 } else {
515 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << 485 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " <<
516 info.printer_name; 486 info.printer_name;
517 next_upload_index_++; 487 next_upload_index_++;
518 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, 488 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
519 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); 489 &CloudPrintProxyBackend::Core::RegisterNextPrinter));
520 } 490 }
521 } else { 491 } else {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; 736 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id;
767 job_handler_map_.erase(printer_id); 737 job_handler_map_.erase(printer_id);
768 } 738 }
769 739
770 void CloudPrintProxyBackend::Core::OnAuthError() { 740 void CloudPrintProxyBackend::Core::OnAuthError() {
771 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 741 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
772 VLOG(1) << "CP_PROXY: Auth Error"; 742 VLOG(1) << "CP_PROXY: Auth Error";
773 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 743 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
774 &Core::NotifyAuthenticationFailed)); 744 &Core::NotifyAuthenticationFailed));
775 } 745 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698