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

Unified Diff: sync/notifier/gcm_network_channel.cc

Issue 182333003: Build correct URL for cacheinvalidation endpoint. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@RollCacheInvalidations
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/notifier/gcm_network_channel.h ('k') | sync/notifier/gcm_network_channel_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/notifier/gcm_network_channel.cc
diff --git a/sync/notifier/gcm_network_channel.cc b/sync/notifier/gcm_network_channel.cc
index c6fbd0239dc60cd1fb2574793dbeb19a3c3224e8..99ad6242e507db69c3b67fb0bec82c3cd53d2689 100644
--- a/sync/notifier/gcm_network_channel.cc
+++ b/sync/notifier/gcm_network_channel.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/base64.h"
+#include "google/cacheinvalidation/android_channel.pb.h"
+#include "google/cacheinvalidation/channel_common.pb.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
@@ -13,6 +16,10 @@ namespace syncer {
namespace {
+const char kCacheInvalidationEndpointUrl[] =
+ "https://clients4.google.com/invalidation/android/request/";
+const char kCacheInvalidationPackageName[] = "com.google.chrome.invalidations";
+
// Register backoff policy.
const net::BackoffEntry::Policy kRegisterBackoffPolicy = {
// Number of initial errors (in sequence) to ignore before applying
@@ -142,9 +149,8 @@ void GCMNetworkChannel::OnGetTokenComplete(
access_token_ = token;
DVLOG(2) << "Got access token, sending message";
-
- fetcher_.reset(net::URLFetcher::Create(BuildUrl(), net::URLFetcher::POST,
- this));
+ fetcher_.reset(net::URLFetcher::Create(
+ BuildUrl(registration_id_), net::URLFetcher::POST, this));
fetcher_->SetRequestContext(request_context_getter_);
const std::string auth_header("Authorization: Bearer " + access_token_);
fetcher_->AddExtraRequestHeader(auth_header);
@@ -174,13 +180,30 @@ void GCMNetworkChannel::OnURLFetchComplete(const net::URLFetcher* source) {
DVLOG(2) << "URLFetcher success";
}
-GURL GCMNetworkChannel::BuildUrl() {
- DCHECK(!registration_id_.empty());
- // Prepare NetworkEndpointId using registration_id
- // Serialize NetworkEndpointId into byte array and base64 encode.
- // Format url using encoded NetworkEndpointId.
- // TODO(pavely): implement all of the above.
- return GURL("http://invalid.url.com");
+GURL GCMNetworkChannel::BuildUrl(const std::string& registration_id) {
+ DCHECK(!registration_id.empty());
+ std::string buffer;
+
+ ipc::invalidation::EndpointId endpoint_id;
+ endpoint_id.set_c2dm_registration_id(registration_id);
+ endpoint_id.set_client_key(std::string());
+ endpoint_id.set_package_name(kCacheInvalidationPackageName);
+ endpoint_id.mutable_channel_version()->set_major_version(
+ ipc::invalidation::INITIAL);
+ endpoint_id.SerializeToString(&buffer);
+
+ ipc::invalidation::NetworkEndpointId network_endpoint_id;
+ network_endpoint_id.set_network_address(
+ ipc::invalidation::NetworkEndpointId_NetworkAddress_ANDROID);
+ network_endpoint_id.set_client_address(buffer);
rlarocque 2014/02/26 22:55:46 Couldn't you get the same serialized result by mak
pavely 2014/02/26 23:11:13 If network_address is not NetworkAddress::ANDROID
+ network_endpoint_id.SerializeToString(&buffer);
rlarocque 2014/02/26 22:55:46 I'd prefer to see a different buffer for this seri
pavely 2014/02/26 23:11:13 Done.
+
+ std::string base64URLPiece;
+ base::Base64Encode(buffer, &base64URLPiece);
+
+ std::string url(kCacheInvalidationEndpointUrl);
+ url += base64URLPiece;
+ return GURL(url);
}
} // namespace syncer
« no previous file with comments | « sync/notifier/gcm_network_channel.h ('k') | sync/notifier/gcm_network_channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698