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