Commit 8ab0c4b2 authored by fgorski@chromium.org's avatar fgorski@chromium.org

Adding handling of MCS Endpoints to GServicesSettings

Removing mcs_hostname and mcs_secure_port from GServicesSettings.
Adding mcs_main_endpoint and mcs_fallback_enpoint.
Constructing the main endpoint based on g-settings from the checkin.
Constructing the fallback endpoint based on mcs hostname and default
fallback port.

R=jianli@chromium.org,zea@chromium.org
BUG=359254

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269632 0039d316-1c4b-4281-b951-d872f2087c98
parent 6150ffff
......@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
namespace {
// The expected time in seconds between periodic checkins.
......@@ -22,10 +23,16 @@ const char kRegistrationURLKey[] = "gcm_registration_url";
const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days.
const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours.
const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin";
const char kDefaultMCSHostname[] = "https://mtalk.google.com";
const int kDefaultMCSSecurePort = 5228;
const char kDefaultMCSHostname[] = "mtalk.google.com";
const int kDefaultMCSMainSecurePort = 5228;
const int kDefaultMCSFallbackSecurePort = 443;
const char kDefaultRegistrationURL[] =
"https://android.clients.google.com/c2dm/register3";
const char kMCSEnpointTemplate[] = "https://%s:%d";
std::string MakeMCSEndpoint(const std::string& mcs_hostname, int port) {
return base::StringPrintf(kMCSEnpointTemplate, mcs_hostname.c_str(), port);
}
} // namespace
......@@ -44,8 +51,10 @@ const GURL GServicesSettings::DefaultCheckinURL() {
GServicesSettings::GServicesSettings()
: checkin_interval_(base::TimeDelta::FromSeconds(kDefaultCheckinInterval)),
checkin_url_(kDefaultCheckinURL),
mcs_hostname_(kDefaultMCSHostname),
mcs_secure_port_(kDefaultMCSSecurePort),
mcs_main_endpoint_(MakeMCSEndpoint(kDefaultMCSHostname,
kDefaultMCSMainSecurePort)),
mcs_fallback_endpoint_(MakeMCSEndpoint(kDefaultMCSHostname,
kDefaultMCSFallbackSecurePort)),
registration_url_(kDefaultRegistrationURL),
weak_ptr_factory_(this) {
}
......@@ -88,8 +97,8 @@ std::map<std::string, std::string> GServicesSettings::GetSettingsMap() const {
settings[kCheckinIntervalKey] =
base::Int64ToString(checkin_interval_.InSeconds());
settings[kCheckinURLKey] = checkin_url_.spec();
settings[kMCSHostnameKey] = mcs_hostname_;
settings[kMCSSecurePortKey] = base::IntToString(mcs_secure_port_);
settings[kMCSHostnameKey] = mcs_main_endpoint_.host();
settings[kMCSSecurePortKey] = mcs_main_endpoint_.port();
settings[kRegistrationURLKey] = registration_url_.spec();
return settings;
}
......@@ -144,6 +153,14 @@ bool GServicesSettings::UpdateSettings(
return false;
}
GURL new_mcs_main_endpoint =
GURL(MakeMCSEndpoint(new_mcs_hostname, new_mcs_secure_port));
GURL new_mcs_fallback_endpoint =
GURL(MakeMCSEndpoint(new_mcs_hostname, kDefaultMCSFallbackSecurePort));
if (!new_mcs_main_endpoint.is_valid() ||
!new_mcs_fallback_endpoint.is_valid())
return false;
GURL new_checkin_url;
iter = settings.find(kCheckinURLKey);
if (iter == settings.end()) {
......@@ -172,8 +189,8 @@ bool GServicesSettings::UpdateSettings(
// We only update the settings once all of them are correct.
checkin_interval_ = base::TimeDelta::FromSeconds(new_checkin_interval);
mcs_hostname_ = new_mcs_hostname;
mcs_secure_port_ = new_mcs_secure_port;
mcs_main_endpoint_ = new_mcs_main_endpoint;
mcs_fallback_endpoint_ = new_mcs_fallback_endpoint;
checkin_url_ = new_checkin_url;
registration_url_ = new_registration_url;
return true;
......
......@@ -47,10 +47,9 @@ class GCM_EXPORT GServicesSettings {
GURL checkin_url() const { return checkin_url_; }
// TODO(fgorski): Consider returning GURL and use it for validation.
std::string mcs_hostname() const { return mcs_hostname_; }
GURL mcs_main_endpoint() const { return mcs_main_endpoint_; }
int mcs_secure_port() const { return mcs_secure_port_; }
GURL mcs_fallback_endpoint() const { return mcs_fallback_endpoint_; }
GURL registration_url() const { return registration_url_; }
......@@ -70,11 +69,11 @@ class GCM_EXPORT GServicesSettings {
// URL that should be used for checkins.
GURL checkin_url_;
// Hostname of the MCS server.
std::string mcs_hostname_;
// Main MCS endpoint.
GURL mcs_main_endpoint_;
// Secure port to connect to on MCS sever.
int mcs_secure_port_;
// Fallback MCS endpoint.
GURL mcs_fallback_endpoint_;
// URL that should be used for regisrations and unregistrations.
GURL registration_url_;
......
......@@ -14,15 +14,13 @@ namespace {
const int64 kAlternativeCheckinInterval = 16 * 60 * 60;
const char kAlternativeCheckinURL[] = "http://alternative.url/checkin";
const char kAlternativeMCSHostname[] = "http://alternative.gcm.host";
const int kAlternativeMCSSecurePort = 443;
const char kAlternativeMCSHostname[] = "alternative.gcm.host";
const int kAlternativeMCSSecurePort = 7777;
const char kAlternativeRegistrationURL[] =
"http://alternative.url/registration";
const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days.
const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin";
const char kDefaultMCSHostname[] = "https://mtalk.google.com";
const int kDefaultMCSSecurePort = 5228;
const char kDefaultRegistrationURL[] =
"https://android.clients.google.com/c2dm/register3";
......@@ -74,8 +72,10 @@ void GServicesSettingsTest::CheckAllSetToDefault() {
EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval),
settings().checkin_interval());
EXPECT_EQ(GURL(kDefaultCheckinURL), settings().checkin_url());
EXPECT_EQ(kDefaultMCSHostname, settings().mcs_hostname());
EXPECT_EQ(kDefaultMCSSecurePort, settings().mcs_secure_port());
EXPECT_EQ(GURL("https://mtalk.google.com:5228"),
settings().mcs_main_endpoint());
EXPECT_EQ(GURL("https://mtalk.google.com:443"),
settings().mcs_fallback_endpoint());
EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().registration_url());
}
......@@ -83,8 +83,10 @@ void GServicesSettingsTest::CheckAllSetToAlternative() {
EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval),
settings().checkin_interval());
EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().checkin_url());
EXPECT_EQ(kAlternativeMCSHostname, settings().mcs_hostname());
EXPECT_EQ(kAlternativeMCSSecurePort, settings().mcs_secure_port());
EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
settings().mcs_main_endpoint());
EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
settings().mcs_fallback_endpoint());
EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().registration_url());
}
......
......@@ -83,13 +83,6 @@ enum OutgoingMessageTTLCategory {
TTL_CATEGORY_COUNT
};
// MCS endpoints. SSL Key pinning is done automatically due to the *.google.com
// pinning rule.
// Note: modifying the endpoints will affect the ability to compare the
// GCM.CurrentEnpoint histogram across versions.
const char kMCSEndpointMain[] = "https://mtalk.google.com:5228";
const char kMCSEndpointFallback[] = "https://mtalk.google.com:443";
const int kMaxRegistrationRetries = 5;
const char kMessageTypeDataMessage[] = "gcm";
const char kMessageTypeDeletedMessagesKey[] = "deleted_messages";
......@@ -275,8 +268,8 @@ void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) {
void GCMClientImpl::InitializeMCSClient(
scoped_ptr<GCMStore::LoadResult> result) {
std::vector<GURL> endpoints;
endpoints.push_back(GURL(kMCSEndpointMain));
endpoints.push_back(GURL(kMCSEndpointFallback));
endpoints.push_back(gservices_settings_.mcs_main_endpoint());
endpoints.push_back(gservices_settings_.mcs_fallback_endpoint());
connection_factory_ = internals_builder_->BuildConnectionFactory(
endpoints,
kDefaultBackoffPolicy,
......
......@@ -719,8 +719,8 @@ TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
std::map<std::string, std::string> settings;
settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval);
settings["checkin_url"] = "http://alternative.url/checkin";
settings["gcm_hostname"] = "http://alternative.gcm.host";
settings["gcm_secure_port"] = "443";
settings["gcm_hostname"] = "alternative.gcm.host";
settings["gcm_secure_port"] = "7777";
settings["gcm_registration_url"] = "http://alternative.url/registration";
CompleteCheckin(
kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings);
......@@ -730,8 +730,10 @@ TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
gservices_settings().checkin_url());
EXPECT_EQ(GURL("http://alternative.url/registration"),
gservices_settings().registration_url());
EXPECT_EQ("http://alternative.gcm.host", gservices_settings().mcs_hostname());
EXPECT_EQ(443, gservices_settings().mcs_secure_port());
EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
gservices_settings().mcs_main_endpoint());
EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
gservices_settings().mcs_fallback_endpoint());
}
// This test only checks that periodic checkin happens.
......@@ -739,8 +741,8 @@ TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) {
std::map<std::string, std::string> settings;
settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
settings["checkin_url"] = "http://alternative.url/checkin";
settings["gcm_hostname"] = "http://alternative.gcm.host";
settings["gcm_secure_port"] = "443";
settings["gcm_hostname"] = "alternative.gcm.host";
settings["gcm_secure_port"] = "7777";
settings["gcm_registration_url"] = "http://alternative.url/registration";
CompleteCheckin(
kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings);
......@@ -755,8 +757,8 @@ TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
std::map<std::string, std::string> settings;
settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
settings["checkin_url"] = "http://alternative.url/checkin";
settings["gcm_hostname"] = "http://alternative.gcm.host";
settings["gcm_secure_port"] = "443";
settings["gcm_hostname"] = "alternative.gcm.host";
settings["gcm_secure_port"] = "7777";
settings["gcm_registration_url"] = "http://alternative.url/registration";
CompleteCheckin(
kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings);
......@@ -770,8 +772,10 @@ TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
gservices_settings().checkin_url());
EXPECT_EQ(GURL("http://alternative.url/registration"),
gservices_settings().registration_url());
EXPECT_EQ("http://alternative.gcm.host", gservices_settings().mcs_hostname());
EXPECT_EQ(443, gservices_settings().mcs_secure_port());
EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
gservices_settings().mcs_main_endpoint());
EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
gservices_settings().mcs_fallback_endpoint());
}
} // namespace gcm
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment