| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/sync/driver/sync_stopped_reporter.h" | 5 #include "components/sync/driver/sync_stopped_reporter.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "components/data_use_measurement/core/data_use_user_data.h" | 12 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 13 #include "components/sync/protocol/sync.pb.h" | 13 #include "components/sync/protocol/sync.pb.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kEventEndpoint[] = "event"; | 20 const char kEventEndpoint[] = "event"; |
| 20 | 21 |
| 21 // The request is tiny, so even on poor connections 10 seconds should be | 22 // The request is tiny, so even on poor connections 10 seconds should be |
| 22 // plenty of time. Since sync is off when this request is started, we don't | 23 // plenty of time. Since sync is off when this request is started, we don't |
| 23 // want anything sync-related hanging around for very long from a human | 24 // want anything sync-related hanging around for very long from a human |
| 24 // perspective either. This seems like a good compromise. | 25 // perspective either. This seems like a good compromise. |
| 25 const int kRequestTimeoutSeconds = 10; | 26 const int kRequestTimeoutSeconds = 10; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 // Make the request proto with the GUID identifying this client. | 55 // Make the request proto with the GUID identifying this client. |
| 55 sync_pb::EventRequest event_request; | 56 sync_pb::EventRequest event_request; |
| 56 sync_pb::SyncDisabledEvent* sync_disabled_event = | 57 sync_pb::SyncDisabledEvent* sync_disabled_event = |
| 57 event_request.mutable_sync_disabled(); | 58 event_request.mutable_sync_disabled(); |
| 58 sync_disabled_event->set_cache_guid(cache_guid); | 59 sync_disabled_event->set_cache_guid(cache_guid); |
| 59 sync_disabled_event->set_store_birthday(birthday); | 60 sync_disabled_event->set_store_birthday(birthday); |
| 60 | 61 |
| 61 std::string msg; | 62 std::string msg; |
| 62 event_request.SerializeToString(&msg); | 63 event_request.SerializeToString(&msg); |
| 63 | 64 |
| 64 fetcher_ = | 65 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 65 net::URLFetcher::Create(sync_event_url_, net::URLFetcher::POST, this); | 66 net::DefineNetworkTrafficAnnotation("sync_stop_reporter", R"( |
| 67 semantics { |
| 68 sender: "Chrome Sync" |
| 69 description: |
| 70 "A network request to inform Chrome Sync that sync has been " |
| 71 "disabled for this device." |
| 72 trigger: "User disables sync." |
| 73 data: "The sync device id and store birthday." |
| 74 destination: GOOGLE_OWNED_SERVICE |
| 75 } |
| 76 policy { |
| 77 cookies_allowed: false |
| 78 setting: "This feature cannot be disabled by settings." |
| 79 policy_exception_justification: |
| 80 "Not required, this network request is only performed after the " |
| 81 "user has opted in to sync and then disables sync." |
| 82 })"); |
| 83 fetcher_ = net::URLFetcher::Create(sync_event_url_, net::URLFetcher::POST, |
| 84 this, traffic_annotation); |
| 66 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 85 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
| 67 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization, | 86 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization, |
| 68 access_token.c_str())); | 87 access_token.c_str())); |
| 69 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 88 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
| 70 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); | 89 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); |
| 71 fetcher_->SetRequestContext(request_context_.get()); | 90 fetcher_->SetRequestContext(request_context_.get()); |
| 72 fetcher_->SetUploadData("application/octet-stream", msg); | 91 fetcher_->SetUploadData("application/octet-stream", msg); |
| 73 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 92 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
| 74 net::LOAD_DO_NOT_SAVE_COOKIES | | 93 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 75 net::LOAD_DO_NOT_SEND_COOKIES); | 94 net::LOAD_DO_NOT_SEND_COOKIES); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 if (path.empty() || *path.rbegin() != '/') { | 124 if (path.empty() || *path.rbegin() != '/') { |
| 106 path += '/'; | 125 path += '/'; |
| 107 } | 126 } |
| 108 path += kEventEndpoint; | 127 path += kEventEndpoint; |
| 109 GURL::Replacements replacements; | 128 GURL::Replacements replacements; |
| 110 replacements.SetPathStr(path); | 129 replacements.SetPathStr(path); |
| 111 return sync_service_url.ReplaceComponents(replacements); | 130 return sync_service_url.ReplaceComponents(replacements); |
| 112 } | 131 } |
| 113 | 132 |
| 114 } // namespace syncer | 133 } // namespace syncer |
| OLD | NEW |