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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/i18n/time_formatting.h" | 6 #include "base/i18n/time_formatting.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
14 #if !defined(OS_ANDROID) | 14 #if !defined(OS_ANDROID) |
15 // channel_common.proto defines ANDROID constant that conflicts with Android | 15 // channel_common.proto defines ANDROID constant that conflicts with Android |
16 // build. At the same time TiclInvalidationService is not used on Android so it | 16 // build. At the same time TiclInvalidationService is not used on Android so it |
17 // is safe to exclude these protos from Android build. | 17 // is safe to exclude these protos from Android build. |
18 #include "google/cacheinvalidation/android_channel.pb.h" | 18 #include "google/cacheinvalidation/android_channel.pb.h" |
19 #include "google/cacheinvalidation/channel_common.pb.h" | 19 #include "google/cacheinvalidation/channel_common.pb.h" |
20 #include "google/cacheinvalidation/types.pb.h" | 20 #include "google/cacheinvalidation/types.pb.h" |
21 #endif | 21 #endif |
22 #include "components/data_use_measurement/core/data_use_user_data.h" | |
23 #include "components/invalidation/impl/gcm_network_channel.h" | 22 #include "components/invalidation/impl/gcm_network_channel.h" |
24 #include "components/invalidation/impl/gcm_network_channel_delegate.h" | 23 #include "components/invalidation/impl/gcm_network_channel_delegate.h" |
25 #include "google_apis/gaia/google_service_auth_error.h" | 24 #include "google_apis/gaia/google_service_auth_error.h" |
26 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
27 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
28 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
29 | 28 |
30 namespace syncer { | 29 namespace syncer { |
31 | 30 |
32 namespace { | 31 namespace { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 cached_message_.clear(); | 204 cached_message_.clear(); |
206 return; | 205 return; |
207 } | 206 } |
208 DCHECK(!token.empty()); | 207 DCHECK(!token.empty()); |
209 // Save access token in case POST fails and we need to invalidate it. | 208 // Save access token in case POST fails and we need to invalidate it. |
210 access_token_ = token; | 209 access_token_ = token; |
211 | 210 |
212 DVLOG(2) << "Got access token, sending message"; | 211 DVLOG(2) << "Got access token, sending message"; |
213 fetcher_ = net::URLFetcher::Create(BuildUrl(registration_id_), | 212 fetcher_ = net::URLFetcher::Create(BuildUrl(registration_id_), |
214 net::URLFetcher::POST, this); | 213 net::URLFetcher::POST, this); |
215 data_use_measurement::DataUseUserData::AttachToFetcher( | |
216 fetcher_.get(), data_use_measurement::DataUseUserData::INVALIDATION); | |
217 fetcher_->SetRequestContext(request_context_getter_.get()); | 214 fetcher_->SetRequestContext(request_context_getter_.get()); |
218 const std::string auth_header("Authorization: Bearer " + access_token_); | 215 const std::string auth_header("Authorization: Bearer " + access_token_); |
219 fetcher_->AddExtraRequestHeader(auth_header); | 216 fetcher_->AddExtraRequestHeader(auth_header); |
220 if (!echo_token_.empty()) { | 217 if (!echo_token_.empty()) { |
221 const std::string echo_header("echo-token: " + echo_token_); | 218 const std::string echo_header("echo-token: " + echo_token_); |
222 fetcher_->AddExtraRequestHeader(echo_header); | 219 fetcher_->AddExtraRequestHeader(echo_header); |
223 } | 220 } |
224 fetcher_->SetUploadData("application/x-protobuffer", cached_message_); | 221 fetcher_->SetUploadData("application/x-protobuffer", cached_message_); |
225 fetcher_->Start(); | 222 fetcher_->Start(); |
226 // Clear message to prevent accidentally resending it in the future. | 223 // Clear message to prevent accidentally resending it in the future. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); | 450 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); |
454 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); | 451 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); |
455 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); | 452 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); |
456 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); | 453 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); |
457 } | 454 } |
458 NOTREACHED(); | 455 NOTREACHED(); |
459 return ""; | 456 return ""; |
460 } | 457 } |
461 | 458 |
462 } // namespace syncer | 459 } // namespace syncer |
OLD | NEW |