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

Side by Side Diff: chrome/browser/local_discovery/privet_http_impl.cc

Issue 69393003: Add minimum timeout for transient errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/local_discovery/privet_http_impl.h" 5 #include "chrome/browser/local_discovery/privet_http_impl.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/rand_util.h" 11 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/local_discovery/privet_constants.h" 13 #include "chrome/browser/local_discovery/privet_constants.h"
12 #include "net/base/url_util.h" 14 #include "net/base/url_util.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 16
15 namespace local_discovery { 17 namespace local_discovery {
16 18
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 invalid_job_retries_++; 544 invalid_job_retries_++;
543 545
544 int timeout = kPrivetLocalPrintDefaultTimeout; 546 int timeout = kPrivetLocalPrintDefaultTimeout;
545 value->GetInteger(kPrivetKeyTimeout, &timeout); 547 value->GetInteger(kPrivetKeyTimeout, &timeout);
546 548
547 double random_scaling_factor = 549 double random_scaling_factor =
548 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; 550 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition;
549 551
550 timeout = static_cast<int>(timeout * random_scaling_factor); 552 timeout = static_cast<int>(timeout * random_scaling_factor);
551 553
554 timeout = std::max(timeout, kPrivetMinimumTimeout);
555
552 base::MessageLoop::current()->PostDelayedTask( 556 base::MessageLoop::current()->PostDelayedTask(
553 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob, 557 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob,
554 weak_factory_.GetWeakPtr()), 558 weak_factory_.GetWeakPtr()),
555 base::TimeDelta::FromSeconds(timeout)); 559 base::TimeDelta::FromSeconds(timeout));
556 } else { 560 } else {
557 delegate_->OnPrivetPrintingError(this, 200); 561 delegate_->OnPrivetPrintingError(this, 200);
558 } 562 }
559 563
560 return; 564 return;
561 } 565 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 TokenCallbackVector token_callbacks; 738 TokenCallbackVector token_callbacks;
735 token_callbacks_.swap(token_callbacks); 739 token_callbacks_.swap(token_callbacks);
736 740
737 for (TokenCallbackVector::iterator i = token_callbacks.begin(); 741 for (TokenCallbackVector::iterator i = token_callbacks.begin();
738 i != token_callbacks.end(); i++) { 742 i != token_callbacks.end(); i++) {
739 i->Run(token); 743 i->Run(token);
740 } 744 }
741 } 745 }
742 746
743 } // namespace local_discovery 747 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_constants.h ('k') | chrome/browser/local_discovery/privet_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698