Commit d8bf9846 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Deduplicated or renamed supervised_user variables

This is a preparatory patch for jumbo compilations where several
cc files are compiled in the same translation unit. Then you get
compilation errors if they all define their own kNumRetries and
kBackoffPolicy, kApiPath and so on.

This patch gives the 5 different kNumRetries variables and 3
different kBackoffPolicy variables in chrome/browser
their own name. It also renames kApiPath, kApiUrl and kApiScope.

It also deduplicates a kAuthorizationHeaderFormat string that had
4 different instances.

Bug: 746957
Change-Id: Ib14ccaa372d3b28cd505b2e7cec519a5635e3173
Reviewed-on: https://chromium-review.googlesource.com/868335Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarPaul Jensen <pauljensen@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#534084}
parent a76d24bc
......@@ -18,7 +18,7 @@
using net::URLFetcher;
const int kNumRetries = 1;
const int kNumFileDownloaderRetries = 1;
FileDownloader::FileDownloader(
const GURL& url,
......@@ -35,7 +35,7 @@ FileDownloader::FileDownloader(
fetcher_->SetRequestContext(request_context);
fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumFileDownloaderRetries);
fetcher_->SaveResponseToTemporaryFile(
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
......
......@@ -17,7 +17,7 @@ namespace offline_pages {
namespace {
const int kDefaultSuspensionDays = 1;
const net::BackoffEntry::Policy kBackoffPolicy = {
const net::BackoffEntry::Policy kPrefetchBackoffPolicy = {
0, // Number of initial errors to ignore without backoff.
30 * 1000, // Initial delay for backoff in ms: 30 seconds.
2, // Factor to multiply for exponential backoff.
......@@ -59,10 +59,10 @@ PrefetchBackgroundTaskHandlerImpl::GetCurrentBackoff() const {
std::unique_ptr<net::BackoffEntry> result;
if (value) {
result = net::BackoffEntrySerializer::DeserializeFromValue(
*value, &kBackoffPolicy, clock_, base::Time::Now());
*value, &kPrefetchBackoffPolicy, clock_, base::Time::Now());
}
if (!result)
return base::MakeUnique<net::BackoffEntry>(&kBackoffPolicy, clock_);
return base::MakeUnique<net::BackoffEntry>(&kPrefetchBackoffPolicy, clock_);
return result;
}
......
......@@ -32,7 +32,8 @@ using net::URLRequestStatus;
namespace {
const char kApiUrl[] = "https://safesearch.googleapis.com/v1:classify";
const char kSafeSearchApiUrl[] =
"https://safesearch.googleapis.com/v1:classify";
const char kDataContentType[] = "application/x-www-form-urlencoded";
const char kDataFormat[] = "key=%s&urls=%s";
......@@ -52,8 +53,9 @@ std::unique_ptr<net::URLFetcher> CreateFetcher(
const std::string& api_key,
const GURL& url,
const net::NetworkTrafficAnnotationTag& traffic_annotation) {
std::unique_ptr<net::URLFetcher> fetcher = URLFetcher::Create(
0, GURL(kApiUrl), URLFetcher::POST, delegate, traffic_annotation);
std::unique_ptr<net::URLFetcher> fetcher =
URLFetcher::Create(0, GURL(kSafeSearchApiUrl), URLFetcher::POST, delegate,
traffic_annotation);
fetcher->SetUploadData(kDataContentType, BuildRequestData(api_key, url));
fetcher->SetRequestContext(context);
fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
......
......@@ -30,7 +30,7 @@
namespace {
const char kApiPath[] = "/async/newtab_ogb";
const char kNewTabOgbApiPath[] = "/async/newtab_ogb";
const char kResponsePreamble[] = ")]}'";
......@@ -181,7 +181,8 @@ OneGoogleBarFetcherImpl::AuthenticatedURLFetcher::AuthenticatedURLFetcher(
callback_(std::move(callback)) {}
GURL OneGoogleBarFetcherImpl::AuthenticatedURLFetcher::GetApiUrl() const {
GURL api_url = google_base_url_.Resolve(api_url_override_.value_or(kApiPath));
GURL api_url =
google_base_url_.Resolve(api_url_override_.value_or(kNewTabOgbApiPath));
// Add the "hl=" parameter.
api_url = net::AppendQueryParameter(api_url, "hl", application_locale_);
......
......@@ -15,7 +15,7 @@
#include "google_apis/gaia/gaia_constants.h"
namespace {
const net::BackoffEntry::Policy kBackoffPolicy = {
const net::BackoffEntry::Policy kForceSigninVerifierBackoffPolicy = {
0, // Number of initial errors to ignore before applying
// exponential back-off rules.
2000, // Initial delay in ms.
......@@ -38,7 +38,7 @@ const char kForceSigninVerificationFailureTimeMetricsName[] =
ForceSigninVerifier::ForceSigninVerifier(Profile* profile)
: OAuth2TokenService::Consumer("force_signin_verifier"),
has_token_verified_(false),
backoff_entry_(&kBackoffPolicy),
backoff_entry_(&kForceSigninVerifierBackoffPolicy),
creation_time_(base::TimeTicks::Now()),
oauth2_token_service_(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)),
......
......@@ -49,36 +49,36 @@ const int kUpdateIntervalSeconds = 60 * 60 * 24;
// In case of an error while getting the family info, retry with exponential
// backoff.
const net::BackoffEntry::Policy kBackoffPolicy = {
// Number of initial errors (in sequence) to ignore before applying
// exponential back-off rules.
0,
const net::BackoffEntry::Policy kFamilyFetchBackoffPolicy = {
// Number of initial errors (in sequence) to ignore before applying
// exponential back-off rules.
0,
// Initial delay for exponential backoff in ms.
2000,
// Initial delay for exponential backoff in ms.
2000,
// Factor by which the waiting time will be multiplied.
2,
// Factor by which the waiting time will be multiplied.
2,
// Fuzzing percentage. ex: 10% will spread requests randomly
// between 90%-100% of the calculated time.
0.2, // 20%
// Fuzzing percentage. ex: 10% will spread requests randomly
// between 90%-100% of the calculated time.
0.2, // 20%
// Maximum amount of time we are willing to delay our request in ms.
1000 * 60 * 60 * 4, // 4 hours.
// Maximum amount of time we are willing to delay our request in ms.
1000 * 60 * 60 * 4, // 4 hours.
// Time to keep an entry from being discarded even when it
// has no significant state, -1 to never discard.
-1,
// Time to keep an entry from being discarded even when it
// has no significant state, -1 to never discard.
-1,
// Don't use initial delay unless the last request was an error.
false,
// Don't use initial delay unless the last request was an error.
false,
};
ChildAccountService::ChildAccountService(Profile* profile)
: profile_(profile),
active_(false),
family_fetch_backoff_(&kBackoffPolicy),
family_fetch_backoff_(&kFamilyFetchBackoffPolicy),
sync_service_observer_(this),
gaia_cookie_manager_(
GaiaCookieManagerServiceFactory::GetForProfile(profile)),
......
......@@ -11,6 +11,7 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/supervised_user/child_accounts/kids_management_api.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
......@@ -21,8 +22,7 @@
const char kGetFamilyProfileApiPath[] = "families/mine?alt=json";
const char kGetFamilyMembersApiPath[] = "families/mine/members?alt=json";
const char kScope[] = "https://www.googleapis.com/auth/kid.family.readonly";
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
const int kNumRetries = 1;
const int kNumFamilyInfoFetcherRetries = 1;
const char kIdFamily[] = "family";
const char kIdFamilyId[] = "familyId";
......@@ -204,9 +204,10 @@ void FamilyInfoFetcher::OnGetTokenSuccess(
url_fetcher_->SetRequestContext(request_context_);
url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
url_fetcher_->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(
kNumFamilyInfoFetcherRetries);
url_fetcher_->AddExtraRequestHeader(base::StringPrintf(
supervised_users::kAuthorizationHeaderFormat, access_token.c_str()));
url_fetcher_->Start();
}
......
......@@ -16,6 +16,7 @@
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/supervised_user/child_accounts/kids_management_api.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/common/chrome_switches.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
......@@ -32,12 +33,11 @@
using net::URLFetcher;
const char kApiPath[] = "people/me/permissionRequests";
const char kApiScope[] = "https://www.googleapis.com/auth/kid.permission";
const char kPermissionRequestApiPath[] = "people/me/permissionRequests";
const char kPermissionRequestApiScope[] =
"https://www.googleapis.com/auth/kid.permission";
const int kNumRetries = 1;
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
const int kNumPermissionRequestRetries = 1;
// Request keys.
const char kEventTypeKey[] = "eventType";
......@@ -141,7 +141,7 @@ GURL PermissionRequestCreatorApiary::GetApiUrl() const {
return url;
}
return kids_management_api::GetURL(kApiPath);
return kids_management_api::GetURL(kPermissionRequestApiPath);
}
std::string PermissionRequestCreatorApiary::GetApiScope() const {
......@@ -150,7 +150,7 @@ std::string PermissionRequestCreatorApiary::GetApiScope() const {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kPermissionRequestApiScope);
} else {
return kApiScope;
return kPermissionRequestApiScope;
}
}
......@@ -219,9 +219,10 @@ void PermissionRequestCreatorApiary::OnGetTokenSuccess(
(*it)->url_fetcher->SetRequestContext(context_);
(*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
(*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
(*it)->url_fetcher->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
(*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(
kNumPermissionRequestRetries);
(*it)->url_fetcher->AddExtraRequestHeader(base::StringPrintf(
supervised_users::kAuthorizationHeaderFormat, access_token.c_str()));
base::DictionaryValue dict;
dict.SetKey(kEventTypeKey, base::Value((*it)->request_type));
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
......@@ -26,12 +27,12 @@
using net::URLFetcher;
const char kApiUrl[] = "https://safesearch.googleapis.com/v1:report";
const char kApiScope[] = "https://www.googleapis.com/auth/safesearch.reporting";
const char kSafeSearchReportApiUrl[] =
"https://safesearch.googleapis.com/v1:report";
const char kSafeSearchReportApiScope[] =
"https://www.googleapis.com/auth/safesearch.reporting";
const int kNumRetries = 1;
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
const int kNumSafeSearchReportRetries = 1;
struct SafeSearchURLReporter::Report {
Report(const GURL& url, const SuccessCallback& callback, int url_fetcher_id);
......@@ -87,7 +88,7 @@ void SafeSearchURLReporter::ReportUrl(const GURL& url,
void SafeSearchURLReporter::StartFetching(Report* report) {
OAuth2TokenService::ScopeSet scopes;
scopes.insert(kApiScope);
scopes.insert(kSafeSearchReportApiScope);
report->access_token_request =
oauth2_token_service_->StartRequest(account_id_, scopes, this);
}
......@@ -132,8 +133,8 @@ void SafeSearchURLReporter::OnGetTokenSuccess(
}
})");
(*it)->url_fetcher =
URLFetcher::Create((*it)->url_fetcher_id, GURL(kApiUrl), URLFetcher::POST,
this, traffic_annotation);
URLFetcher::Create((*it)->url_fetcher_id, GURL(kSafeSearchReportApiUrl),
URLFetcher::POST, this, traffic_annotation);
data_use_measurement::DataUseUserData::AttachToFetcher(
(*it)->url_fetcher.get(),
......@@ -141,9 +142,10 @@ void SafeSearchURLReporter::OnGetTokenSuccess(
(*it)->url_fetcher->SetRequestContext(context_);
(*it)->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
(*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
(*it)->url_fetcher->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
(*it)->url_fetcher->SetAutomaticallyRetryOnNetworkChanges(
kNumSafeSearchReportRetries);
(*it)->url_fetcher->AddExtraRequestHeader(base::StringPrintf(
supervised_users::kAuthorizationHeaderFormat, access_token.c_str()));
base::DictionaryValue dict;
dict.SetKey("url", base::Value((*it)->url.spec()));
......@@ -189,7 +191,7 @@ void SafeSearchURLReporter::OnURLFetchComplete(const URLFetcher* source) {
if (response_code == net::HTTP_UNAUTHORIZED && !(*it)->access_token_expired) {
(*it)->access_token_expired = true;
OAuth2TokenService::ScopeSet scopes;
scopes.insert(kApiScope);
scopes.insert(kSafeSearchReportApiScope);
oauth2_token_service_->InvalidateAccessToken(account_id_, scopes,
(*it)->access_token);
StartFetching((*it).get());
......
......@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_oauth_client.h"
......@@ -32,7 +33,7 @@ using net::URLRequestContextGetter;
namespace {
const int kNumRetries = 1;
const int kNumRefreshTokenRetries = 1;
static const char kIssueTokenBodyFormat[] =
"client_id=%s"
......@@ -49,9 +50,6 @@ static const char kIssueTokenBodyFormat[] =
static const char kIssueTokenBodyFormatDeviceIdAddendum[] =
"&device_id=%s&lib_ver=supervised_user";
static const char kAuthorizationHeaderFormat[] =
"Authorization: Bearer %s";
static const char kCodeKey[] = "code";
class SupervisedUserRefreshTokenFetcherImpl
......@@ -202,9 +200,9 @@ void SupervisedUserRefreshTokenFetcherImpl::OnGetTokenSuccess(
url_fetcher_->SetRequestContext(context_);
url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRetries);
url_fetcher_->AddExtraRequestHeader(
base::StringPrintf(kAuthorizationHeaderFormat, access_token.c_str()));
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(kNumRefreshTokenRetries);
url_fetcher_->AddExtraRequestHeader(base::StringPrintf(
supervised_users::kAuthorizationHeaderFormat, access_token.c_str()));
std::string body = base::StringPrintf(
kIssueTokenBodyFormat,
......@@ -276,8 +274,8 @@ void SupervisedUserRefreshTokenFetcherImpl::OnURLFetchComplete(
client_info.client_id = urls->oauth2_chrome_client_id();
client_info.client_secret = urls->oauth2_chrome_client_secret();
gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(context_));
gaia_oauth_client_->GetTokensFromAuthCode(client_info, auth_code, kNumRetries,
this);
gaia_oauth_client_->GetTokensFromAuthCode(client_info, auth_code,
kNumRefreshTokenRetries, this);
}
void SupervisedUserRefreshTokenFetcherImpl::OnGetTokensResponse(
......
......@@ -11,6 +11,7 @@ const char kAccountConsistencyMirrorRequired[] =
"AccountConsistencyMirrorRequired";
#endif
const char kApprovedExtensions[] = "ApprovedExtensions";
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
const char kCameraMicDisabled[] = "CameraMicDisabled";
const char kContentPackDefaultFilteringBehavior[] =
"ContentPackDefaultFilteringBehavior";
......
......@@ -13,6 +13,7 @@ namespace supervised_users {
extern const char kAccountConsistencyMirrorRequired[];
#endif
extern const char kApprovedExtensions[];
extern const char kAuthorizationHeaderFormat[];
extern const char kCameraMicDisabled[];
extern const char kContentPackDefaultFilteringBehavior[];
extern const char kContentPackManualBehaviorHosts[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment