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: "Sync device identifier and metadata." |
| 74 destination: GOOGLE_OWNED_SERVICE |
| 75 } |
| 76 policy { |
| 77 cookies_allowed: false |
| 78 setting: "This feature cannot be disabled by settings." |
| 79 chrome_policy { |
| 80 SyncDisabled { |
| 81 policy_options {mode: MANDATORY} |
| 82 SyncDisabled: true |
| 83 } |
| 84 } |
| 85 })"); |
| 86 fetcher_ = net::URLFetcher::Create(sync_event_url_, net::URLFetcher::POST, |
| 87 this, traffic_annotation); |
66 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 88 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
67 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization, | 89 "%s: Bearer %s", net::HttpRequestHeaders::kAuthorization, |
68 access_token.c_str())); | 90 access_token.c_str())); |
69 fetcher_->AddExtraRequestHeader(base::StringPrintf( | 91 fetcher_->AddExtraRequestHeader(base::StringPrintf( |
70 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); | 92 "%s: %s", net::HttpRequestHeaders::kUserAgent, user_agent_.c_str())); |
71 fetcher_->SetRequestContext(request_context_.get()); | 93 fetcher_->SetRequestContext(request_context_.get()); |
72 fetcher_->SetUploadData("application/octet-stream", msg); | 94 fetcher_->SetUploadData("application/octet-stream", msg); |
73 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | | 95 fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | |
74 net::LOAD_DO_NOT_SAVE_COOKIES | | 96 net::LOAD_DO_NOT_SAVE_COOKIES | |
75 net::LOAD_DO_NOT_SEND_COOKIES); | 97 net::LOAD_DO_NOT_SEND_COOKIES); |
(...skipping 29 matching lines...) Expand all Loading... |
105 if (path.empty() || *path.rbegin() != '/') { | 127 if (path.empty() || *path.rbegin() != '/') { |
106 path += '/'; | 128 path += '/'; |
107 } | 129 } |
108 path += kEventEndpoint; | 130 path += kEventEndpoint; |
109 GURL::Replacements replacements; | 131 GURL::Replacements replacements; |
110 replacements.SetPathStr(path); | 132 replacements.SetPathStr(path); |
111 return sync_service_url.ReplaceComponents(replacements); | 133 return sync_service_url.ReplaceComponents(replacements); |
112 } | 134 } |
113 | 135 |
114 } // namespace syncer | 136 } // namespace syncer |
OLD | NEW |