Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: google_apis/gcm/engine/gservices_settings.cc

Issue 252933002: [GCM] fixing G-settings initialization from an empty store (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | google_apis/gcm/engine/gservices_settings_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gcm/engine/gservices_settings.h" 5 #include "google_apis/gcm/engine/gservices_settings.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 9
10 namespace { 10 namespace {
11 // The expected time in seconds between periodic checkins. 11 // The expected time in seconds between periodic checkins.
12 const char kCheckinIntervalKey[] = "checkin_interval"; 12 const char kCheckinIntervalKey[] = "checkin_interval";
13 // The override URL to the checkin server. 13 // The override URL to the checkin server.
14 const char kCheckinURLKey[] = "checkin_url"; 14 const char kCheckinURLKey[] = "checkin_url";
15 // The MCS machine name to connect to. 15 // The MCS machine name to connect to.
16 const char kMCSHostnameKey[] = "gcm_hostname"; 16 const char kMCSHostnameKey[] = "gcm_hostname";
17 // The MCS port to connect to. 17 // The MCS port to connect to.
18 const char kMCSSecurePortKey[] = "gcm_secure_port"; 18 const char kMCSSecurePortKey[] = "gcm_secure_port";
19 // The URL to get MCS registration IDs. 19 // The URL to get MCS registration IDs.
20 const char kRegistrationURLKey[] = "gcm_registration_url"; 20 const char kRegistrationURLKey[] = "gcm_registration_url";
21 21
22 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. 22 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days.
23 const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours.
23 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; 24 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin";
24 const char kDefaultMCSHostname[] = "https://mtalk.google.com"; 25 const char kDefaultMCSHostname[] = "https://mtalk.google.com";
25 const int kDefaultMCSSecurePort = 5228; 26 const int kDefaultMCSSecurePort = 5228;
26 const char kDefaultRegistrationURL[] = 27 const char kDefaultRegistrationURL[] =
27 "https://android.clients.google.com/c2dm/register3"; 28 "https://android.clients.google.com/c2dm/register3";
28 29
29 } // namespace 30 } // namespace
30 31
31 namespace gcm { 32 namespace gcm {
32 33
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 71 }
71 72
72 void GServicesSettings::UpdateFromLoadResult( 73 void GServicesSettings::UpdateFromLoadResult(
73 const GCMStore::LoadResult& load_result) { 74 const GCMStore::LoadResult& load_result) {
74 if (UpdateSettings(load_result.gservices_settings)) 75 if (UpdateSettings(load_result.gservices_settings))
75 digest_ = load_result.gservices_digest; 76 digest_ = load_result.gservices_digest;
76 } 77 }
77 78
78 bool GServicesSettings::UpdateSettings( 79 bool GServicesSettings::UpdateSettings(
79 const std::map<std::string, std::string>& settings) { 80 const std::map<std::string, std::string>& settings) {
80 int64 new_checkin_interval = 0LL; 81 int64 new_checkin_interval = kMinimumCheckinInterval;
81 std::map<std::string, std::string>::const_iterator iter = 82 std::map<std::string, std::string>::const_iterator iter =
82 settings.find(kCheckinIntervalKey); 83 settings.find(kCheckinIntervalKey);
83 if (iter != settings.end()) { 84 if (iter == settings.end()) {
84 if (!base::StringToInt64(iter->second, &new_checkin_interval)) { 85 LOG(ERROR) << "Setting not found: " << kCheckinIntervalKey;
85 LOG(ERROR) << "Failed to parse checkin interval: " << iter->second; 86 return false;
86 return false; 87 }
87 } 88 if (!base::StringToInt64(iter->second, &new_checkin_interval)) {
88 if (new_checkin_interval <= 0LL) { 89 LOG(ERROR) << "Failed to parse checkin interval: " << iter->second;
89 LOG(ERROR) << "Checkin interval not positive: " << new_checkin_interval; 90 return false;
90 return false; 91 }
91 } 92 if (new_checkin_interval < kMinimumCheckinInterval) {
jianli 2014/04/28 17:33:50 Probably we should use kMinimumCheckinInterval if
fgorski 2014/04/28 17:50:53 Done. I was thinking about that, but it might no l
93 LOG(ERROR) << "Checkin interval: " << new_checkin_interval
94 << " is less than allowed minimum: " << kMinimumCheckinInterval;
95 return false;
92 } 96 }
93 97
94 std::string new_mcs_hostname; 98 std::string new_mcs_hostname;
99 iter = settings.find(kMCSHostnameKey);
100 if (iter == settings.end()) {
101 LOG(ERROR) << "Setting not found: " << kMCSHostnameKey;
102 return false;
103 }
104 new_mcs_hostname = iter->second;
105 if (new_mcs_hostname.empty()) {
106 LOG(ERROR) << "Empty MCS hostname provided.";
107 return false;
108 }
109
95 int new_mcs_secure_port = -1; 110 int new_mcs_secure_port = -1;
96 iter = settings.find(kMCSHostnameKey); 111 iter = settings.find(kMCSSecurePortKey);
97 if (iter != settings.end()) { 112 if (iter == settings.end()) {
98 new_mcs_hostname = iter->second; 113 LOG(ERROR) << "Setting not found: " << kMCSSecurePortKey;
99 if (new_mcs_hostname.empty()) { 114 return false;
100 LOG(ERROR) << "Empty MCS hostname provided."; 115 }
101 return false; 116 if (!base::StringToInt(iter->second, &new_mcs_secure_port)) {
102 } 117 LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second;
103 118 return false;
104 iter = settings.find(kMCSSecurePortKey); 119 }
105 if (iter != settings.end()) { 120 if (new_mcs_secure_port < 0 || 65535 < new_mcs_secure_port) {
106 if (!base::StringToInt(iter->second, &new_mcs_secure_port)) { 121 LOG(ERROR) << "Incorrect port value: " << new_mcs_secure_port;
107 LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second; 122 return false;
108 return false;
109 }
110 if (new_mcs_secure_port < 0 || 65535 < new_mcs_secure_port) {
111 LOG(ERROR) << "Incorrect port value: " << new_mcs_secure_port;
112 return false;
113 }
114 }
115 } 123 }
116 124
117 std::string new_checkin_url; 125 std::string new_checkin_url;
118 iter = settings.find(kCheckinURLKey); 126 iter = settings.find(kCheckinURLKey);
119 if (iter != settings.end()) { 127 if (iter == settings.end()) {
120 new_checkin_url = iter->second; 128 LOG(ERROR) << "Setting not found: " << kCheckinURLKey;
121 if (new_checkin_url.empty()) { 129 return false;
122 LOG(ERROR) << "Empty checkin URL provided."; 130 }
123 return false; 131 new_checkin_url = iter->second;
124 } 132 if (new_checkin_url.empty()) {
133 LOG(ERROR) << "Empty checkin URL provided.";
134 return false;
125 } 135 }
126 136
127 std::string new_registration_url; 137 std::string new_registration_url;
128 iter = settings.find(kRegistrationURLKey); 138 iter = settings.find(kRegistrationURLKey);
129 if (iter != settings.end()) { 139 if (iter == settings.end()) {
130 new_registration_url = iter->second; 140 LOG(ERROR) << "Setting not found: " << kRegistrationURLKey;
131 if (new_registration_url.empty()) { 141 return false;
132 LOG(ERROR) << "Empty registration URL provided."; 142 }
133 return false; 143 new_registration_url = iter->second;
134 } 144 if (new_registration_url.empty()) {
145 LOG(ERROR) << "Empty registration URL provided.";
146 return false;
135 } 147 }
136 148
137 // We only update the settings once all of them are correct. 149 // We only update the settings once all of them are correct.
138 checkin_interval_ = new_checkin_interval; 150 checkin_interval_ = new_checkin_interval;
139 mcs_hostname_ = new_mcs_hostname; 151 mcs_hostname_ = new_mcs_hostname;
140 mcs_secure_port_ = new_mcs_secure_port; 152 mcs_secure_port_ = new_mcs_secure_port;
141 checkin_url_ = new_checkin_url; 153 checkin_url_ = new_checkin_url;
142 registration_url_ = new_registration_url; 154 registration_url_ = new_registration_url;
143 return true; 155 return true;
144 } 156 }
145 157
146 void GServicesSettings::SetGServicesSettingsCallback(bool success) { 158 void GServicesSettings::SetGServicesSettingsCallback(bool success) {
147 DCHECK(success); 159 DCHECK(success);
148 } 160 }
149 161
150 } // namespace gcm 162 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/gservices_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698