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

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

Issue 270403006: Adding handling of MCS Endpoints to GServicesSettings (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
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 #include "base/strings/stringprintf.h"
9 10
10 namespace { 11 namespace {
11 // The expected time in seconds between periodic checkins. 12 // The expected time in seconds between periodic checkins.
12 const char kCheckinIntervalKey[] = "checkin_interval"; 13 const char kCheckinIntervalKey[] = "checkin_interval";
13 // The override URL to the checkin server. 14 // The override URL to the checkin server.
14 const char kCheckinURLKey[] = "checkin_url"; 15 const char kCheckinURLKey[] = "checkin_url";
15 // The MCS machine name to connect to. 16 // The MCS machine name to connect to.
16 const char kMCSHostnameKey[] = "gcm_hostname"; 17 const char kMCSHostnameKey[] = "gcm_hostname";
17 // The MCS port to connect to. 18 // The MCS port to connect to.
18 const char kMCSSecurePortKey[] = "gcm_secure_port"; 19 const char kMCSSecurePortKey[] = "gcm_secure_port";
19 // The URL to get MCS registration IDs. 20 // The URL to get MCS registration IDs.
20 const char kRegistrationURLKey[] = "gcm_registration_url"; 21 const char kRegistrationURLKey[] = "gcm_registration_url";
21 22
22 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. 23 const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days.
23 const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours. 24 const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours.
24 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; 25 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin";
25 const char kDefaultMCSHostname[] = "https://mtalk.google.com"; 26 const char kDefaultMCSHostname[] = "mtalk.google.com";
26 const int kDefaultMCSSecurePort = 5228; 27 const int kDefaultMCSSecurePort = 5228;
jianli 2014/05/08 18:59:37 nit: kDefaultMCSMainSecurePort
fgorski 2014/05/08 19:21:03 Done.
28 const int kDefaultMCSFallbackPort = 443;
jianli 2014/05/08 18:59:37 nit: better to add "Secure" into the name, like kD
fgorski 2014/05/08 19:21:03 Done.
27 const char kDefaultRegistrationURL[] = 29 const char kDefaultRegistrationURL[] =
28 "https://android.clients.google.com/c2dm/register3"; 30 "https://android.clients.google.com/c2dm/register3";
31 const char kMCSEnpointTemplate[] = "https://%s:%d";
32
33 std::string MakeMCSEndpoint(const std::string& mcs_hostname, int port) {
34 return base::StringPrintf(kMCSEnpointTemplate, mcs_hostname.c_str(), port);
35 }
29 36
30 } // namespace 37 } // namespace
31 38
32 namespace gcm { 39 namespace gcm {
33 40
34 // static 41 // static
35 const base::TimeDelta GServicesSettings::MinimumCheckinInterval() { 42 const base::TimeDelta GServicesSettings::MinimumCheckinInterval() {
36 return base::TimeDelta::FromSeconds(kMinimumCheckinInterval); 43 return base::TimeDelta::FromSeconds(kMinimumCheckinInterval);
37 } 44 }
38 45
39 // static 46 // static
40 const GURL GServicesSettings::DefaultCheckinURL() { 47 const GURL GServicesSettings::DefaultCheckinURL() {
41 return GURL(kDefaultCheckinURL); 48 return GURL(kDefaultCheckinURL);
42 } 49 }
43 50
44 GServicesSettings::GServicesSettings() 51 GServicesSettings::GServicesSettings()
45 : checkin_interval_(base::TimeDelta::FromSeconds(kDefaultCheckinInterval)), 52 : checkin_interval_(base::TimeDelta::FromSeconds(kDefaultCheckinInterval)),
46 checkin_url_(kDefaultCheckinURL), 53 checkin_url_(kDefaultCheckinURL),
47 mcs_hostname_(kDefaultMCSHostname), 54 mcs_main_endpoint_(MakeMCSEndpoint(kDefaultMCSHostname,
48 mcs_secure_port_(kDefaultMCSSecurePort), 55 kDefaultMCSSecurePort)),
56 mcs_fallback_endpoint_(MakeMCSEndpoint(kDefaultMCSHostname,
57 kDefaultMCSFallbackPort)),
49 registration_url_(kDefaultRegistrationURL), 58 registration_url_(kDefaultRegistrationURL),
50 weak_ptr_factory_(this) { 59 weak_ptr_factory_(this) {
51 } 60 }
52 61
53 GServicesSettings::~GServicesSettings() {} 62 GServicesSettings::~GServicesSettings() {}
54 63
55 bool GServicesSettings::UpdateFromCheckinResponse( 64 bool GServicesSettings::UpdateFromCheckinResponse(
56 const checkin_proto::AndroidCheckinResponse& checkin_response) { 65 const checkin_proto::AndroidCheckinResponse& checkin_response) {
57 if (!checkin_response.has_digest() || 66 if (!checkin_response.has_digest() ||
58 checkin_response.digest() == digest_) { 67 checkin_response.digest() == digest_) {
(...skipping 22 matching lines...) Expand all
81 const GCMStore::LoadResult& load_result) { 90 const GCMStore::LoadResult& load_result) {
82 if (UpdateSettings(load_result.gservices_settings)) 91 if (UpdateSettings(load_result.gservices_settings))
83 digest_ = load_result.gservices_digest; 92 digest_ = load_result.gservices_digest;
84 } 93 }
85 94
86 std::map<std::string, std::string> GServicesSettings::GetSettingsMap() const { 95 std::map<std::string, std::string> GServicesSettings::GetSettingsMap() const {
87 std::map<std::string, std::string> settings; 96 std::map<std::string, std::string> settings;
88 settings[kCheckinIntervalKey] = 97 settings[kCheckinIntervalKey] =
89 base::Int64ToString(checkin_interval_.InSeconds()); 98 base::Int64ToString(checkin_interval_.InSeconds());
90 settings[kCheckinURLKey] = checkin_url_.spec(); 99 settings[kCheckinURLKey] = checkin_url_.spec();
91 settings[kMCSHostnameKey] = mcs_hostname_; 100 settings[kMCSHostnameKey] = mcs_main_endpoint_.host();
92 settings[kMCSSecurePortKey] = base::IntToString(mcs_secure_port_); 101 settings[kMCSSecurePortKey] = mcs_main_endpoint_.port();
93 settings[kRegistrationURLKey] = registration_url_.spec(); 102 settings[kRegistrationURLKey] = registration_url_.spec();
94 return settings; 103 return settings;
95 } 104 }
96 105
97 bool GServicesSettings::UpdateSettings( 106 bool GServicesSettings::UpdateSettings(
98 const std::map<std::string, std::string>& settings) { 107 const std::map<std::string, std::string>& settings) {
99 int64 new_checkin_interval = kMinimumCheckinInterval; 108 int64 new_checkin_interval = kMinimumCheckinInterval;
100 std::map<std::string, std::string>::const_iterator iter = 109 std::map<std::string, std::string>::const_iterator iter =
101 settings.find(kCheckinIntervalKey); 110 settings.find(kCheckinIntervalKey);
102 if (iter == settings.end()) { 111 if (iter == settings.end()) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 174 }
166 new_registration_url = GURL(iter->second); 175 new_registration_url = GURL(iter->second);
167 if (!new_registration_url.is_valid()) { 176 if (!new_registration_url.is_valid()) {
168 LOG(ERROR) << "Invalid registration URL provided: " 177 LOG(ERROR) << "Invalid registration URL provided: "
169 << new_registration_url.possibly_invalid_spec(); 178 << new_registration_url.possibly_invalid_spec();
170 return false; 179 return false;
171 } 180 }
172 181
173 // We only update the settings once all of them are correct. 182 // We only update the settings once all of them are correct.
174 checkin_interval_ = base::TimeDelta::FromSeconds(new_checkin_interval); 183 checkin_interval_ = base::TimeDelta::FromSeconds(new_checkin_interval);
175 mcs_hostname_ = new_mcs_hostname; 184 mcs_main_endpoint_ = GURL(MakeMCSEndpoint(new_mcs_hostname,
jianli 2014/05/08 18:59:37 Can you validate the URL?
fgorski 2014/05/08 19:21:03 Done.
176 mcs_secure_port_ = new_mcs_secure_port; 185 new_mcs_secure_port));
186 mcs_fallback_endpoint_ = GURL(MakeMCSEndpoint(new_mcs_hostname,
187 kDefaultMCSFallbackPort));
177 checkin_url_ = new_checkin_url; 188 checkin_url_ = new_checkin_url;
178 registration_url_ = new_registration_url; 189 registration_url_ = new_registration_url;
179 return true; 190 return true;
180 } 191 }
181 192
182 } // namespace gcm 193 } // 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