OLD | NEW |
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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } // namespace | 171 } // namespace |
172 | 172 |
173 namespace gcm { | 173 namespace gcm { |
174 | 174 |
175 // static | 175 // static |
176 const base::TimeDelta GServicesSettings::MinimumCheckinInterval() { | 176 const base::TimeDelta GServicesSettings::MinimumCheckinInterval() { |
177 return base::TimeDelta::FromSeconds(kMinimumCheckinInterval); | 177 return base::TimeDelta::FromSeconds(kMinimumCheckinInterval); |
178 } | 178 } |
179 | 179 |
180 // static | 180 // static |
181 const GURL GServicesSettings::DefaultCheckinURL() { | |
182 return GURL(kDefaultCheckinURL); | |
183 } | |
184 | |
185 // static | |
186 std::string GServicesSettings::CalculateDigest(const SettingsMap& settings) { | 181 std::string GServicesSettings::CalculateDigest(const SettingsMap& settings) { |
187 unsigned char hash[base::kSHA1Length]; | 182 unsigned char hash[base::kSHA1Length]; |
188 std::string data; | 183 std::string data; |
189 for (SettingsMap::const_iterator iter = settings.begin(); | 184 for (SettingsMap::const_iterator iter = settings.begin(); |
190 iter != settings.end(); | 185 iter != settings.end(); |
191 ++iter) { | 186 ++iter) { |
192 data += iter->first; | 187 data += iter->first; |
193 data += '\0'; | 188 data += '\0'; |
194 data += iter->second; | 189 data += iter->second; |
195 data += '\0'; | 190 data += '\0'; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 checkin_interval = kDefaultCheckinInterval; | 271 checkin_interval = kDefaultCheckinInterval; |
277 } | 272 } |
278 | 273 |
279 if (checkin_interval < kMinimumCheckinInterval) | 274 if (checkin_interval < kMinimumCheckinInterval) |
280 checkin_interval = kMinimumCheckinInterval; | 275 checkin_interval = kMinimumCheckinInterval; |
281 | 276 |
282 return base::TimeDelta::FromSeconds(checkin_interval); | 277 return base::TimeDelta::FromSeconds(checkin_interval); |
283 } | 278 } |
284 | 279 |
285 GURL GServicesSettings::GetCheckinURL() const { | 280 GURL GServicesSettings::GetCheckinURL() const { |
| 281 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 282 if (command_line->HasSwitch(switches::kGCMCheckinURL)) |
| 283 return GURL(command_line->GetSwitchValueASCII(switches::kGCMCheckinURL)); |
| 284 |
286 SettingsMap::const_iterator iter = settings_.find(kCheckinURLKey); | 285 SettingsMap::const_iterator iter = settings_.find(kCheckinURLKey); |
287 if (iter == settings_.end() || iter->second.empty()) | 286 if (iter == settings_.end() || iter->second.empty()) |
288 return GURL(kDefaultCheckinURL); | 287 return GURL(kDefaultCheckinURL); |
289 return GURL(iter->second); | 288 return GURL(iter->second); |
290 } | 289 } |
291 | 290 |
292 GURL GServicesSettings::GetMCSMainEndpoint() const { | 291 GURL GServicesSettings::GetMCSMainEndpoint() const { |
| 292 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 293 if (command_line->HasSwitch(switches::kGCMMCSEndpoint)) |
| 294 return GURL(command_line->GetSwitchValueASCII(switches::kGCMMCSEndpoint)); |
| 295 |
293 // Get alternative hostname or use default. | 296 // Get alternative hostname or use default. |
294 std::string mcs_hostname; | 297 std::string mcs_hostname; |
295 SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey); | 298 SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey); |
296 if (iter != settings_.end() && !iter->second.empty()) | 299 if (iter != settings_.end() && !iter->second.empty()) |
297 mcs_hostname = iter->second; | 300 mcs_hostname = iter->second; |
298 else | 301 else |
299 mcs_hostname = kDefaultMCSHostname; | 302 mcs_hostname = kDefaultMCSHostname; |
300 | 303 |
301 // Get alternative secure port or use defualt. | 304 // Get alternative secure port or use defualt. |
302 int mcs_secure_port = 0; | 305 int mcs_secure_port = 0; |
303 iter = settings_.find(kMCSSecurePortKey); | 306 iter = settings_.find(kMCSSecurePortKey); |
304 if (iter == settings_.end() || iter->second.empty() || | 307 if (iter == settings_.end() || iter->second.empty() || |
305 !base::StringToInt(iter->second, &mcs_secure_port)) { | 308 !base::StringToInt(iter->second, &mcs_secure_port)) { |
306 mcs_secure_port = kDefaultMCSMainSecurePort; | 309 mcs_secure_port = kDefaultMCSMainSecurePort; |
307 } | 310 } |
308 | 311 |
309 // If constructed address makes sense use it. | 312 // If constructed address makes sense use it. |
310 GURL mcs_endpoint(MakeMCSEndpoint(mcs_hostname, mcs_secure_port)); | 313 GURL mcs_endpoint(MakeMCSEndpoint(mcs_hostname, mcs_secure_port)); |
311 if (mcs_endpoint.is_valid()) | 314 if (mcs_endpoint.is_valid()) |
312 return mcs_endpoint; | 315 return mcs_endpoint; |
313 | 316 |
314 // Otherwise use default settings. | 317 // Otherwise use default settings. |
315 return GURL(MakeMCSEndpoint(kDefaultMCSHostname, kDefaultMCSMainSecurePort)); | 318 return GURL(MakeMCSEndpoint(kDefaultMCSHostname, kDefaultMCSMainSecurePort)); |
316 } | 319 } |
317 | 320 |
318 GURL GServicesSettings::GetMCSFallbackEndpoint() const { | 321 GURL GServicesSettings::GetMCSFallbackEndpoint() const { |
| 322 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 323 if (command_line->HasSwitch(switches::kGCMMCSEndpoint)) |
| 324 return GURL(); // No fallback endpoint when using command line override. |
| 325 |
319 // Get alternative hostname or use default. | 326 // Get alternative hostname or use default. |
320 std::string mcs_hostname; | 327 std::string mcs_hostname; |
321 SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey); | 328 SettingsMap::const_iterator iter = settings_.find(kMCSHostnameKey); |
322 if (iter != settings_.end() && !iter->second.empty()) | 329 if (iter != settings_.end() && !iter->second.empty()) |
323 mcs_hostname = iter->second; | 330 mcs_hostname = iter->second; |
324 else | 331 else |
325 mcs_hostname = kDefaultMCSHostname; | 332 mcs_hostname = kDefaultMCSHostname; |
326 | 333 |
327 // If constructed address makes sense use it. | 334 // If constructed address makes sense use it. |
328 GURL mcs_endpoint( | 335 GURL mcs_endpoint( |
329 MakeMCSEndpoint(mcs_hostname, kDefaultMCSFallbackSecurePort)); | 336 MakeMCSEndpoint(mcs_hostname, kDefaultMCSFallbackSecurePort)); |
330 if (mcs_endpoint.is_valid()) | 337 if (mcs_endpoint.is_valid()) |
331 return mcs_endpoint; | 338 return mcs_endpoint; |
332 | 339 |
333 return GURL( | 340 return GURL( |
334 MakeMCSEndpoint(kDefaultMCSHostname, kDefaultMCSFallbackSecurePort)); | 341 MakeMCSEndpoint(kDefaultMCSHostname, kDefaultMCSFallbackSecurePort)); |
335 } | 342 } |
336 | 343 |
337 GURL GServicesSettings::GetRegistrationURL() const { | 344 GURL GServicesSettings::GetRegistrationURL() const { |
338 SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey); | 345 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
339 if (iter == settings_.end() || iter->second.empty()) { | 346 if (command_line->HasSwitch(switches::kGCMRegistrationURL)) { |
340 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
341 if (!command_line->HasSwitch(switches::kGCMRegistrationURL)) | |
342 return GURL(kDefaultRegistrationURL); | |
343 | |
344 return GURL( | 347 return GURL( |
345 command_line->GetSwitchValueASCII(switches::kGCMRegistrationURL)); | 348 command_line->GetSwitchValueASCII(switches::kGCMRegistrationURL)); |
346 } | 349 } |
| 350 |
| 351 SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey); |
| 352 if (iter == settings_.end() || iter->second.empty()) |
| 353 return GURL(kDefaultRegistrationURL); |
347 return GURL(iter->second); | 354 return GURL(iter->second); |
348 } | 355 } |
349 | 356 |
350 } // namespace gcm | 357 } // namespace gcm |
OLD | NEW |