Update endpoint URLs for the kids management API

Also make them configurable via a variation param.

BUG=678958

Review-Url: https://codereview.chromium.org/2655313002
Cr-Commit-Position: refs/heads/master@{#446647}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 33250439..443d291 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -3673,6 +3673,8 @@
       "supervised_user/child_accounts/child_account_service_factory.h",
       "supervised_user/child_accounts/family_info_fetcher.cc",
       "supervised_user/child_accounts/family_info_fetcher.h",
+      "supervised_user/child_accounts/kids_management_api.cc",
+      "supervised_user/child_accounts/kids_management_api.h",
       "supervised_user/child_accounts/permission_request_creator_apiary.cc",
       "supervised_user/child_accounts/permission_request_creator_apiary.h",
       "supervised_user/experimental/safe_search_url_reporter.cc",
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 3f20b35..28fbabb7 100644
--- a/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc
+++ b/chrome/browser/supervised_user/child_accounts/family_info_fetcher.cc
@@ -10,15 +10,15 @@
 #include "base/macros.h"
 #include "base/strings/stringprintf.h"
 #include "base/values.h"
+#include "chrome/browser/supervised_user/child_accounts/kids_management_api.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"
 #include "net/url_request/url_request_status.h"
 #include "url/gurl.h"
 
-const char kFamilyApiUrl[] = "https://www.googleapis.com/kidsmanagement/v1/";
-const char kGetFamilyProfileApiSuffix[] = "families/mine?alt=json";
-const char kGetFamilyMembersApiSuffix[] = "families/mine/members?alt=json";
+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;
@@ -89,7 +89,6 @@
       account_id_(account_id),
       token_service_(token_service),
       request_context_(request_context),
-      request_type_(net::URLFetcher::GET),
       access_token_expired_(false) {
 }
 
@@ -118,14 +117,12 @@
 }
 
 void FamilyInfoFetcher::StartGetFamilyProfile() {
-  request_suffix_ = kGetFamilyProfileApiSuffix;
-  request_type_ = net::URLFetcher::GET;
+  request_path_ = kGetFamilyProfileApiPath;
   StartFetching();
 }
 
 void FamilyInfoFetcher::StartGetFamilyMembers() {
-  request_suffix_ = kGetFamilyMembersApiSuffix;
-  request_type_ = net::URLFetcher::GET;
+  request_path_ = kGetFamilyMembersApiPath;
   StartFetching();
 }
 
@@ -141,8 +138,8 @@
 void FamilyInfoFetcher::StartFetchingAccessToken() {
   OAuth2TokenService::ScopeSet scopes;
   scopes.insert(kScope);
-  access_token_request_ = token_service_->StartRequest(
-    account_id_, scopes, this);
+  access_token_request_ =
+      token_service_->StartRequest(account_id_, scopes, this);
 }
 
 void FamilyInfoFetcher::OnRefreshTokenAvailable(
@@ -172,9 +169,9 @@
   DCHECK_EQ(access_token_request_.get(), request);
   access_token_ = access_token;
 
-  GURL url(kFamilyApiUrl + request_suffix_);
+  GURL url = kids_management_api::GetURL(request_path_);
   const int id = 0;
-  url_fetcher_ = net::URLFetcher::Create(id, url, request_type_, this);
+  url_fetcher_ = net::URLFetcher::Create(id, url, net::URLFetcher::GET, this);
 
   data_use_measurement::DataUseUserData::AttachToFetcher(
       url_fetcher_.get(),
@@ -226,9 +223,9 @@
   std::string response_body;
   source->GetResponseAsString(&response_body);
 
-  if (request_suffix_ == kGetFamilyProfileApiSuffix) {
+  if (request_path_ == kGetFamilyProfileApiPath) {
     FamilyProfileFetched(response_body);
-  } else if (request_suffix_ == kGetFamilyMembersApiSuffix) {
+  } else if (request_path_ == kGetFamilyMembersApiPath) {
     FamilyMembersFetched(response_body);
   } else {
     NOTREACHED();
diff --git a/chrome/browser/supervised_user/child_accounts/family_info_fetcher.h b/chrome/browser/supervised_user/child_accounts/family_info_fetcher.h
index a2e61c0..2adb0b06 100644
--- a/chrome/browser/supervised_user/child_accounts/family_info_fetcher.h
+++ b/chrome/browser/supervised_user/child_accounts/family_info_fetcher.h
@@ -25,6 +25,9 @@
 class URLRequestContextGetter;
 }
 
+// Fetches information about the family of the signed-in user. It can get
+// information about the family itself (e.g. a name), as well as a list of
+// family members and their properties.
 class FamilyInfoFetcher : public OAuth2TokenService::Observer,
                           public OAuth2TokenService::Consumer,
                           public net::URLFetcherDelegate {
@@ -34,6 +37,8 @@
     NETWORK_ERROR,  // Network failure.
     SERVICE_ERROR,  // Service returned an error or malformed reply.
   };
+  // Note: If you add or update an entry, also update |kFamilyMemberRoleStrings|
+  // in the .cc file.
   enum FamilyMemberRole {
     HEAD_OF_HOUSEHOLD = 0,
     PARENT,
@@ -74,6 +79,8 @@
     virtual void OnFailure(ErrorCode error) {}
   };
 
+  // Instantiates a fetcher, but doesn't start a fetch - use the StartGet*
+  // methods below. |consumer| must outlive us.
   FamilyInfoFetcher(Consumer* consumer,
                     const std::string& account_id,
                     OAuth2TokenService* token_service,
@@ -84,6 +91,8 @@
   static std::string RoleToString(FamilyMemberRole role);
   static bool StringToRole(const std::string& str, FamilyMemberRole* role);
 
+  // Start a fetch for the family profile or members.
+  // Note: Only one fetch is supported at a time.
   void StartGetFamilyProfile();
   void StartGetFamilyMembers();
 
@@ -119,8 +128,7 @@
   OAuth2TokenService* token_service_;
   net::URLRequestContextGetter* request_context_;
 
-  std::string request_suffix_;
-  net::URLFetcher::RequestType request_type_;
+  std::string request_path_;
   std::unique_ptr<OAuth2TokenService::Request> access_token_request_;
   std::string access_token_;
   bool access_token_expired_;
@@ -130,4 +138,3 @@
 };
 
 #endif  // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_INFO_FETCHER_H_
-
diff --git a/chrome/browser/supervised_user/child_accounts/kids_management_api.cc b/chrome/browser/supervised_user/child_accounts/kids_management_api.cc
new file mode 100644
index 0000000..f22f716
--- /dev/null
+++ b/chrome/browser/supervised_user/child_accounts/kids_management_api.cc
@@ -0,0 +1,41 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/supervised_user/child_accounts/kids_management_api.h"
+
+#include "base/feature_list.h"
+#include "components/variations/variations_associated_data.h"
+#include "url/gurl.h"
+
+namespace kids_management_api {
+
+namespace {
+
+const char kDefaultBaseURL[] =
+    "https://kidsmanagement-pa.googleapis.com/kidsmanagement/v1/";
+
+// A dummy feature that can be used to specify a variation param that overrides
+// the default API URL.
+const base::Feature kKidsManagementAPIFeature{
+    "KidsManagementAPI", base::FEATURE_DISABLED_BY_DEFAULT};
+
+const char kURLParamName[] = "kids_management_api_url";
+
+}  // namespace
+
+GURL GetBaseURL() {
+  // If the parameter isn't set or the feature is disabled, this will return
+  // the empty string, resulting in an invalid URL.
+  GURL url(variations::GetVariationParamValueByFeature(
+      kKidsManagementAPIFeature, kURLParamName));
+  if (url.is_valid())
+    return url;
+  return GURL(kDefaultBaseURL);
+}
+
+GURL GetURL(const std::string& path) {
+  return GetBaseURL().Resolve(path);
+}
+
+}  // namespace kids_management_api
diff --git a/chrome/browser/supervised_user/child_accounts/kids_management_api.h b/chrome/browser/supervised_user/child_accounts/kids_management_api.h
new file mode 100644
index 0000000..927077b8
--- /dev/null
+++ b/chrome/browser/supervised_user/child_accounts/kids_management_api.h
@@ -0,0 +1,20 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_KIDS_MANAGEMENT_API_H_
+#define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_KIDS_MANAGEMENT_API_H_
+
+#include <string>
+
+class GURL;
+
+namespace kids_management_api {
+
+GURL GetBaseURL();
+
+GURL GetURL(const std::string& path);
+
+}  // namespace kids_management_api
+
+#endif  // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_KIDS_MANAGEMENT_API_H_
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 d28092d..f887bb5 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
@@ -15,6 +15,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/child_accounts/kids_management_api.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"
@@ -30,8 +31,7 @@
 
 using net::URLFetcher;
 
-const char kApiUrl[] =
-    "https://www.googleapis.com/kidsmanagement/v1/people/me/permissionRequests";
+const char kApiPath[] = "people/me/permissionRequests";
 const char kApiScope[] = "https://www.googleapis.com/auth/kid.permission";
 
 const int kNumRetries = 1;
@@ -138,9 +138,9 @@
     LOG_IF(WARNING, !url.is_valid())
         << "Got invalid URL for " << switches::kPermissionRequestApiUrl;
     return url;
-  } else {
-    return GURL(kApiUrl);
   }
+
+  return kids_management_api::GetURL(kApiPath);
 }
 
 std::string PermissionRequestCreatorApiary::GetApiScope() const {