0

Add command line overrides for GCM checkin URL & MCS endpoint

It can be useful during development to have Chrome connect to test GCM
environments instead of production GCM.

BUG=https://b.corp.google.com/23523760

Review URL: https://codereview.chromium.org/1492913002

Cr-Commit-Position: refs/heads/master@{#362965}
This commit is contained in:
johnme
2015-12-03 05:00:37 -08:00
committed by Commit bot
parent 51a61fd376
commit 099ee16b53
6 changed files with 33 additions and 17 deletions

@ -478,7 +478,9 @@ void GCMClientImpl::StartGCM() {
void GCMClientImpl::InitializeMCSClient() {
std::vector<GURL> endpoints;
endpoints.push_back(gservices_settings_.GetMCSMainEndpoint());
endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint());
GURL fallback_endpoint = gservices_settings_.GetMCSFallbackEndpoint();
if (fallback_endpoint.is_valid())
endpoints.push_back(fallback_endpoint);
connection_factory_ = internals_builder_->BuildConnectionFactory(
endpoints,
GetGCMBackoffPolicy(),

@ -177,11 +177,6 @@ const base::TimeDelta GServicesSettings::MinimumCheckinInterval() {
return base::TimeDelta::FromSeconds(kMinimumCheckinInterval);
}
// static
const GURL GServicesSettings::DefaultCheckinURL() {
return GURL(kDefaultCheckinURL);
}
// static
std::string GServicesSettings::CalculateDigest(const SettingsMap& settings) {
unsigned char hash[base::kSHA1Length];
@ -283,6 +278,10 @@ base::TimeDelta GServicesSettings::GetCheckinInterval() const {
}
GURL GServicesSettings::GetCheckinURL() const {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kGCMCheckinURL))
return GURL(command_line->GetSwitchValueASCII(switches::kGCMCheckinURL));
SettingsMap::const_iterator iter = settings_.find(kCheckinURLKey);
if (iter == settings_.end() || iter->second.empty())
return GURL(kDefaultCheckinURL);
@ -290,6 +289,10 @@ GURL GServicesSettings::GetCheckinURL() const {
}
GURL GServicesSettings::GetMCSMainEndpoint() const {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kGCMMCSEndpoint))
return GURL(command_line->GetSwitchValueASCII(switches::kGCMMCSEndpoint));
// Get alternative hostname or use default.
std::string mcs_hostname;
SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey);
@ -316,6 +319,10 @@ GURL GServicesSettings::GetMCSMainEndpoint() const {
}
GURL GServicesSettings::GetMCSFallbackEndpoint() const {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kGCMMCSEndpoint))
return GURL(); // No fallback endpoint when using command line override.
// Get alternative hostname or use default.
std::string mcs_hostname;
SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey);
@ -335,15 +342,15 @@ GURL GServicesSettings::GetMCSFallbackEndpoint() const {
}
GURL GServicesSettings::GetRegistrationURL() const {
SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey);
if (iter == settings_.end() || iter->second.empty()) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kGCMRegistrationURL))
return GURL(kDefaultRegistrationURL);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kGCMRegistrationURL)) {
return GURL(
command_line->GetSwitchValueASCII(switches::kGCMRegistrationURL));
}
SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey);
if (iter == settings_.end() || iter->second.empty())
return GURL(kDefaultRegistrationURL);
return GURL(iter->second);
}

@ -26,9 +26,6 @@ class GCM_EXPORT GServicesSettings {
// Minimum periodic checkin interval in seconds.
static const base::TimeDelta MinimumCheckinInterval();
// Default checkin URL.
static const GURL DefaultCheckinURL();
// Calculates digest of provided settings.
static std::string CalculateDigest(const SettingsMap& settings);
@ -56,7 +53,7 @@ class GCM_EXPORT GServicesSettings {
// Gets address of main MCS endpoint.
GURL GetMCSMainEndpoint() const;
// Gets address of fallback MCS endpoint.
// Gets address of fallback MCS endpoint. Will be empty if there isn't one.
GURL GetMCSFallbackEndpoint() const;
// Gets the URL to use when registering or unregistering the apps.

@ -6,6 +6,14 @@
namespace switches {
// Sets the checkin service endpoint that will be used for performing Google
// Cloud Messaging checkins.
const char kGCMCheckinURL[] = "gcm-checkin-url";
// Sets the Mobile Connection Server endpoint that will be used for Google
// Cloud Messaging.
const char kGCMMCSEndpoint[] = "gcm-mcs-endpoint";
// Sets the registration endpoint that will be used for creating new Google
// Cloud Messaging registrations.
const char kGCMRegistrationURL[] = "gcm-registration-url";

@ -7,6 +7,8 @@
namespace switches {
extern const char kGCMCheckinURL[];
extern const char kGCMMCSEndpoint[];
extern const char kGCMRegistrationURL[];
} // namespace switches

@ -449,7 +449,7 @@ void MCSProbe::CheckIn() {
chrome_build_proto);
checkin_request_.reset(new CheckinRequest(
GServicesSettings::DefaultCheckinURL(),
GServicesSettings().GetCheckinURL(),
request_info,
kDefaultBackoffPolicy,
base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)),