diff options
author | fgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 00:51:13 +0000 |
---|---|---|
committer | fgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-02 00:51:13 +0000 |
commit | f0935451bd271481031d8ddc990d044f8fc216e7 (patch) | |
tree | b5341f9149ac3e561b94faf3d8ac72754df7b1a9 /google_apis | |
parent | 2a53aefd0d85dfe4b91747a6aec7015480bab999 (diff) | |
download | chromium_src-f0935451bd271481031d8ddc990d044f8fc216e7.zip chromium_src-f0935451bd271481031d8ddc990d044f8fc216e7.tar.gz chromium_src-f0935451bd271481031d8ddc990d044f8fc216e7.tar.bz2 |
[GCM] Updating GServicesSettings to use GURLs and TimeDelta
Updating G-services settings to provide checkin and registration URLs as GURLs
Updating checkin_interval to be a time delta, removing fixed TODOs
BUG=359254
Review URL: https://codereview.chromium.org/244883004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r-- | google_apis/gcm/engine/checkin_request.cc | 6 | ||||
-rw-r--r-- | google_apis/gcm/engine/checkin_request.h | 5 | ||||
-rw-r--r-- | google_apis/gcm/engine/checkin_request_unittest.cc | 8 | ||||
-rw-r--r-- | google_apis/gcm/engine/gservices_settings.cc | 32 | ||||
-rw-r--r-- | google_apis/gcm/engine/gservices_settings.h | 25 | ||||
-rw-r--r-- | google_apis/gcm/engine/gservices_settings_unittest.cc | 16 | ||||
-rw-r--r-- | google_apis/gcm/engine/registration_request.cc | 6 | ||||
-rw-r--r-- | google_apis/gcm/engine/registration_request.h | 3 | ||||
-rw-r--r-- | google_apis/gcm/engine/registration_request_unittest.cc | 6 | ||||
-rw-r--r-- | google_apis/gcm/engine/unregistration_request.cc | 7 | ||||
-rw-r--r-- | google_apis/gcm/engine/unregistration_request.h | 3 | ||||
-rw-r--r-- | google_apis/gcm/engine/unregistration_request_unittest.cc | 4 | ||||
-rw-r--r-- | google_apis/gcm/gcm_client_impl.cc | 10 | ||||
-rw-r--r-- | google_apis/gcm/gcm_client_impl_unittest.cc | 3 | ||||
-rw-r--r-- | google_apis/gcm/tools/mcs_probe.cc | 2 |
15 files changed, 85 insertions, 51 deletions
diff --git a/google_apis/gcm/engine/checkin_request.cc b/google_apis/gcm/engine/checkin_request.cc index 7addbeb..f4d0c5c 100644 --- a/google_apis/gcm/engine/checkin_request.cc +++ b/google_apis/gcm/engine/checkin_request.cc @@ -11,12 +11,10 @@ #include "net/http/http_status_code.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_status.h" -#include "url/gurl.h" namespace gcm { namespace { -const char kCheckinURL[] = "https://android.clients.google.com/checkin"; const char kRequestContentType[] = "application/x-protobuf"; const int kRequestVersionValue = 2; const int kDefaultUserSerialNumber = 0; @@ -62,6 +60,7 @@ CheckinRequest::RequestInfo::RequestInfo( CheckinRequest::RequestInfo::~RequestInfo() {} CheckinRequest::CheckinRequest( + const GURL& checkin_url, const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const CheckinRequestCallback& callback, @@ -69,6 +68,7 @@ CheckinRequest::CheckinRequest( : request_context_getter_(request_context_getter), callback_(callback), backoff_entry_(&backoff_policy), + checkin_url_(checkin_url), request_info_(request_info), weak_ptr_factory_(this) { } @@ -105,7 +105,7 @@ void CheckinRequest::Start() { CHECK(request.SerializeToString(&upload_data)); url_fetcher_.reset( - net::URLFetcher::Create(GURL(kCheckinURL), net::URLFetcher::POST, this)); + net::URLFetcher::Create(checkin_url_, net::URLFetcher::POST, this)); url_fetcher_->SetRequestContext(request_context_getter_); url_fetcher_->SetUploadData(kRequestContentType, upload_data); url_fetcher_->Start(); diff --git a/google_apis/gcm/engine/checkin_request.h b/google_apis/gcm/engine/checkin_request.h index 5ae8dd3..abe4e6e 100644 --- a/google_apis/gcm/engine/checkin_request.h +++ b/google_apis/gcm/engine/checkin_request.h @@ -16,6 +16,7 @@ #include "google_apis/gcm/protocol/checkin.pb.h" #include "net/base/backoff_entry.h" #include "net/url_request/url_fetcher_delegate.h" +#include "url/gurl.h" namespace net { class URLRequestContextGetter; @@ -55,7 +56,8 @@ class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { checkin_proto::ChromeBuildProto chrome_build_proto; }; - CheckinRequest(const RequestInfo& request_info, + CheckinRequest(const GURL& checkin_url, + const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const CheckinRequestCallback& callback, net::URLRequestContextGetter* request_context_getter); @@ -75,6 +77,7 @@ class GCM_EXPORT CheckinRequest : public net::URLFetcherDelegate { CheckinRequestCallback callback_; net::BackoffEntry backoff_entry_; + GURL checkin_url_; scoped_ptr<net::URLFetcher> url_fetcher_; const RequestInfo request_info_; diff --git a/google_apis/gcm/engine/checkin_request_unittest.cc b/google_apis/gcm/engine/checkin_request_unittest.cc index e750df0..23ad430 100644 --- a/google_apis/gcm/engine/checkin_request_unittest.cc +++ b/google_apis/gcm/engine/checkin_request_unittest.cc @@ -49,6 +49,7 @@ const net::BackoffEntry::Policy kDefaultBackoffPolicy = { const uint64 kAndroidId = 42UL; const uint64 kBlankAndroidId = 999999UL; const uint64 kBlankSecurityToken = 999999UL; +const char kCheckinURL[] = "http://foo.bar/checkin"; const char kChromeVersion[] = "Version String"; const uint64 kSecurityToken = 77; const char kSettingsDigest[] = "settings_digest"; @@ -131,6 +132,7 @@ void CheckinRequestTest::CreateRequest(uint64 android_id, // Then create a request with that protobuf and specified android_id, // security_token. request_.reset(new CheckinRequest( + GURL(kCheckinURL), request_info, kDefaultBackoffPolicy, base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), @@ -179,17 +181,17 @@ void CheckinRequestTest::SetResponse(ResponseScenario response_scenario) { SetResponseStatusAndString(net::HTTP_OK, response_string); } -TEST_F(CheckinRequestTest, FetcherData) { +TEST_F(CheckinRequestTest, FetcherDataAndURL) { CreateRequest(kAndroidId, kSecurityToken); request_->Start(); // Get data sent by request. net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); ASSERT_TRUE(fetcher); - fetcher->set_response_code(net::HTTP_OK); + EXPECT_EQ(GURL(kCheckinURL), fetcher->GetOriginalURL()); + checkin_proto::AndroidCheckinRequest request_proto; request_proto.ParseFromString(fetcher->upload_data()); - EXPECT_EQ(kAndroidId, static_cast<uint64>(request_proto.id())); EXPECT_EQ(kSecurityToken, request_proto.security_token()); EXPECT_EQ(chrome_build_proto_.platform(), diff --git a/google_apis/gcm/engine/gservices_settings.cc b/google_apis/gcm/engine/gservices_settings.cc index 20b9d7d..340d1a7 100644 --- a/google_apis/gcm/engine/gservices_settings.cc +++ b/google_apis/gcm/engine/gservices_settings.cc @@ -20,6 +20,7 @@ const char kMCSSecurePortKey[] = "gcm_secure_port"; const char kRegistrationURLKey[] = "gcm_registration_url"; const int64 kDefaultCheckinInterval = 2 * 24 * 60 * 60; // seconds = 2 days. +const int64 kMinimumCheckinInterval = 12 * 60 * 60; // seconds = 12 hours. const char kDefaultCheckinURL[] = "https://android.clients.google.com/checkin"; const char kDefaultMCSHostname[] = "https://mtalk.google.com"; const int kDefaultMCSSecurePort = 5228; @@ -30,11 +31,14 @@ const char kDefaultRegistrationURL[] = namespace gcm { -const int64 GServicesSettings::kMinimumCheckinInterval = 12 * 60 * 60; +// static +const base::TimeDelta GServicesSettings::MinimumCheckinInterval() { + return base::TimeDelta::FromSeconds(kMinimumCheckinInterval); +} GServicesSettings::GServicesSettings(GCMStore* gcm_store) : gcm_store_(gcm_store), - checkin_interval_(kDefaultCheckinInterval), + checkin_interval_(base::TimeDelta::FromSeconds(kDefaultCheckinInterval)), checkin_url_(kDefaultCheckinURL), mcs_hostname_(kDefaultMCSHostname), mcs_secure_port_(kDefaultMCSSecurePort), @@ -95,6 +99,10 @@ bool GServicesSettings::UpdateSettings( << " is less than allowed minimum: " << kMinimumCheckinInterval; new_checkin_interval = kMinimumCheckinInterval; } + if (new_checkin_interval == std::numeric_limits<int64>::max()) { + LOG(ERROR) << "Checkin interval is too big: " << new_checkin_interval; + return false; + } std::string new_mcs_hostname; iter = settings.find(kMCSHostnameKey); @@ -123,32 +131,34 @@ bool GServicesSettings::UpdateSettings( return false; } - std::string new_checkin_url; + GURL new_checkin_url; iter = settings.find(kCheckinURLKey); if (iter == settings.end()) { LOG(ERROR) << "Setting not found: " << kCheckinURLKey; return false; } - new_checkin_url = iter->second; - if (new_checkin_url.empty()) { - LOG(ERROR) << "Empty checkin URL provided."; + new_checkin_url = GURL(iter->second); + if (!new_checkin_url.is_valid()) { + LOG(ERROR) << "Invalid checkin URL provided: " + << new_checkin_url.possibly_invalid_spec(); return false; } - std::string new_registration_url; + GURL new_registration_url; iter = settings.find(kRegistrationURLKey); if (iter == settings.end()) { LOG(ERROR) << "Setting not found: " << kRegistrationURLKey; return false; } - new_registration_url = iter->second; - if (new_registration_url.empty()) { - LOG(ERROR) << "Empty registration URL provided."; + new_registration_url = GURL(iter->second); + if (!new_registration_url.is_valid()) { + LOG(ERROR) << "Invalid registration URL provided: " + << new_registration_url.possibly_invalid_spec(); return false; } // We only update the settings once all of them are correct. - checkin_interval_ = new_checkin_interval; + checkin_interval_ = base::TimeDelta::FromSeconds(new_checkin_interval); mcs_hostname_ = new_mcs_hostname; mcs_secure_port_ = new_mcs_secure_port; checkin_url_ = new_checkin_url; diff --git a/google_apis/gcm/engine/gservices_settings.h b/google_apis/gcm/engine/gservices_settings.h index 775c676..9cc6727 100644 --- a/google_apis/gcm/engine/gservices_settings.h +++ b/google_apis/gcm/engine/gservices_settings.h @@ -9,9 +9,11 @@ #include <string> #include "base/memory/weak_ptr.h" +#include "base/time/time.h" #include "google_apis/gcm/base/gcm_export.h" #include "google_apis/gcm/engine/gcm_store.h" #include "google_apis/gcm/protocol/checkin.pb.h" +#include "url/gurl.h" namespace gcm { @@ -20,7 +22,7 @@ namespace gcm { class GCM_EXPORT GServicesSettings { public: // Minimum periodic checkin interval in seconds. - static const int64 kMinimumCheckinInterval; + static const base::TimeDelta MinimumCheckinInterval(); // Create an instance of GServicesSettings class. |gcm_store| is used to store // the settings after they are extracted from checkin response. @@ -34,21 +36,18 @@ class GCM_EXPORT GServicesSettings { // Updates the settings based on |load_result|. void UpdateFromLoadResult(const GCMStore::LoadResult& load_result); - const std::string& digest() const { return digest_; } + std::string digest() const { return digest_; } - // TODO(fgorski): Consider returning TimeDelta. - int64 checkin_interval() const { return checkin_interval_; } + base::TimeDelta checkin_interval() const { return checkin_interval_; } - // TODO(fgorski): Consider returning GURL and use it for validation. - const std::string& checkin_url() const { return checkin_url_; } + GURL checkin_url() const { return checkin_url_; } // TODO(fgorski): Consider returning GURL and use it for validation. - const std::string& mcs_hostname() const { return mcs_hostname_; } + std::string mcs_hostname() const { return mcs_hostname_; } int mcs_secure_port() const { return mcs_secure_port_; } - // TODO(fgorski): Consider returning GURL and use it for validation. - const std::string& registration_url() const { return registration_url_; } + GURL registration_url() const { return registration_url_; } private: // Parses the |settings| to fill in specific fields. @@ -66,11 +65,11 @@ class GCM_EXPORT GServicesSettings { // settings table. std::string digest_; - // Time in seconds between periodic checkins. - int64 checkin_interval_; + // Time delta between periodic checkins. + base::TimeDelta checkin_interval_; // URL that should be used for checkins. - std::string checkin_url_; + GURL checkin_url_; // Hostname of the MCS server. std::string mcs_hostname_; @@ -79,7 +78,7 @@ class GCM_EXPORT GServicesSettings { int mcs_secure_port_; // URL that should be used for regisrations and unregistrations. - std::string registration_url_; + GURL registration_url_; // Factory for creating references in callbacks. base::WeakPtrFactory<GServicesSettings> weak_ptr_factory_; diff --git a/google_apis/gcm/engine/gservices_settings_unittest.cc b/google_apis/gcm/engine/gservices_settings_unittest.cc index de756f8..9ed4d9f 100644 --- a/google_apis/gcm/engine/gservices_settings_unittest.cc +++ b/google_apis/gcm/engine/gservices_settings_unittest.cc @@ -145,19 +145,21 @@ void GServicesSettingsTest::SetUp() { } void GServicesSettingsTest::CheckAllSetToDefault() { - EXPECT_EQ(kDefaultCheckinInterval, settings().checkin_interval()); - EXPECT_EQ(kDefaultCheckinURL, settings().checkin_url()); + EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultCheckinInterval), + settings().checkin_interval()); + EXPECT_EQ(GURL(kDefaultCheckinURL), settings().checkin_url()); EXPECT_EQ(kDefaultMCSHostname, settings().mcs_hostname()); EXPECT_EQ(kDefaultMCSSecurePort, settings().mcs_secure_port()); - EXPECT_EQ(kDefaultRegistrationURL, settings().registration_url()); + EXPECT_EQ(GURL(kDefaultRegistrationURL), settings().registration_url()); } void GServicesSettingsTest::CheckAllSetToAlternative() { - EXPECT_EQ(kAlternativeCheckinInterval, settings().checkin_interval()); - EXPECT_EQ(kAlternativeCheckinURL, settings().checkin_url()); + EXPECT_EQ(base::TimeDelta::FromSeconds(kAlternativeCheckinInterval), + settings().checkin_interval()); + EXPECT_EQ(GURL(kAlternativeCheckinURL), settings().checkin_url()); EXPECT_EQ(kAlternativeMCSHostname, settings().mcs_hostname()); EXPECT_EQ(kAlternativeMCSSecurePort, settings().mcs_secure_port()); - EXPECT_EQ(kAlternativeRegistrationURL, settings().registration_url()); + EXPECT_EQ(GURL(kAlternativeRegistrationURL), settings().registration_url()); } void GServicesSettingsTest::SetWithAlternativeSettings( @@ -238,7 +240,7 @@ TEST_F(GServicesSettingsTest, UpdateFromCheckinResponseMinimumCheckinInterval) { settings().UpdateFromCheckinResponse(checkin_response); EXPECT_TRUE(gcm_store().settings_saved()); - EXPECT_EQ(GServicesSettings::kMinimumCheckinInterval, + EXPECT_EQ(GServicesSettings::MinimumCheckinInterval(), settings().checkin_interval()); EXPECT_EQ("digest_value", settings().digest()); } diff --git a/google_apis/gcm/engine/registration_request.cc b/google_apis/gcm/engine/registration_request.cc index 13a040b..dd3f369 100644 --- a/google_apis/gcm/engine/registration_request.cc +++ b/google_apis/gcm/engine/registration_request.cc @@ -22,8 +22,6 @@ namespace gcm { namespace { -const char kRegistrationURL[] = - "https://android.clients.google.com/c2dm/register3"; const char kRegistrationRequestContentType[] = "application/x-www-form-urlencoded"; @@ -99,6 +97,7 @@ RegistrationRequest::RequestInfo::RequestInfo( RegistrationRequest::RequestInfo::~RequestInfo() {} RegistrationRequest::RegistrationRequest( + const GURL& registration_url, const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const RegistrationCallback& callback, @@ -107,6 +106,7 @@ RegistrationRequest::RegistrationRequest( GCMStatsRecorder* recorder) : callback_(callback), request_info_(request_info), + registration_url_(registration_url), backoff_entry_(&backoff_policy), request_context_getter_(request_context_getter), retries_left_(max_retry_count), @@ -126,7 +126,7 @@ void RegistrationRequest::Start() { DCHECK(!url_fetcher_.get()); url_fetcher_.reset(net::URLFetcher::Create( - GURL(kRegistrationURL), net::URLFetcher::POST, this)); + registration_url_, net::URLFetcher::POST, this)); url_fetcher_->SetRequestContext(request_context_getter_); std::string android_id = base::Uint64ToString(request_info_.android_id); diff --git a/google_apis/gcm/engine/registration_request.h b/google_apis/gcm/engine/registration_request.h index 95ec4d9..30bed41 100644 --- a/google_apis/gcm/engine/registration_request.h +++ b/google_apis/gcm/engine/registration_request.h @@ -16,6 +16,7 @@ #include "google_apis/gcm/base/gcm_export.h" #include "net/base/backoff_entry.h" #include "net/url_request/url_fetcher_delegate.h" +#include "url/gurl.h" namespace net { class URLRequestContextGetter; @@ -80,6 +81,7 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate { }; RegistrationRequest( + const GURL& registration_url, const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const RegistrationCallback& callback, @@ -104,6 +106,7 @@ class GCM_EXPORT RegistrationRequest : public net::URLFetcherDelegate { RegistrationCallback callback_; RequestInfo request_info_; + GURL registration_url_; net::BackoffEntry backoff_entry_; scoped_refptr<net::URLRequestContextGetter> request_context_getter_; diff --git a/google_apis/gcm/engine/registration_request_unittest.cc b/google_apis/gcm/engine/registration_request_unittest.cc index 859f20b..37f2575 100644 --- a/google_apis/gcm/engine/registration_request_unittest.cc +++ b/google_apis/gcm/engine/registration_request_unittest.cc @@ -22,6 +22,7 @@ const uint64 kAndroidId = 42UL; const char kAppId[] = "TestAppId"; const char kDeveloperId[] = "Project1"; const char kLoginHeader[] = "AidLogin"; +const char kRegistrationURL[] = "http://foo.bar/register"; const uint64 kSecurityToken = 77UL; // Backoff policy for testing registration request. @@ -108,6 +109,7 @@ void RegistrationRequestTest::CreateRequest(const std::string& sender_ids) { senders.push_back(tokenizer.token()); request_.reset(new RegistrationRequest( + GURL(kRegistrationURL), RegistrationRequest::RequestInfo(kAndroidId, kSecurityToken, kAppId, @@ -152,7 +154,7 @@ TEST_F(RegistrationRequestTest, RequestSuccessful) { EXPECT_EQ("2501", registration_id_); } -TEST_F(RegistrationRequestTest, RequestDataPassedToFetcher) { +TEST_F(RegistrationRequestTest, RequestDataAndURL) { CreateRequest(kDeveloperId); request_->Start(); @@ -160,6 +162,8 @@ TEST_F(RegistrationRequestTest, RequestDataPassedToFetcher) { net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); ASSERT_TRUE(fetcher); + EXPECT_EQ(GURL(kRegistrationURL), fetcher->GetOriginalURL()); + // Verify that authorization header was put together properly. net::HttpRequestHeaders headers; fetcher->GetExtraRequestHeaders(&headers); diff --git a/google_apis/gcm/engine/unregistration_request.cc b/google_apis/gcm/engine/unregistration_request.cc index dbcce84..92136bf 100644 --- a/google_apis/gcm/engine/unregistration_request.cc +++ b/google_apis/gcm/engine/unregistration_request.cc @@ -17,14 +17,11 @@ #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" -#include "url/gurl.h" namespace gcm { namespace { -const char kRegistrationURL[] = - "https://android.clients.google.com/c2dm/register3"; const char kRequestContentType[] = "application/x-www-form-urlencoded"; // Request constants. @@ -113,6 +110,7 @@ UnregistrationRequest::RequestInfo::RequestInfo( UnregistrationRequest::RequestInfo::~RequestInfo() {} UnregistrationRequest::UnregistrationRequest( + const GURL& registration_url, const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const UnregistrationCallback& callback, @@ -120,6 +118,7 @@ UnregistrationRequest::UnregistrationRequest( GCMStatsRecorder* recorder) : callback_(callback), request_info_(request_info), + registration_url_(registration_url), backoff_entry_(&backoff_policy), request_context_getter_(request_context_getter), recorder_(recorder), @@ -135,7 +134,7 @@ void UnregistrationRequest::Start() { DCHECK(!url_fetcher_.get()); url_fetcher_.reset(net::URLFetcher::Create( - GURL(kRegistrationURL), net::URLFetcher::POST, this)); + registration_url_, net::URLFetcher::POST, this)); url_fetcher_->SetRequestContext(request_context_getter_); std::string android_id = base::Uint64ToString(request_info_.android_id); diff --git a/google_apis/gcm/engine/unregistration_request.h b/google_apis/gcm/engine/unregistration_request.h index ad9b82c..b25e28c 100644 --- a/google_apis/gcm/engine/unregistration_request.h +++ b/google_apis/gcm/engine/unregistration_request.h @@ -13,6 +13,7 @@ #include "google_apis/gcm/base/gcm_export.h" #include "net/base/backoff_entry.h" #include "net/url_request/url_fetcher_delegate.h" +#include "url/gurl.h" namespace net { class URLRequestContextGetter; @@ -72,6 +73,7 @@ class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { // once registration has been revoked or there has been an error that makes // further retries pointless. UnregistrationRequest( + const GURL& registration_url, const RequestInfo& request_info, const net::BackoffEntry::Policy& backoff_policy, const UnregistrationCallback& callback, @@ -92,6 +94,7 @@ class GCM_EXPORT UnregistrationRequest : public net::URLFetcherDelegate { UnregistrationCallback callback_; RequestInfo request_info_; + GURL registration_url_; net::BackoffEntry backoff_entry_; scoped_refptr<net::URLRequestContextGetter> request_context_getter_; diff --git a/google_apis/gcm/engine/unregistration_request_unittest.cc b/google_apis/gcm/engine/unregistration_request_unittest.cc index dff9fb7..02f4968 100644 --- a/google_apis/gcm/engine/unregistration_request_unittest.cc +++ b/google_apis/gcm/engine/unregistration_request_unittest.cc @@ -21,6 +21,7 @@ const uint64 kAndroidId = 42UL; const char kLoginHeader[] = "AidLogin"; const char kAppId[] = "TestAppId"; const char kDeletedAppId[] = "deleted=TestAppId"; +const char kRegistrationURL[] = "http://foo.bar/register"; const uint64 kSecurityToken = 77UL; // Backoff policy for testing registration request. @@ -91,6 +92,7 @@ void UnregistrationRequestTest::UnregistrationCallback( void UnregistrationRequestTest::CreateRequest() { request_.reset(new UnregistrationRequest( + GURL(kRegistrationURL), UnregistrationRequest::RequestInfo(kAndroidId, kSecurityToken, kAppId), @@ -126,6 +128,8 @@ TEST_F(UnregistrationRequestTest, RequestDataPassedToFetcher) { net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); ASSERT_TRUE(fetcher); + EXPECT_EQ(GURL(kRegistrationURL), fetcher->GetOriginalURL()); + // Verify that authorization header was put together properly. net::HttpRequestHeaders headers; fetcher->GetExtraRequestHeaders(&headers); diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc index 2a59bbf..13b7eb8 100644 --- a/google_apis/gcm/gcm_client_impl.cc +++ b/google_apis/gcm/gcm_client_impl.cc @@ -307,7 +307,8 @@ void GCMClientImpl::StartCheckin() { account_ids_, chrome_build_proto_); checkin_request_.reset( - new CheckinRequest(request_info, + new CheckinRequest(gservices_settings_->checkin_url(), + request_info, kDefaultBackoffPolicy, base::Bind(&GCMClientImpl::OnCheckinCompleted, weak_ptr_factory_.GetWeakPtr()), @@ -373,8 +374,7 @@ void GCMClientImpl::SchedulePeriodicCheckin() { } base::TimeDelta GCMClientImpl::GetTimeToNextCheckin() const { - return last_checkin_time_ + - base::TimeDelta::FromSeconds(gservices_settings_->checkin_interval()) - + return last_checkin_time_ + gservices_settings_->checkin_interval() - clock_->Now(); } @@ -432,7 +432,8 @@ void GCMClientImpl::Register(const std::string& app_id, DCHECK_EQ(0u, pending_registration_requests_.count(app_id)); RegistrationRequest* registration_request = - new RegistrationRequest(request_info, + new RegistrationRequest(gservices_settings_->registration_url(), + request_info, kDefaultBackoffPolicy, base::Bind(&GCMClientImpl::OnRegisterCompleted, weak_ptr_factory_.GetWeakPtr(), @@ -507,6 +508,7 @@ void GCMClientImpl::Unregister(const std::string& app_id) { UnregistrationRequest* unregistration_request = new UnregistrationRequest( + gservices_settings_->registration_url(), request_info, kDefaultBackoffPolicy, base::Bind(&GCMClientImpl::OnUnregisterCompleted, diff --git a/google_apis/gcm/gcm_client_impl_unittest.cc b/google_apis/gcm/gcm_client_impl_unittest.cc index 25c0afd..451c2c4 100644 --- a/google_apis/gcm/gcm_client_impl_unittest.cc +++ b/google_apis/gcm/gcm_client_impl_unittest.cc @@ -723,7 +723,8 @@ TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { settings["gcm_registration_url"] = "http://alternative.url/registration"; CompleteCheckin( kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); - EXPECT_EQ(kSettingsCheckinInterval, gservices_settings()->checkin_interval()); + EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), + gservices_settings()->checkin_interval()); } // This test only checks that periodic checkin happens. diff --git a/google_apis/gcm/tools/mcs_probe.cc b/google_apis/gcm/tools/mcs_probe.cc index af757d2..863e9e3 100644 --- a/google_apis/gcm/tools/mcs_probe.cc +++ b/google_apis/gcm/tools/mcs_probe.cc @@ -28,6 +28,7 @@ #include "google_apis/gcm/engine/checkin_request.h" #include "google_apis/gcm/engine/connection_factory_impl.h" #include "google_apis/gcm/engine/gcm_store_impl.h" +#include "google_apis/gcm/engine/gservices_settings.h" #include "google_apis/gcm/engine/mcs_client.h" #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" #include "net/base/host_mapping_rules.h" @@ -433,6 +434,7 @@ void MCSProbe::CheckIn() { 0, 0, std::string(), std::vector<std::string>(), chrome_build_proto); checkin_request_.reset(new CheckinRequest( + GServicesSettings(gcm_store_.get()).checkin_url(), request_info, kDefaultBackoffPolicy, base::Bind(&MCSProbe::OnCheckInCompleted, base::Unretained(this)), |