Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / content / browser / wallet / wallet_service_url.cc
blob78aad22c34b71e9bea9c1620e7f05d746344da6d
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
3 // found in the LICENSE file.
5 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/format_macros.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "components/autofill/core/common/autofill_switches.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h"
19 #include "google_apis/gaia/gaia_urls.h"
20 #include "net/base/url_util.h"
21 #include "url/gurl.h"
23 namespace autofill {
24 namespace {
26 const char kProdWalletServiceUrl[] = "https://wallet.google.com/";
28 const char kSandboxWalletSecureServiceUrl[] =
29 "https://wallet-web.sandbox.google.com/";
31 bool IsWalletProductionEnabled() {
32 // If the command line flag exists, it takes precedence.
33 const base::CommandLine* command_line =
34 base::CommandLine::ForCurrentProcess();
35 std::string sandbox_enabled(
36 command_line->GetSwitchValueASCII(switches::kWalletServiceUseSandbox));
37 if (!sandbox_enabled.empty())
38 return sandbox_enabled != "1";
40 // Default to sandbox when --reduce-security-for-testing is passed to allow
41 // rAc on http:// pages.
42 if (command_line->HasSwitch(::switches::kReduceSecurityForTesting))
43 return false;
45 #if defined(ENABLE_PROD_WALLET_SERVICE)
46 return true;
47 #else
48 return false;
49 #endif
52 GURL GetBaseSecureUrl() {
53 const base::CommandLine& command_line =
54 *base::CommandLine::ForCurrentProcess();
55 std::string wallet_secure_url =
56 command_line.GetSwitchValueASCII(switches::kWalletSecureServiceUrl);
57 if (!wallet_secure_url.empty())
58 return GURL(wallet_secure_url);
59 if (IsWalletProductionEnabled())
60 return GURL(kProdWalletServiceUrl);
61 return GURL(kSandboxWalletSecureServiceUrl);
64 } // namespace
66 namespace wallet {
68 GURL GetManageInstrumentsUrl(size_t user_index) {
69 std::string path =
70 base::StringPrintf("manage/w/%" PRIuS "/paymentMethods", user_index);
71 return GetBaseSecureUrl().Resolve(path);
74 GURL GetManageAddressesUrl(size_t user_index) {
75 std::string path =
76 base::StringPrintf("manage/w/%" PRIuS "/settings/addresses", user_index);
77 return GetBaseSecureUrl().Resolve(path);
80 } // namespace wallet
81 } // namespace autofill