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

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 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 talk_mediator_->SetDelegate(this); 347 talk_mediator_->SetDelegate(this);
351 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, 348 talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token,
352 kSyncGaiaServiceId); 349 kSyncGaiaServiceId);
353 talk_mediator_->Login(); 350 talk_mediator_->Login();
354 351
355 print_server_watcher_ = print_system_->CreatePrintServerWatcher(); 352 print_server_watcher_ = print_system_->CreatePrintServerWatcher();
356 print_server_watcher_->StartWatching(this); 353 print_server_watcher_->StartWatching(this);
357 354
358 proxy_id_ = proxy_id; 355 proxy_id_ = proxy_id;
359 356
360 // Register the request retry policies for cloud print APIs and job data
361 // requests.
362 URLFetcherProtectManager::GetInstance()->Register(
363 kCloudPrintAPIRetryPolicy, CreateDefaultRetryPolicy());
364 URLFetcherProtectManager::GetInstance()->Register(
365 kJobDataRetryPolicy, CreateDefaultRetryPolicy())->SetMaxRetries(
366 kJobDataMaxRetryCount);
367
368 StartRegistration(); 357 StartRegistration();
369 } 358 }
370 359
371 URLFetcherProtectEntry*
372 CloudPrintProxyBackend::Core::CreateDefaultRetryPolicy() {
373 // Times are in milliseconds.
374 const int kSlidingWindowPeriod = 2000;
375 const int kMaxSendThreshold = 20;
376 const int kMaxRetries = -1;
377 const int kInitialTimeout = 100;
378 const double kMultiplier = 2.0;
379 const int kConstantFactor = 100;
380 const int kMaximumTimeout = 5*60*1000;
381 return new URLFetcherProtectEntry(kSlidingWindowPeriod,
382 kMaxSendThreshold,
383 kMaxRetries,
384 kInitialTimeout,
385 kMultiplier,
386 kConstantFactor,
387 kMaximumTimeout);
388 }
389
390 void CloudPrintProxyBackend::Core::StartRegistration() { 360 void CloudPrintProxyBackend::Core::StartRegistration() {
391 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 361 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
392 printer_list_.clear(); 362 printer_list_.clear();
393 print_system_->EnumeratePrinters(&printer_list_); 363 print_system_->EnumeratePrinters(&printer_list_);
394 // Now we need to ask the server about printers that were registered on the 364 // Now we need to ask the server about printers that were registered on the
395 // server so that we can trim this list. 365 // server so that we can trim this list.
396 GetRegisteredPrinters(); 366 GetRegisteredPrinters();
397 } 367 }
398 368
399 void CloudPrintProxyBackend::Core::EndRegistration() { 369 void CloudPrintProxyBackend::Core::EndRegistration() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 407
438 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() { 408 void CloudPrintProxyBackend::Core::GetRegisteredPrinters() {
439 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 409 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
440 GURL printer_list_url = 410 GURL printer_list_url =
441 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_, 411 CloudPrintHelpers::GetUrlForPrinterList(cloud_print_server_url_,
442 proxy_id_); 412 proxy_id_);
443 next_response_handler_ = 413 next_response_handler_ =
444 &CloudPrintProxyBackend::Core::HandlePrinterListResponse; 414 &CloudPrintProxyBackend::Core::HandlePrinterListResponse;
445 request_ = new CloudPrintURLFetcher; 415 request_ = new CloudPrintURLFetcher;
446 request_->StartGetRequest(printer_list_url, this, auth_token_, 416 request_->StartGetRequest(printer_list_url, this, auth_token_,
447 kCloudPrintAPIRetryPolicy); 417 kCloudPrintAPIMaxRetryCount);
448 } 418 }
449 419
450 void CloudPrintProxyBackend::Core::RegisterNextPrinter() { 420 void CloudPrintProxyBackend::Core::RegisterNextPrinter() {
451 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 421 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
452 // For the next printer to be uploaded, create a multi-part post request to 422 // For the next printer to be uploaded, create a multi-part post request to
453 // upload the printer capabilities and the printer defaults. 423 // upload the printer capabilities and the printer defaults.
454 if (next_upload_index_ < printer_list_.size()) { 424 if (next_upload_index_ < printer_list_.size()) {
455 const printing::PrinterBasicInfo& info = 425 const printing::PrinterBasicInfo& info =
456 printer_list_.at(next_upload_index_); 426 printer_list_.at(next_upload_index_);
457 bool have_printer_info = true; 427 bool have_printer_info = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 post_data.append("--" + mime_boundary + "--\r\n"); 474 post_data.append("--" + mime_boundary + "--\r\n");
505 std::string mime_type("multipart/form-data; boundary="); 475 std::string mime_type("multipart/form-data; boundary=");
506 mime_type += mime_boundary; 476 mime_type += mime_boundary;
507 GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration( 477 GURL register_url = CloudPrintHelpers::GetUrlForPrinterRegistration(
508 cloud_print_server_url_); 478 cloud_print_server_url_);
509 479
510 next_response_handler_ = 480 next_response_handler_ =
511 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse; 481 &CloudPrintProxyBackend::Core::HandleRegisterPrinterResponse;
512 request_ = new CloudPrintURLFetcher; 482 request_ = new CloudPrintURLFetcher;
513 request_->StartPostRequest(register_url, this, auth_token_, 483 request_->StartPostRequest(register_url, this, auth_token_,
514 kCloudPrintAPIRetryPolicy, mime_type, 484 kCloudPrintAPIMaxRetryCount, mime_type,
515 post_data); 485 post_data);
516 486
517 } else { 487 } else {
518 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " << 488 LOG(ERROR) << "CP_PROXY: Failed to get printer info for: " <<
519 info.printer_name; 489 info.printer_name;
520 next_upload_index_++; 490 next_upload_index_++;
521 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, 491 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
522 &CloudPrintProxyBackend::Core::RegisterNextPrinter)); 492 &CloudPrintProxyBackend::Core::RegisterNextPrinter));
523 } 493 }
524 } else { 494 } else {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id; 755 VLOG(1) << "CP_PROXY: Printer job handle shutdown, id " << printer_id;
786 job_handler_map_.erase(printer_id); 756 job_handler_map_.erase(printer_id);
787 } 757 }
788 758
789 void CloudPrintProxyBackend::Core::OnAuthError() { 759 void CloudPrintProxyBackend::Core::OnAuthError() {
790 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 760 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
791 VLOG(1) << "CP_PROXY: Auth Error"; 761 VLOG(1) << "CP_PROXY: Auth Error";
792 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, 762 backend_->frontend_loop_->PostTask(FROM_HERE, NewRunnableMethod(this,
793 &Core::NotifyAuthenticationFailed)); 763 &Core::NotifyAuthenticationFailed));
794 } 764 }
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_consts.cc ('k') | chrome/service/cloud_print/cloud_print_url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698