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

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

Issue 1548673002: Switch to standard integer types in google_apis/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years 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
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 <stdint.h>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h"
9 #include "base/sha1.h" 12 #include "base/sha1.h"
10 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
13 #include "google_apis/gcm/engine/gservices_switches.h" 16 #include "google_apis/gcm/engine/gservices_switches.h"
14 17
15 namespace { 18 namespace {
16 // The expected time in seconds between periodic checkins. 19 // The expected time in seconds between periodic checkins.
17 const char kCheckinIntervalKey[] = "checkin_interval"; 20 const char kCheckinIntervalKey[] = "checkin_interval";
18 // The override URL to the checkin server. 21 // The override URL to the checkin server.
19 const char kCheckinURLKey[] = "checkin_url"; 22 const char kCheckinURLKey[] = "checkin_url";
20 // The MCS machine name to connect to. 23 // The MCS machine name to connect to.
21 const char kMCSHostnameKey[] = "gcm_hostname"; 24 const char kMCSHostnameKey[] = "gcm_hostname";
22 // The MCS port to connect to. 25 // The MCS port to connect to.
23 const char kMCSSecurePortKey[] = "gcm_secure_port"; 26 const char kMCSSecurePortKey[] = "gcm_secure_port";
24 // The URL to get MCS registration IDs. 27 // The URL to get MCS registration IDs.
25 const char kRegistrationURLKey[] = "gcm_registration_url"; 28 const char kRegistrationURLKey[] = "gcm_registration_url";
26 29
27 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. 30 const int64_t kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days.
28 const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours. 31 const int64_t kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours.
29 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; 32 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin";
30 const char kDefaultMCSHostname[] = "mtalk.google.com"; 33 const char kDefaultMCSHostname[] = "mtalk.google.com";
31 const int kDefaultMCSMainSecurePort = 5228; 34 const int kDefaultMCSMainSecurePort = 5228;
32 const int kDefaultMCSFallbackSecurePort = 443; 35 const int kDefaultMCSFallbackSecurePort = 443;
33 const char kDefaultRegistrationURL[] = 36 const char kDefaultRegistrationURL[] =
34 "https://android.clients.google.com/c2dm/register3"; 37 "https://android.clients.google.com/c2dm/register3";
35 // Settings that are to be deleted are marked with this prefix in checkin 38 // Settings that are to be deleted are marked with this prefix in checkin
36 // response. 39 // response.
37 const char kDeleteSettingPrefix[] = "delete_"; 40 const char kDeleteSettingPrefix[] = "delete_";
38 // Settings digest starts with verison number followed by '-'. 41 // Settings digest starts with verison number followed by '-'.
(...skipping 15 matching lines...) Expand all
54 settings_name == kRegistrationURLKey; 57 settings_name == kRegistrationURLKey;
55 } 58 }
56 59
57 bool VerifyCheckinInterval( 60 bool VerifyCheckinInterval(
58 const gcm::GServicesSettings::SettingsMap& settings) { 61 const gcm::GServicesSettings::SettingsMap& settings) {
59 gcm::GServicesSettings::SettingsMap::const_iterator iter = 62 gcm::GServicesSettings::SettingsMap::const_iterator iter =
60 settings.find(kCheckinIntervalKey); 63 settings.find(kCheckinIntervalKey);
61 if (iter == settings.end()) 64 if (iter == settings.end())
62 return CanBeOmitted(kCheckinIntervalKey); 65 return CanBeOmitted(kCheckinIntervalKey);
63 66
64 int64 checkin_interval = kMinimumCheckinInterval; 67 int64_t checkin_interval = kMinimumCheckinInterval;
65 if (!base::StringToInt64(iter->second, &checkin_interval)) { 68 if (!base::StringToInt64(iter->second, &checkin_interval)) {
66 DVLOG(1) << "Failed to parse checkin interval: " << iter->second; 69 DVLOG(1) << "Failed to parse checkin interval: " << iter->second;
67 return false; 70 return false;
68 } 71 }
69 if (checkin_interval == std::numeric_limits<int64>::max()) { 72 if (checkin_interval == std::numeric_limits<int64_t>::max()) {
70 DVLOG(1) << "Checkin interval is too big: " << checkin_interval; 73 DVLOG(1) << "Checkin interval is too big: " << checkin_interval;
71 return false; 74 return false;
72 } 75 }
73 if (checkin_interval < kMinimumCheckinInterval) { 76 if (checkin_interval < kMinimumCheckinInterval) {
74 DVLOG(1) << "Checkin interval: " << checkin_interval 77 DVLOG(1) << "Checkin interval: " << checkin_interval
75 << " is less than allowed minimum: " << kMinimumCheckinInterval; 78 << " is less than allowed minimum: " << kMinimumCheckinInterval;
76 } 79 }
77 80
78 return true; 81 return true;
79 } 82 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 << "Expected digest: " << load_result.gservices_digest 260 << "Expected digest: " << load_result.gservices_digest
258 << ". Calculated digest is: " << digest; 261 << ". Calculated digest is: " << digest;
259 return; 262 return;
260 } 263 }
261 264
262 settings_ = load_result.gservices_settings; 265 settings_ = load_result.gservices_settings;
263 digest_ = load_result.gservices_digest; 266 digest_ = load_result.gservices_digest;
264 } 267 }
265 268
266 base::TimeDelta GServicesSettings::GetCheckinInterval() const { 269 base::TimeDelta GServicesSettings::GetCheckinInterval() const {
267 int64 checkin_interval = kMinimumCheckinInterval; 270 int64_t checkin_interval = kMinimumCheckinInterval;
268 SettingsMap::const_iterator iter = settings_.find(kCheckinIntervalKey); 271 SettingsMap::const_iterator iter = settings_.find(kCheckinIntervalKey);
269 if (iter == settings_.end() || 272 if (iter == settings_.end() ||
270 !base::StringToInt64(iter->second, &checkin_interval)) { 273 !base::StringToInt64(iter->second, &checkin_interval)) {
271 checkin_interval = kDefaultCheckinInterval; 274 checkin_interval = kDefaultCheckinInterval;
272 } 275 }
273 276
274 if (checkin_interval < kMinimumCheckinInterval) 277 if (checkin_interval < kMinimumCheckinInterval)
275 checkin_interval = kMinimumCheckinInterval; 278 checkin_interval = kMinimumCheckinInterval;
276 279
277 return base::TimeDelta::FromSeconds(checkin_interval); 280 return base::TimeDelta::FromSeconds(checkin_interval);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 command_line->GetSwitchValueASCII(switches::kGCMRegistrationURL)); 351 command_line->GetSwitchValueASCII(switches::kGCMRegistrationURL));
349 } 352 }
350 353
351 SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey); 354 SettingsMap::const_iterator iter = settings_.find(kRegistrationURLKey);
352 if (iter == settings_.end() || iter->second.empty()) 355 if (iter == settings_.end() || iter->second.empty())
353 return GURL(kDefaultRegistrationURL); 356 return GURL(kDefaultRegistrationURL);
354 return GURL(iter->second); 357 return GURL(iter->second);
355 } 358 }
356 359
357 } // namespace gcm 360 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/gservices_settings.h ('k') | google_apis/gcm/engine/gservices_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698