Make castv2 performance test work.
[chromium-blink-merge.git] / google_apis / gaia / gaia_urls.cc
blob6545d56451201d301203bbd5af48afa071ee3ade
1 // Copyright (c) 2012 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 "google_apis/gaia/gaia_urls.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "google_apis/gaia/gaia_switches.h"
11 #include "google_apis/google_api_keys.h"
13 namespace {
15 // Gaia service constants
16 const char kDefaultGaiaUrl[] = "https://accounts.google.com";
17 const char kDefaultGoogleApisBaseUrl[] = "https://www.googleapis.com";
19 // API calls from accounts.google.com
20 const char kClientLoginUrlSuffix[] = "ClientLogin";
21 const char kServiceLoginUrlSuffix[] = "ServiceLogin";
22 const char kEmbeddedSetupChromeOsUrlSuffix[] = "embedded/setup/chromeos";
23 const char kServiceLoginAuthUrlSuffix[] = "ServiceLoginAuth";
24 const char kServiceLogoutUrlSuffix[] = "Logout";
25 const char kIssueAuthTokenUrlSuffix[] = "IssueAuthToken";
26 const char kGetUserInfoUrlSuffix[] = "GetUserInfo";
27 const char kTokenAuthUrlSuffix[] = "TokenAuth";
28 const char kMergeSessionUrlSuffix[] = "MergeSession";
29 const char kOAuthGetAccessTokenUrlSuffix[] = "OAuthGetAccessToken";
30 const char kOAuthWrapBridgeUrlSuffix[] = "OAuthWrapBridge";
31 const char kOAuth1LoginUrlSuffix[] = "OAuthLogin";
32 const char kOAuthRevokeTokenUrlSuffix[] = "AuthSubRevokeToken";
33 const char kListAccountsSuffix[] = "ListAccounts?json=standard";
34 const char kEmbeddedSigninSuffix[] = "EmbeddedSignIn";
35 const char kAddAccountSuffix[] = "AddSession";
36 const char kGetCheckConnectionInfoSuffix[] = "GetCheckConnectionInfo";
38 // API calls from accounts.google.com (LSO)
39 const char kGetOAuthTokenUrlSuffix[] = "o/oauth/GetOAuthToken/";
40 const char kClientLoginToOAuth2UrlSuffix[] = "o/oauth2/programmatic_auth";
41 const char kOAuth2AuthUrlSuffix[] = "o/oauth2/auth";
42 const char kOAuth2RevokeUrlSuffix[] = "o/oauth2/revoke";
43 const char kOAuth2TokenUrlSuffix[] = "o/oauth2/token";
44 const char kOAuth2IFrameUrlSuffix[] = "o/oauth2/iframerpc";
46 // API calls from www.googleapis.com
47 const char kOAuth2IssueTokenUrlSuffix[] = "oauth2/v2/IssueToken";
48 const char kOAuth2TokenInfoUrlSuffix[] = "oauth2/v2/tokeninfo";
49 const char kOAuthUserInfoUrlSuffix[] = "oauth2/v1/userinfo";
51 void GetSwitchValueWithDefault(const char* switch_value,
52 const char* default_value,
53 std::string* output_value) {
54 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
55 if (command_line->HasSwitch(switch_value)) {
56 *output_value = command_line->GetSwitchValueASCII(switch_value);
57 } else {
58 *output_value = default_value;
62 GURL GetURLSwitchValueWithDefault(const char* switch_value,
63 const char* default_value) {
64 std::string string_value;
65 GetSwitchValueWithDefault(switch_value, default_value, &string_value);
66 const GURL result(string_value);
67 DCHECK(result.is_valid());
68 return result;
72 } // namespace
74 GaiaUrls* GaiaUrls::GetInstance() {
75 return Singleton<GaiaUrls>::get();
78 GaiaUrls::GaiaUrls() {
79 gaia_url_ = GetURLSwitchValueWithDefault(switches::kGaiaUrl, kDefaultGaiaUrl);
80 lso_origin_url_ =
81 GetURLSwitchValueWithDefault(switches::kLsoUrl, kDefaultGaiaUrl);
82 google_apis_origin_url_ = GetURLSwitchValueWithDefault(
83 switches::kGoogleApisUrl, kDefaultGoogleApisBaseUrl);
85 captcha_base_url_ =
86 GURL("http://" + gaia_url_.host() +
87 (gaia_url_.has_port() ? ":" + gaia_url_.port() : ""));
89 oauth2_chrome_client_id_ =
90 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
91 oauth2_chrome_client_secret_ =
92 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
94 // URLs from accounts.google.com.
95 client_login_url_ = gaia_url_.Resolve(kClientLoginUrlSuffix);
96 service_login_url_ = gaia_url_.Resolve(kServiceLoginUrlSuffix);
97 embedded_setup_chromeos_url_ =
98 gaia_url_.Resolve(kEmbeddedSetupChromeOsUrlSuffix);
99 service_login_auth_url_ = gaia_url_.Resolve(kServiceLoginAuthUrlSuffix);
100 service_logout_url_ = gaia_url_.Resolve(kServiceLogoutUrlSuffix);
101 issue_auth_token_url_ = gaia_url_.Resolve(kIssueAuthTokenUrlSuffix);
102 get_user_info_url_ = gaia_url_.Resolve(kGetUserInfoUrlSuffix);
103 token_auth_url_ = gaia_url_.Resolve(kTokenAuthUrlSuffix);
104 merge_session_url_ = gaia_url_.Resolve(kMergeSessionUrlSuffix);
105 oauth_get_access_token_url_ =
106 gaia_url_.Resolve(kOAuthGetAccessTokenUrlSuffix);
107 oauth_wrap_bridge_url_ = gaia_url_.Resolve(kOAuthWrapBridgeUrlSuffix);
108 oauth_revoke_token_url_ = gaia_url_.Resolve(kOAuthRevokeTokenUrlSuffix);
109 oauth1_login_url_ = gaia_url_.Resolve(kOAuth1LoginUrlSuffix);
110 list_accounts_url_ = gaia_url_.Resolve(kListAccountsSuffix);
111 embedded_signin_url_ = gaia_url_.Resolve(kEmbeddedSigninSuffix);
112 add_account_url_ = gaia_url_.Resolve(kAddAccountSuffix);
113 get_check_connection_info_url_ =
114 gaia_url_.Resolve(kGetCheckConnectionInfoSuffix);
116 // URLs from accounts.google.com (LSO).
117 get_oauth_token_url_ = lso_origin_url_.Resolve(kGetOAuthTokenUrlSuffix);
118 client_login_to_oauth2_url_ =
119 lso_origin_url_.Resolve(kClientLoginToOAuth2UrlSuffix);
120 oauth2_auth_url_ = lso_origin_url_.Resolve(kOAuth2AuthUrlSuffix);
121 oauth2_token_url_ = lso_origin_url_.Resolve(kOAuth2TokenUrlSuffix);
122 oauth2_revoke_url_ = lso_origin_url_.Resolve(kOAuth2RevokeUrlSuffix);
123 oauth2_iframe_url_ =
124 lso_origin_url_.Resolve(kOAuth2IFrameUrlSuffix);
126 // URLs from www.googleapis.com.
127 oauth2_issue_token_url_ =
128 google_apis_origin_url_.Resolve(kOAuth2IssueTokenUrlSuffix);
129 oauth2_token_info_url_ =
130 google_apis_origin_url_.Resolve(kOAuth2TokenInfoUrlSuffix);
131 oauth_user_info_url_ =
132 google_apis_origin_url_.Resolve(kOAuthUserInfoUrlSuffix);
134 gaia_login_form_realm_ = gaia_url_;
137 GaiaUrls::~GaiaUrls() {
140 const GURL& GaiaUrls::gaia_url() const {
141 return gaia_url_;
144 const GURL& GaiaUrls::captcha_base_url() const {
145 return captcha_base_url_;
148 const GURL& GaiaUrls::client_login_url() const {
149 return client_login_url_;
152 const GURL& GaiaUrls::service_login_url() const {
153 return service_login_url_;
156 const GURL& GaiaUrls::embedded_setup_chromeos_url() const {
157 return embedded_setup_chromeos_url_;
161 const GURL& GaiaUrls::service_login_auth_url() const {
162 return service_login_auth_url_;
165 const GURL& GaiaUrls::service_logout_url() const {
166 return service_logout_url_;
169 const GURL& GaiaUrls::issue_auth_token_url() const {
170 return issue_auth_token_url_;
173 const GURL& GaiaUrls::get_user_info_url() const {
174 return get_user_info_url_;
177 const GURL& GaiaUrls::token_auth_url() const {
178 return token_auth_url_;
181 const GURL& GaiaUrls::merge_session_url() const {
182 return merge_session_url_;
185 const GURL& GaiaUrls::get_oauth_token_url() const {
186 return get_oauth_token_url_;
189 const GURL& GaiaUrls::oauth_get_access_token_url() const {
190 return oauth_get_access_token_url_;
193 const GURL& GaiaUrls::oauth_wrap_bridge_url() const {
194 return oauth_wrap_bridge_url_;
197 const GURL& GaiaUrls::oauth_user_info_url() const {
198 return oauth_user_info_url_;
201 const GURL& GaiaUrls::oauth_revoke_token_url() const {
202 return oauth_revoke_token_url_;
205 const GURL& GaiaUrls::oauth2_iframe_url() const {
206 return oauth2_iframe_url_;
209 const GURL& GaiaUrls::oauth1_login_url() const {
210 return oauth1_login_url_;
213 const GURL& GaiaUrls::embedded_signin_url() const {
214 return embedded_signin_url_;
217 const GURL& GaiaUrls::add_account_url() const {
218 return add_account_url_;
221 const std::string& GaiaUrls::oauth2_chrome_client_id() const {
222 return oauth2_chrome_client_id_;
225 const std::string& GaiaUrls::oauth2_chrome_client_secret() const {
226 return oauth2_chrome_client_secret_;
229 const GURL& GaiaUrls::client_login_to_oauth2_url() const {
230 return client_login_to_oauth2_url_;
233 const GURL& GaiaUrls::oauth2_auth_url() const {
234 return oauth2_auth_url_;
237 const GURL& GaiaUrls::oauth2_token_url() const {
238 return oauth2_token_url_;
241 const GURL& GaiaUrls::oauth2_issue_token_url() const {
242 return oauth2_issue_token_url_;
245 const GURL& GaiaUrls::oauth2_token_info_url() const {
246 return oauth2_token_info_url_;
249 const GURL& GaiaUrls::oauth2_revoke_url() const {
250 return oauth2_revoke_url_;
253 const GURL& GaiaUrls::gaia_login_form_realm() const {
254 return gaia_url_;
257 GURL GaiaUrls::ListAccountsURLWithSource(const std::string& source) {
258 if (source.empty()) {
259 return list_accounts_url_;
260 } else {
261 std::string query = list_accounts_url_.query();
262 return list_accounts_url_.Resolve(
263 base::StringPrintf("?source=%s&%s", source.c_str(), query.c_str()));
267 GURL GaiaUrls::GetCheckConnectionInfoURLWithSource(const std::string& source) {
268 return source.empty()
269 ? get_check_connection_info_url_
270 : get_check_connection_info_url_.Resolve(
271 base::StringPrintf("?source=%s", source.c_str()));