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/868335
Reviewed-by: David Roger <droger@chromium.org>
Reviewed-by: Paul Jensen <pauljensen@chromium.org>
Reviewed-by: Cathy Li <chili@chromium.org>
Reviewed-by: Marc Treib <treib@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#534084}
diff --git a/chrome/browser/net/file_downloader.cc b/chrome/browser/net/file_downloader.cc
index 326369a..473ff271 100644
--- a/chrome/browser/net/file_downloader.cc
+++ b/chrome/browser/net/file_downloader.cc
@@ -18,7 +18,7 @@
 
 using net::URLFetcher;
 
-const int kNumRetries = 1;
+const int kNumFileDownloaderRetries = 1;
 
 FileDownloader::FileDownloader(
     const GURL& url,
@@ -35,7 +35,7 @@
   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,
diff --git a/chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.cc b/chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.cc
index 56421bd..5e00320 100644
--- a/chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.cc
+++ b/chrome/browser/offline_pages/prefetch/prefetch_background_task_handler_impl.cc
@@ -17,7 +17,7 @@
 
 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 @@
   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;
 }
 
diff --git a/chrome/browser/safe_search_api/safe_search_url_checker.cc b/chrome/browser/safe_search_api/safe_search_url_checker.cc
index 308ecff..0011b8b 100644
--- a/chrome/browser/safe_search_api/safe_search_url_checker.cc
+++ b/chrome/browser/safe_search_api/safe_search_url_checker.cc
@@ -32,7 +32,8 @@
 
 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 @@
     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 |
diff --git a/chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.cc b/chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.cc
index ff2d30b..bc0e36c 100644
--- a/chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.cc
+++ b/chrome/browser/search/one_google_bar/one_google_bar_fetcher_impl.cc
@@ -30,7 +30,7 @@
 
 namespace {
 
-const char kApiPath[] = "/async/newtab_ogb";
+const char kNewTabOgbApiPath[] = "/async/newtab_ogb";
 
 const char kResponsePreamble[] = ")]}'";
 
@@ -181,7 +181,8 @@
       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_);
diff --git a/chrome/browser/signin/force_signin_verifier.cc b/chrome/browser/signin/force_signin_verifier.cc
index bbf133f..9ed225fb 100644
--- a/chrome/browser/signin/force_signin_verifier.cc
+++ b/chrome/browser/signin/force_signin_verifier.cc
@@ -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 @@
 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)),
diff --git a/chrome/browser/supervised_user/child_accounts/child_account_service.cc b/chrome/browser/supervised_user/child_accounts/child_account_service.cc
index 308fd93..d194c43c 100644
--- a/chrome/browser/supervised_user/child_accounts/child_account_service.cc
+++ b/chrome/browser/supervised_user/child_accounts/child_account_service.cc
@@ -49,36 +49,36 @@
 
 // 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)),
diff --git a/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc b/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc
index 22d70ea..7c6cdd9b 100644
--- a/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc
+++ b/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc
@@ -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 @@
   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();
 }
diff --git a/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.cc b/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.cc
index 854d3e4..77cfdbd 100644
--- a/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.cc
+++ b/chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.cc
@@ -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 @@
     return url;
   }
 
-  return kids_management_api::GetURL(kApiPath);
+  return kids_management_api::GetURL(kPermissionRequestApiPath);
 }
 
 std::string PermissionRequestCreatorApiary::GetApiScope() const {
@@ -150,7 +150,7 @@
     return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
         switches::kPermissionRequestApiScope);
   } else {
-    return kApiScope;
+    return kPermissionRequestApiScope;
   }
 }
 
@@ -219,9 +219,10 @@
   (*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));
diff --git a/chrome/browser/supervised_user/experimental/safe_search_url_reporter.cc b/chrome/browser/supervised_user/experimental/safe_search_url_reporter.cc
index d0038964..9634e5c 100644
--- a/chrome/browser/supervised_user/experimental/safe_search_url_reporter.cc
+++ b/chrome/browser/supervised_user/experimental/safe_search_url_reporter.cc
@@ -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::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 @@
           }
         })");
   (*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 @@
   (*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 @@
   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());
diff --git a/chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fetcher.cc b/chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fetcher.cc
index 2347d04..d1ab18f 100644
--- a/chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fetcher.cc
+++ b/chrome/browser/supervised_user/legacy/supervised_user_refresh_token_fetcher.cc
@@ -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 @@
 
 namespace {
 
-const int kNumRetries = 1;
+const int kNumRefreshTokenRetries = 1;
 
 static const char kIssueTokenBodyFormat[] =
     "client_id=%s"
@@ -49,9 +50,6 @@
 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 @@
   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 @@
   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(
diff --git a/chrome/browser/supervised_user/supervised_user_constants.cc b/chrome/browser/supervised_user/supervised_user_constants.cc
index b570a7b..779d449 100644
--- a/chrome/browser/supervised_user/supervised_user_constants.cc
+++ b/chrome/browser/supervised_user/supervised_user_constants.cc
@@ -11,6 +11,7 @@
     "AccountConsistencyMirrorRequired";
 #endif
 const char kApprovedExtensions[] = "ApprovedExtensions";
+const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
 const char kCameraMicDisabled[] = "CameraMicDisabled";
 const char kContentPackDefaultFilteringBehavior[] =
     "ContentPackDefaultFilteringBehavior";
diff --git a/chrome/browser/supervised_user/supervised_user_constants.h b/chrome/browser/supervised_user/supervised_user_constants.h
index 508fac8..222e849 100644
--- a/chrome/browser/supervised_user/supervised_user_constants.h
+++ b/chrome/browser/supervised_user/supervised_user_constants.h
@@ -13,6 +13,7 @@
 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[];