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/base/load_flags.h" |
23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 24 #include "net/traffic_annotation/network_traffic_annotation.h" |
24 #include "net/url_request/url_fetcher.h" | 25 #include "net/url_request/url_fetcher.h" |
25 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
26 | 27 |
27 #if !defined(OS_ANDROID) | 28 #if !defined(OS_ANDROID) |
28 // channel_common.proto defines ANDROID constant that conflicts with Android | 29 // channel_common.proto defines ANDROID constant that conflicts with Android |
29 // build. At the same time TiclInvalidationService is not used on Android so it | 30 // build. At the same time TiclInvalidationService is not used on Android so it |
30 // is safe to exclude these protos from Android build. | 31 // is safe to exclude these protos from Android build. |
31 #include "google/cacheinvalidation/android_channel.pb.h" | 32 #include "google/cacheinvalidation/android_channel.pb.h" |
32 #include "google/cacheinvalidation/channel_common.pb.h" | 33 #include "google/cacheinvalidation/channel_common.pb.h" |
33 #include "google/cacheinvalidation/types.pb.h" | 34 #include "google/cacheinvalidation/types.pb.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // Message won't get sent. Notify that http channel doesn't work. | 212 // Message won't get sent. Notify that http channel doesn't work. |
212 UpdateHttpChannelState(false); | 213 UpdateHttpChannelState(false); |
213 cached_message_.clear(); | 214 cached_message_.clear(); |
214 return; | 215 return; |
215 } | 216 } |
216 DCHECK(!token.empty()); | 217 DCHECK(!token.empty()); |
217 // Save access token in case POST fails and we need to invalidate it. | 218 // Save access token in case POST fails and we need to invalidate it. |
218 access_token_ = token; | 219 access_token_ = token; |
219 | 220 |
220 DVLOG(2) << "Got access token, sending message"; | 221 DVLOG(2) << "Got access token, sending message"; |
221 fetcher_ = net::URLFetcher::Create(BuildUrl(registration_id_), | 222 net::NetworkTrafficAnnotationTag traffic_annotation = |
222 net::URLFetcher::POST, this); | 223 net::DefineNetworkTrafficAnnotation("invalidation_service", R"( |
| 224 semantics { |
| 225 sender: "Invalidation service" |
| 226 description: |
| 227 "Chromium uses cacheinvalidation library to receive push " |
| 228 "notifications from the server about sync items (bookmarks, " |
| 229 "passwords, preferences, etc.) modified on other clients. It uses " |
| 230 "GCMClient to receive incoming messages. This request is used for " |
| 231 "client-to-server communications." |
| 232 trigger: |
| 233 "The first message is sent to register client with the server on " |
| 234 "Chromium startup. It is then sent periodically to confirm that " |
| 235 "the client is still online. After receiving notification about " |
| 236 "server changes, the client sends this request to acknowledge that " |
| 237 "the notification is processed." |
| 238 data: |
| 239 "Different in each use case:\n" |
| 240 "- Initial registration: Doesn't contain user data.\n" |
| 241 "- Updating the set of subscriptions: Contains server generated " |
| 242 "client_token and ObjectIds identifying subscriptions. ObjectId " |
| 243 "is not unique to user.\n" |
| 244 "- Invalidation acknowledgement: Contains client_token, ObjectId " |
| 245 "and server version for corresponding subscription. Version is not " |
| 246 "related to sync data, it is an internal concept of invalidations " |
| 247 "protocol." |
| 248 destination: GOOGLE_OWNED_SERVICE |
| 249 } |
| 250 policy { |
| 251 cookies_allowed: false |
| 252 setting: "This feature cannot be disabled." |
| 253 policy_exception_justification: |
| 254 "Not implemented. Disabling InvalidationService might break " |
| 255 "features that depend on it. It makes sense to control top level " |
| 256 "features that use InvalidationService." |
| 257 })"); |
| 258 fetcher_ = |
| 259 net::URLFetcher::Create(BuildUrl(registration_id_), net::URLFetcher::POST, |
| 260 this, traffic_annotation); |
223 data_use_measurement::DataUseUserData::AttachToFetcher( | 261 data_use_measurement::DataUseUserData::AttachToFetcher( |
224 fetcher_.get(), data_use_measurement::DataUseUserData::INVALIDATION); | 262 fetcher_.get(), data_use_measurement::DataUseUserData::INVALIDATION); |
225 fetcher_->SetRequestContext(request_context_getter_.get()); | 263 fetcher_->SetRequestContext(request_context_getter_.get()); |
226 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 264 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
227 net::LOAD_DO_NOT_SAVE_COOKIES); | 265 net::LOAD_DO_NOT_SAVE_COOKIES); |
228 const std::string auth_header("Authorization: Bearer " + access_token_); | 266 const std::string auth_header("Authorization: Bearer " + access_token_); |
229 fetcher_->AddExtraRequestHeader(auth_header); | 267 fetcher_->AddExtraRequestHeader(auth_header); |
230 if (!echo_token_.empty()) { | 268 if (!echo_token_.empty()) { |
231 const std::string echo_header("echo-token: " + echo_token_); | 269 const std::string echo_header("echo-token: " + echo_token_); |
232 fetcher_->AddExtraRequestHeader(echo_header); | 270 fetcher_->AddExtraRequestHeader(echo_header); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); | 484 ENUM_CASE(gcm::GCMClient::UNKNOWN_ERROR); |
447 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); | 485 ENUM_CASE(gcm::GCMClient::INVALID_PARAMETER); |
448 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); | 486 ENUM_CASE(gcm::GCMClient::ASYNC_OPERATION_PENDING); |
449 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); | 487 ENUM_CASE(gcm::GCMClient::GCM_DISABLED); |
450 } | 488 } |
451 NOTREACHED(); | 489 NOTREACHED(); |
452 return ""; | 490 return ""; |
453 } | 491 } |
454 | 492 |
455 } // namespace syncer | 493 } // namespace syncer |
OLD | NEW |