Extract SIGPIPE ignoring code to a common place.
[chromium-blink-merge.git] / google_apis / gaia / gaia_urls.cc
blob8ececeb55ee004bc4143de260f95a1326ca67ec8
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 "google_apis/gaia/gaia_switches.h"
9 #include "google_apis/google_api_keys.h"
11 namespace {
13 // Gaia service constants
14 const char kDefaultGaiaBaseUrl[] = "accounts.google.com";
15 const char kCaptchaUrlPrefixSuffix[] = "/";
16 const char kClientLoginUrlSuffix[] = "/ClientLogin";
17 const char kServiceLoginUrlSuffix[] = "/ServiceLogin";
18 const char kIssueAuthTokenUrlSuffix[] = "/IssueAuthToken";
19 const char kGetUserInfoUrlSuffix[] = "/GetUserInfo";
20 const char kTokenAuthUrlSuffix[] = "/TokenAuth";
21 const char kMergeSessionUrlSuffix[] = "/MergeSession";
23 const char kOAuthGetAccessTokenUrlSuffix[] = "/OAuthGetAccessToken";
24 const char kOAuthWrapBridgeUrlSuffix[] = "/OAuthWrapBridge";
25 const char kOAuth1LoginUrlSuffix[] = "/OAuthLogin";
26 const char kOAuthRevokeTokenUrlSuffix[] = "/AuthSubRevokeToken";
28 // Federated login constants
29 const char kDefaultFederatedLoginHost[] = "www.google.com";
30 const char kDefaultFederatedLoginPath[] = "/accounts";
31 const char kGetOAuthTokenUrlSuffix[] = "/o/oauth/GetOAuthToken/";
33 const char kClientLoginToOAuth2Url[] =
34 "https://accounts.google.com/o/oauth2/programmatic_auth";
35 const char kOAuth2TokenUrl[] =
36 "https://accounts.google.com/o/oauth2/token";
37 const char kOAuth2IssueTokenUrl[] =
38 "https://www.googleapis.com/oauth2/v2/IssueToken";
39 const char kOAuth1LoginScope[] =
40 "https://www.google.com/accounts/OAuthLogin";
41 const char kOAuthUserInfoUrl[] =
42 "https://www.googleapis.com/oauth2/v1/userinfo";
45 void GetSwitchValueWithDefault(const char* switch_value,
46 const char* default_value,
47 std::string* output_value) {
48 CommandLine* command_line = CommandLine::ForCurrentProcess();
49 if (command_line->HasSwitch(switch_value)) {
50 *output_value = command_line->GetSwitchValueASCII(switch_value);
51 } else {
52 *output_value = default_value;
56 } // namespace
58 GaiaUrls* GaiaUrls::GetInstance() {
59 return Singleton<GaiaUrls>::get();
62 GaiaUrls::GaiaUrls() {
63 CommandLine* command_line = CommandLine::ForCurrentProcess();
64 std::string host_base;
65 GetSwitchValueWithDefault(switches::kGaiaHost, kDefaultGaiaBaseUrl,
66 &host_base);
68 captcha_url_prefix_ = "http://" + host_base + kCaptchaUrlPrefixSuffix;
69 gaia_origin_url_ = "https://" + host_base;
70 std::string gaia_url_base = gaia_origin_url_;
71 if (command_line->HasSwitch(switches::kGaiaUrlPath)) {
72 std::string path =
73 command_line->GetSwitchValueASCII(switches::kGaiaUrlPath);
74 if (!path.empty()) {
75 if (path[0] != '/')
76 gaia_url_base.append("/");
78 gaia_url_base.append(path);
82 client_login_url_ = gaia_url_base + kClientLoginUrlSuffix;
83 service_login_url_ = gaia_url_base + kServiceLoginUrlSuffix;
84 issue_auth_token_url_ = gaia_url_base + kIssueAuthTokenUrlSuffix;
85 get_user_info_url_ = gaia_url_base + kGetUserInfoUrlSuffix;
86 token_auth_url_ = gaia_url_base + kTokenAuthUrlSuffix;
87 merge_session_url_ = gaia_url_base + kMergeSessionUrlSuffix;
88 get_oauth_token_url_ = gaia_url_base + kGetOAuthTokenUrlSuffix;
89 oauth_get_access_token_url_ = gaia_url_base +
90 kOAuthGetAccessTokenUrlSuffix;
91 oauth_wrap_bridge_url_ = gaia_url_base + kOAuthWrapBridgeUrlSuffix;
92 oauth_revoke_token_url_ = gaia_url_base + kOAuthRevokeTokenUrlSuffix;
93 oauth1_login_url_ = gaia_url_base + kOAuth1LoginUrlSuffix;
95 GetSwitchValueWithDefault(switches::kOAuth1LoginScope,
96 kOAuth1LoginScope,
97 &oauth1_login_scope_);
99 // TODO(joaodasilva): these aren't configurable for now, but are managed here
100 // so that users of Gaia URLs don't have to use static constants.
101 // http://crbug.com/97126
102 oauth_wrap_bridge_user_info_scope_ =
103 "https://www.googleapis.com/auth/userinfo.email";
104 client_oauth_url_ = "https://accounts.google.com/ClientOAuth";
106 oauth2_chrome_client_id_ =
107 google_apis::GetOAuth2ClientID(google_apis::CLIENT_MAIN);
108 oauth2_chrome_client_secret_ =
109 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_MAIN);
111 GetSwitchValueWithDefault(switches::kClientLoginToOAuth2Url,
112 kClientLoginToOAuth2Url,
113 &client_login_to_oauth2_url_);
114 GetSwitchValueWithDefault(switches::kOAuth2TokenUrl,
115 kOAuth2TokenUrl,
116 &oauth2_token_url_);
117 GetSwitchValueWithDefault(switches::kOAuth2IssueTokenUrl,
118 kOAuth2IssueTokenUrl,
119 &oauth2_issue_token_url_);
120 GetSwitchValueWithDefault(switches::kOAuthUserInfoUrl,
121 kOAuthUserInfoUrl,
122 &oauth_user_info_url_);
124 gaia_login_form_realm_ = "https://accounts.google.com/";
127 GaiaUrls::~GaiaUrls() {
130 const std::string& GaiaUrls::captcha_url_prefix() {
131 return captcha_url_prefix_;
134 const std::string& GaiaUrls::gaia_origin_url() {
135 return gaia_origin_url_;
138 const std::string& GaiaUrls::client_login_url() {
139 return client_login_url_;
142 const std::string& GaiaUrls::service_login_url() {
143 return service_login_url_;
146 const std::string& GaiaUrls::issue_auth_token_url() {
147 return issue_auth_token_url_;
150 const std::string& GaiaUrls::get_user_info_url() {
151 return get_user_info_url_;
154 const std::string& GaiaUrls::token_auth_url() {
155 return token_auth_url_;
158 const std::string& GaiaUrls::merge_session_url() {
159 return merge_session_url_;
162 const std::string& GaiaUrls::get_oauth_token_url() {
163 return get_oauth_token_url_;
166 const std::string& GaiaUrls::oauth_get_access_token_url() {
167 return oauth_get_access_token_url_;
170 const std::string& GaiaUrls::oauth_wrap_bridge_url() {
171 return oauth_wrap_bridge_url_;
174 const std::string& GaiaUrls::oauth_user_info_url() {
175 return oauth_user_info_url_;
178 const std::string& GaiaUrls::oauth_revoke_token_url() {
179 return oauth_revoke_token_url_;
182 const std::string& GaiaUrls::oauth1_login_url() {
183 return oauth1_login_url_;
186 const std::string& GaiaUrls::oauth1_login_scope() {
187 return oauth1_login_scope_;
190 const std::string& GaiaUrls::oauth_wrap_bridge_user_info_scope() {
191 return oauth_wrap_bridge_user_info_scope_;
194 const std::string& GaiaUrls::client_oauth_url() {
195 return client_oauth_url_;
198 const std::string& GaiaUrls::oauth2_chrome_client_id() {
199 return oauth2_chrome_client_id_;
202 const std::string& GaiaUrls::oauth2_chrome_client_secret() {
203 return oauth2_chrome_client_secret_;
206 const std::string& GaiaUrls::client_login_to_oauth2_url() {
207 return client_login_to_oauth2_url_;
210 const std::string& GaiaUrls::oauth2_token_url() {
211 return oauth2_token_url_;
214 const std::string& GaiaUrls::oauth2_issue_token_url() {
215 return oauth2_issue_token_url_;
219 const std::string& GaiaUrls::gaia_login_form_realm() {
220 return gaia_login_form_realm_;