| 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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; | 23 const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; |
| 24 const char kDefaultMCSHostname[] = "https://mtalk.google.com"; | 24 const char kDefaultMCSHostname[] = "https://mtalk.google.com"; |
| 25 const int kDefaultMCSSecurePort = 5228; | 25 const int kDefaultMCSSecurePort = 5228; |
| 26 const char kDefaultRegistrationURL[] = | 26 const char kDefaultRegistrationURL[] = |
| 27 "https://android.clients.google.com/c2dm/register3"; | 27 "https://android.clients.google.com/c2dm/register3"; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 namespace gcm { | 31 namespace gcm { |
| 32 | 32 |
| 33 const int64 GServicesSettings::kMinimumCheckinInterval = 12 * 60 * 60; |
| 34 |
| 33 GServicesSettings::GServicesSettings(GCMStore* gcm_store) | 35 GServicesSettings::GServicesSettings(GCMStore* gcm_store) |
| 34 : gcm_store_(gcm_store), | 36 : gcm_store_(gcm_store), |
| 35 checkin_interval_(kDefaultCheckinInterval), | 37 checkin_interval_(kDefaultCheckinInterval), |
| 36 checkin_url_(kDefaultCheckinURL), | 38 checkin_url_(kDefaultCheckinURL), |
| 37 mcs_hostname_(kDefaultMCSHostname), | 39 mcs_hostname_(kDefaultMCSHostname), |
| 38 mcs_secure_port_(kDefaultMCSSecurePort), | 40 mcs_secure_port_(kDefaultMCSSecurePort), |
| 39 registration_url_(kDefaultRegistrationURL), | 41 registration_url_(kDefaultRegistrationURL), |
| 40 weak_ptr_factory_(this) { | 42 weak_ptr_factory_(this) { |
| 41 } | 43 } |
| 42 | 44 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 70 } | 72 } |
| 71 | 73 |
| 72 void GServicesSettings::UpdateFromLoadResult( | 74 void GServicesSettings::UpdateFromLoadResult( |
| 73 const GCMStore::LoadResult& load_result) { | 75 const GCMStore::LoadResult& load_result) { |
| 74 if (UpdateSettings(load_result.gservices_settings)) | 76 if (UpdateSettings(load_result.gservices_settings)) |
| 75 digest_ = load_result.gservices_digest; | 77 digest_ = load_result.gservices_digest; |
| 76 } | 78 } |
| 77 | 79 |
| 78 bool GServicesSettings::UpdateSettings( | 80 bool GServicesSettings::UpdateSettings( |
| 79 const std::map<std::string, std::string>& settings) { | 81 const std::map<std::string, std::string>& settings) { |
| 80 int64 new_checkin_interval = 0LL; | 82 int64 new_checkin_interval = kMinimumCheckinInterval; |
| 81 std::map<std::string, std::string>::const_iterator iter = | 83 std::map<std::string, std::string>::const_iterator iter = |
| 82 settings.find(kCheckinIntervalKey); | 84 settings.find(kCheckinIntervalKey); |
| 83 if (iter != settings.end()) { | 85 if (iter == settings.end()) { |
| 84 if (!base::StringToInt64(iter->second, &new_checkin_interval)) { | 86 LOG(ERROR) << "Setting not found: " << kCheckinIntervalKey; |
| 85 LOG(ERROR) << "Failed to parse checkin interval: " << iter->second; | 87 return false; |
| 86 return false; | 88 } |
| 87 } | 89 if (!base::StringToInt64(iter->second, &new_checkin_interval)) { |
| 88 if (new_checkin_interval <= 0LL) { | 90 LOG(ERROR) << "Failed to parse checkin interval: " << iter->second; |
| 89 LOG(ERROR) << "Checkin interval not positive: " << new_checkin_interval; | 91 return false; |
| 90 return false; | 92 } |
| 91 } | 93 if (new_checkin_interval < kMinimumCheckinInterval) { |
| 94 LOG(ERROR) << "Checkin interval: " << new_checkin_interval |
| 95 << " is less than allowed minimum: " << kMinimumCheckinInterval; |
| 96 new_checkin_interval = kMinimumCheckinInterval; |
| 92 } | 97 } |
| 93 | 98 |
| 94 std::string new_mcs_hostname; | 99 std::string new_mcs_hostname; |
| 100 iter = settings.find(kMCSHostnameKey); |
| 101 if (iter == settings.end()) { |
| 102 LOG(ERROR) << "Setting not found: " << kMCSHostnameKey; |
| 103 return false; |
| 104 } |
| 105 new_mcs_hostname = iter->second; |
| 106 if (new_mcs_hostname.empty()) { |
| 107 LOG(ERROR) << "Empty MCS hostname provided."; |
| 108 return false; |
| 109 } |
| 110 |
| 95 int new_mcs_secure_port = -1; | 111 int new_mcs_secure_port = -1; |
| 96 iter = settings.find(kMCSHostnameKey); | 112 iter = settings.find(kMCSSecurePortKey); |
| 97 if (iter != settings.end()) { | 113 if (iter == settings.end()) { |
| 98 new_mcs_hostname = iter->second; | 114 LOG(ERROR) << "Setting not found: " << kMCSSecurePortKey; |
| 99 if (new_mcs_hostname.empty()) { | 115 return false; |
| 100 LOG(ERROR) << "Empty MCS hostname provided."; | 116 } |
| 101 return false; | 117 if (!base::StringToInt(iter->second, &new_mcs_secure_port)) { |
| 102 } | 118 LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second; |
| 103 | 119 return false; |
| 104 iter = settings.find(kMCSSecurePortKey); | 120 } |
| 105 if (iter != settings.end()) { | 121 if (new_mcs_secure_port < 0 || 65535 < new_mcs_secure_port) { |
| 106 if (!base::StringToInt(iter->second, &new_mcs_secure_port)) { | 122 LOG(ERROR) << "Incorrect port value: " << new_mcs_secure_port; |
| 107 LOG(ERROR) << "Failed to parse MCS secure port: " << iter->second; | 123 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 } | 124 } |
| 116 | 125 |
| 117 std::string new_checkin_url; | 126 std::string new_checkin_url; |
| 118 iter = settings.find(kCheckinURLKey); | 127 iter = settings.find(kCheckinURLKey); |
| 119 if (iter != settings.end()) { | 128 if (iter == settings.end()) { |
| 120 new_checkin_url = iter->second; | 129 LOG(ERROR) << "Setting not found: " << kCheckinURLKey; |
| 121 if (new_checkin_url.empty()) { | 130 return false; |
| 122 LOG(ERROR) << "Empty checkin URL provided."; | 131 } |
| 123 return false; | 132 new_checkin_url = iter->second; |
| 124 } | 133 if (new_checkin_url.empty()) { |
| 134 LOG(ERROR) << "Empty checkin URL provided."; |
| 135 return false; |
| 125 } | 136 } |
| 126 | 137 |
| 127 std::string new_registration_url; | 138 std::string new_registration_url; |
| 128 iter = settings.find(kRegistrationURLKey); | 139 iter = settings.find(kRegistrationURLKey); |
| 129 if (iter != settings.end()) { | 140 if (iter == settings.end()) { |
| 130 new_registration_url = iter->second; | 141 LOG(ERROR) << "Setting not found: " << kRegistrationURLKey; |
| 131 if (new_registration_url.empty()) { | 142 return false; |
| 132 LOG(ERROR) << "Empty registration URL provided."; | 143 } |
| 133 return false; | 144 new_registration_url = iter->second; |
| 134 } | 145 if (new_registration_url.empty()) { |
| 146 LOG(ERROR) << "Empty registration URL provided."; |
| 147 return false; |
| 135 } | 148 } |
| 136 | 149 |
| 137 // We only update the settings once all of them are correct. | 150 // We only update the settings once all of them are correct. |
| 138 checkin_interval_ = new_checkin_interval; | 151 checkin_interval_ = new_checkin_interval; |
| 139 mcs_hostname_ = new_mcs_hostname; | 152 mcs_hostname_ = new_mcs_hostname; |
| 140 mcs_secure_port_ = new_mcs_secure_port; | 153 mcs_secure_port_ = new_mcs_secure_port; |
| 141 checkin_url_ = new_checkin_url; | 154 checkin_url_ = new_checkin_url; |
| 142 registration_url_ = new_registration_url; | 155 registration_url_ = new_registration_url; |
| 143 return true; | 156 return true; |
| 144 } | 157 } |
| 145 | 158 |
| 146 void GServicesSettings::SetGServicesSettingsCallback(bool success) { | 159 void GServicesSettings::SetGServicesSettingsCallback(bool success) { |
| 147 DCHECK(success); | 160 DCHECK(success); |
| 148 } | 161 } |
| 149 | 162 |
| 150 } // namespace gcm | 163 } // namespace gcm |
| OLD | NEW |