summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorfgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 02:24:34 +0000
committerfgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-30 02:24:34 +0000
commitdcfe32a7ea850f1ce29cfe7c4e22ee2336a956cd (patch)
treebaaf95e992fd4a3a270aba4ebf6ff095fa5b9b44 /google_apis
parent625791699a3cb76b5b161f8cfa83b96b681f73f2 (diff)
downloadchromium_src-dcfe32a7ea850f1ce29cfe7c4e22ee2336a956cd.zip
chromium_src-dcfe32a7ea850f1ce29cfe7c4e22ee2336a956cd.tar.gz
chromium_src-dcfe32a7ea850f1ce29cfe7c4e22ee2336a956cd.tar.bz2
[GCM] fixing G-settings initialization from an empty store
Adding a test for the problem Fixing the problem Adding a minimum checkin interval BUG=359254 Review URL: https://codereview.chromium.org/252933002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gcm/engine/gservices_settings.cc95
-rw-r--r--google_apis/gcm/engine/gservices_settings.h3
-rw-r--r--google_apis/gcm/engine/gservices_settings_unittest.cc60
3 files changed, 115 insertions, 43 deletions
diff --git a/google_apis/gcm/engine/gservices_settings.cc b/google_apis/gcm/engine/gservices_settings.cc
index fc38e9d..20b9d7d 100644
--- a/google_apis/gcm/engine/gservices_settings.cc
+++ b/google_apis/gcm/engine/gservices_settings.cc
@@ -30,6 +30,8 @@ const char kDefaultRegistrationURL[] =
namespace gcm {
+const int64 GServicesSettings::kMinimumCheckinInterval = 12 * 60 * 60;
+
GServicesSettings::GServicesSettings(GCMStore* gcm_store)
: gcm_store_(gcm_store),
checkin_interval_(kDefaultCheckinInterval),
@@ -77,61 +79,72 @@ void GServicesSettings::UpdateFromLoadResult(
bool GServicesSettings::UpdateSettings(
const std::map<std::string, std::string>& settings) {
- int64 new_checkin_interval = 0LL;
+ int64 new_checkin_interval = kMinimumCheckinInterval;
std::map<std::string, std::string>::const_iterator iter =
settings.find(kCheckinIntervalKey);
- if (iter != settings.end()) {
- if (!base::StringToInt64(iter->second, &new_checkin_interval)) {
- LOG(ERROR) << "Failed to parse checkin interval: " << iter->second;
- return false;
- }
- if (new_checkin_interval <= 0LL) {
- LOG(ERROR) << "Checkin interval not positive: " << new_checkin_interval;
- return false;
- }
+ if (iter == settings.end()) {
+ LOG(ERROR) << "Setting not found: " << kCheckinIntervalKey;
+ return false;
+ }
+ if (!base::StringToInt64(iter->second, &new_checkin_interval)) {
+ LOG(ERROR) << "Failed to parse checkin interval: " << iter->second;
+ return false;
+ }
+ if (new_checkin_interval < kMinimumCheckinInterval) {
+ LOG(ERROR) << "Checkin interval: " << new_checkin_interval
+ << " is less than allowed minimum: " << kMinimumCheckinInterval;
+ new_checkin_interval = kMinimumCheckinInterval;
}
std::string new_mcs_hostname;
- int new_mcs_secure_port = -1;
iter = settings.find(kMCSHostnameKey);
- if (iter != settings.end()) {
- new_mcs_hostname = iter->second;
- if (new_mcs_hostname.empty()) {
- LOG(ERROR) << "Empty MCS hostname provided.";
- return false;
- }
-
- iter = settings.find(kMCSSecurePortKey);
- if (iter != settings.end()) {
- if (!base::StringToInt(iter->second, &new_mcs_secure_port)) {
- LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second;
- return false;
- }
- if (new_mcs_secure_port < 0 || 65535 < new_mcs_secure_port) {
- LOG(ERROR) << "Incorrect port value: " << new_mcs_secure_port;
- return false;
- }
- }
+ if (iter == settings.end()) {
+ LOG(ERROR) << "Setting not found: " << kMCSHostnameKey;
+ return false;
+ }
+ new_mcs_hostname = iter->second;
+ if (new_mcs_hostname.empty()) {
+ LOG(ERROR) << "Empty MCS hostname provided.";
+ return false;
+ }
+
+ int new_mcs_secure_port = -1;
+ iter = settings.find(kMCSSecurePortKey);
+ if (iter == settings.end()) {
+ LOG(ERROR) << "Setting not found: " << kMCSSecurePortKey;
+ return false;
+ }
+ if (!base::StringToInt(iter->second, &new_mcs_secure_port)) {
+ LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second;
+ return false;
+ }
+ if (new_mcs_secure_port < 0 || 65535 < new_mcs_secure_port) {
+ LOG(ERROR) << "Incorrect port value: " << new_mcs_secure_port;
+ return false;
}
std::string new_checkin_url;
iter = settings.find(kCheckinURLKey);
- if (iter != settings.end()) {
- new_checkin_url = iter->second;
- if (new_checkin_url.empty()) {
- LOG(ERROR) << "Empty checkin URL provided.";
- return false;
- }
+ if (iter == settings.end()) {
+ LOG(ERROR) << "Setting not found: " << kCheckinURLKey;
+ return false;
+ }
+ new_checkin_url = iter->second;
+ if (new_checkin_url.empty()) {
+ LOG(ERROR) << "Empty checkin URL provided.";
+ return false;
}
std::string new_registration_url;
iter = settings.find(kRegistrationURLKey);
- if (iter != settings.end()) {
- new_registration_url = iter->second;
- if (new_registration_url.empty()) {
- LOG(ERROR) << "Empty registration URL provided.";
- return false;
- }
+ if (iter == settings.end()) {
+ LOG(ERROR) << "Setting not found: " << kRegistrationURLKey;
+ return false;
+ }
+ new_registration_url = iter->second;
+ if (new_registration_url.empty()) {
+ LOG(ERROR) << "Empty registration URL provided.";
+ return false;
}
// We only update the settings once all of them are correct.
diff --git a/google_apis/gcm/engine/gservices_settings.h b/google_apis/gcm/engine/gservices_settings.h
index db3c6b0..775c676 100644
--- a/google_apis/gcm/engine/gservices_settings.h
+++ b/google_apis/gcm/engine/gservices_settings.h
@@ -19,6 +19,9 @@ namespace gcm {
// extracting them from checkin response and storing in GCMStore.
class GCM_EXPORT GServicesSettings {
public:
+ // Minimum periodic checkin interval in seconds.
+ static const int64 kMinimumCheckinInterval;
+
// Create an instance of GServicesSettings class. |gcm_store| is used to store
// the settings after they are extracted from checkin response.
explicit GServicesSettings(GCMStore* gcm_store);
diff --git a/google_apis/gcm/engine/gservices_settings_unittest.cc b/google_apis/gcm/engine/gservices_settings_unittest.cc
index ada4194..de756f8 100644
--- a/google_apis/gcm/engine/gservices_settings_unittest.cc
+++ b/google_apis/gcm/engine/gservices_settings_unittest.cc
@@ -12,7 +12,7 @@ namespace gcm {
namespace {
-const int64 kAlternativeCheckinInterval = 2000LL;
+const int64 kAlternativeCheckinInterval = 16 * 60 * 60;
const char kAlternativeCheckinURL[] = "http://alternative.url/checkin";
const char kAlternativeMCSHostname[] = "http://alternative.gcm.host";
const int kAlternativeMCSSecurePort = 443;
@@ -121,10 +121,11 @@ class GServicesSettingsTest : public testing::Test {
FakeGCMStore& gcm_store() { return gcm_store_; }
+ std::map<std::string, std::string> alternative_settings_;
+
private:
FakeGCMStore gcm_store_;
GServicesSettings gserivces_settings_;
- std::map<std::string, std::string> alternative_settings_;
};
GServicesSettingsTest::GServicesSettingsTest()
@@ -176,6 +177,28 @@ TEST_F(GServicesSettingsTest, DefaultSettingsAndDigest) {
EXPECT_EQ(std::string(), settings().digest());
}
+// Verifies that settings are not updated when load result is empty.
+TEST_F(GServicesSettingsTest, UpdateFromEmptyLoadResult) {
+ GCMStore::LoadResult result;
+ result.gservices_digest = "digest_value";
+ settings().UpdateFromLoadResult(result);
+
+ CheckAllSetToDefault();
+ EXPECT_EQ(std::string(), settings().digest());
+}
+
+// Verifies that settings are not updated when one of them is missing.
+TEST_F(GServicesSettingsTest, UpdateFromLoadResultWithSettingMissing) {
+ GCMStore::LoadResult result;
+ result.gservices_settings = alternative_settings();
+ result.gservices_digest = "digest_value";
+ result.gservices_settings.erase("gcm_hostname");
+ settings().UpdateFromLoadResult(result);
+
+ CheckAllSetToDefault();
+ EXPECT_EQ(std::string(), settings().digest());
+}
+
// Verifies that the settings are set correctly based on the load result.
TEST_F(GServicesSettingsTest, UpdateFromLoadResult) {
GCMStore::LoadResult result;
@@ -202,6 +225,39 @@ TEST_F(GServicesSettingsTest, UpdateFromCheckinResponse) {
EXPECT_EQ("digest_value", settings().digest());
}
+// Verifies that the checkin interval is updated to minimum if the original
+// value is less than minimum.
+TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseMinimumCheckinInterval) {
+ checkin_proto::AndroidCheckinResponse checkin_response;
+
+ checkin_response.set_digest("digest_value");
+ // Setting the checkin interval to less than minimum.
+ alternative_settings_["checkin_interval"] = base::IntToString(3600);
+ SetWithAlternativeSettings(checkin_response);
+
+ settings().UpdateFromCheckinResponse(checkin_response);
+ EXPECT_TRUE(gcm_store().settings_saved());
+
+ EXPECT_EQ(GServicesSettings::kMinimumCheckinInterval,
+ settings().checkin_interval());
+ EXPECT_EQ("digest_value", settings().digest());
+}
+
+// Verifies that settings are not updated when one of them is missing.
+TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseWithSettingMissing) {
+ checkin_proto::AndroidCheckinResponse checkin_response;
+
+ checkin_response.set_digest("digest_value");
+ alternative_settings_.erase("gcm_hostname");
+ SetWithAlternativeSettings(checkin_response);
+
+ settings().UpdateFromCheckinResponse(checkin_response);
+ EXPECT_FALSE(gcm_store().settings_saved());
+
+ CheckAllSetToDefault();
+ EXPECT_EQ(std::string(), settings().digest());
+}
+
// Verifies that no update is done, when a checkin response misses digest.
TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseNoDigest) {
checkin_proto::AndroidCheckinResponse checkin_response;