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

Side by Side Diff: components/ntp_snippets/remote/ntp_snippets_fetcher.cc

Issue 2548343002: NTPSnippets: Set MaxRetriesOn5xx only for interactive requests. (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_snippets/remote/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 654
655 NTPSnippetsFetcher::RequestBuilder& 655 NTPSnippetsFetcher::RequestBuilder&
656 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier( 656 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier(
657 const UserClassifier& user_classifier) { 657 const UserClassifier& user_classifier) {
658 if (IsSendingUserClassEnabled()) { 658 if (IsSendingUserClassEnabled()) {
659 user_class_ = GetUserClassString(user_classifier.GetUserClass()); 659 user_class_ = GetUserClassString(user_classifier.GetUserClass());
660 } 660 }
661 return *this; 661 return *this;
662 } 662 }
663 663
664 std::unique_ptr<net::URLFetcher>
665 NTPSnippetsFetcher::RequestBuilder::PreviewURLFetcherForTesting() const {
666 return BuildURLFetcher(/*request=*/nullptr, // Can never be called anyways.
tschumann 2016/12/05 17:26:33 this is a smell. If you really need something like
fhorschig 2016/12/06 14:31:40 Removed. As noted in your last comment, this was e
667 /*headers=*/"", // Can be set later if needed.
668 /*body=*/""); // Can be set later if needed.
669 }
670
664 bool NTPSnippetsFetcher::RequestBuilder::IsSendingTopLanguagesEnabled() const { 671 bool NTPSnippetsFetcher::RequestBuilder::IsSendingTopLanguagesEnabled() const {
665 return IsBooleanParameterEnabled(kSendTopLanguagesName, 672 return IsBooleanParameterEnabled(kSendTopLanguagesName,
666 /*default_value=*/false); 673 /*default_value=*/false);
667 } 674 }
668 675
669 bool NTPSnippetsFetcher::RequestBuilder::IsSendingUserClassEnabled() const { 676 bool NTPSnippetsFetcher::RequestBuilder::IsSendingUserClassEnabled() const {
670 return IsBooleanParameterEnabled(kSendUserClassName, 677 return IsBooleanParameterEnabled(kSendUserClassName,
671 /*default_value=*/false); 678 /*default_value=*/false);
672 } 679 }
673 680
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 812 url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
806 net::LOAD_DO_NOT_SAVE_COOKIES); 813 net::LOAD_DO_NOT_SAVE_COOKIES);
807 data_use_measurement::DataUseUserData::AttachToFetcher( 814 data_use_measurement::DataUseUserData::AttachToFetcher(
808 url_fetcher.get(), data_use_measurement::DataUseUserData::NTP_SNIPPETS); 815 url_fetcher.get(), data_use_measurement::DataUseUserData::NTP_SNIPPETS);
809 816
810 url_fetcher->SetExtraRequestHeaders(headers); 817 url_fetcher->SetExtraRequestHeaders(headers);
811 url_fetcher->SetUploadData("application/json", body); 818 url_fetcher->SetUploadData("application/json", body);
812 819
813 // Fetchers are sometimes cancelled because a network change was detected. 820 // Fetchers are sometimes cancelled because a network change was detected.
814 url_fetcher->SetAutomaticallyRetryOnNetworkChanges(3); 821 url_fetcher->SetAutomaticallyRetryOnNetworkChanges(3);
815 // Try to make fetching the files bit more robust even with poor connection. 822 if (params_.interactive_request) {
816 url_fetcher->SetMaxRetriesOn5xx(3); 823 // Try to make fetching the files bit more robust even with poor connection.
824 url_fetcher->SetMaxRetriesOn5xx(2);
825 } else {
826 // Don't retry immediately if a scheduled fetch fails.
827 // TODO(fhorschig): back off for 1h (+1h jitter) and then retry.
828 url_fetcher->SetMaxRetriesOn5xx(0);
829 }
817 return url_fetcher; 830 return url_fetcher;
818 } 831 }
819 832
820 void NTPSnippetsFetcher::RequestBuilder::PrepareLanguages( 833 void NTPSnippetsFetcher::RequestBuilder::PrepareLanguages(
821 translate::LanguageModel::LanguageInfo* ui_language, 834 translate::LanguageModel::LanguageInfo* ui_language,
822 translate::LanguageModel::LanguageInfo* other_top_language) const { 835 translate::LanguageModel::LanguageInfo* other_top_language) const {
823 // TODO(jkrcal): Add language model factory for iOS and add fakes to tests so 836 // TODO(jkrcal): Add language model factory for iOS and add fakes to tests so
824 // that |language_model| is never nullptr. Remove this check and add a DCHECK 837 // that |language_model| is never nullptr. Remove this check and add a DCHECK
825 // into the constructor. 838 // into the constructor.
826 if (!language_model_ || !IsSendingTopLanguagesEnabled()) { 839 if (!language_model_ || !IsSendingTopLanguagesEnabled()) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 NOTREACHED(); 1110 NOTREACHED();
1098 return false; 1111 return false;
1099 } 1112 }
1100 1113
1101 bool NTPSnippetsFetcher::NeedsAuthentication() const { 1114 bool NTPSnippetsFetcher::NeedsAuthentication() const {
1102 return (personalization_ == Personalization::kPersonal || 1115 return (personalization_ == Personalization::kPersonal ||
1103 personalization_ == Personalization::kBoth); 1116 personalization_ == Personalization::kBoth);
1104 } 1117 }
1105 1118
1106 } // namespace ntp_snippets 1119 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698