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 |