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 "google_apis/gcm/engine/checkin_request.h" | 5 #include "google_apis/gcm/engine/checkin_request.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 11 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
12 #include "google_apis/gcm/protocol/checkin.pb.h" | 12 #include "google_apis/gcm/protocol/checkin.pb.h" |
13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/traffic_annotation/network_traffic_annotation.h" |
14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
15 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
16 | 17 |
17 namespace gcm { | 18 namespace gcm { |
18 | 19 |
19 namespace { | 20 namespace { |
20 const char kRequestContentType[] = "application/x-protobuf"; | 21 const char kRequestContentType[] = "application/x-protobuf"; |
21 const int kRequestVersionValue = 3; | 22 const int kRequestVersionValue = 3; |
22 const int kDefaultUserSerialNumber = 0; | 23 const int kDefaultUserSerialNumber = 0; |
23 | 24 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 for (std::map<std::string, std::string>::const_iterator iter = | 138 for (std::map<std::string, std::string>::const_iterator iter = |
138 request_info_.account_tokens.begin(); | 139 request_info_.account_tokens.begin(); |
139 iter != request_info_.account_tokens.end(); | 140 iter != request_info_.account_tokens.end(); |
140 ++iter) { | 141 ++iter) { |
141 request.add_account_cookie(iter->first); | 142 request.add_account_cookie(iter->first); |
142 request.add_account_cookie(iter->second); | 143 request.add_account_cookie(iter->second); |
143 } | 144 } |
144 | 145 |
145 std::string upload_data; | 146 std::string upload_data; |
146 CHECK(request.SerializeToString(&upload_data)); | 147 CHECK(request.SerializeToString(&upload_data)); |
147 | 148 net::NetworkTrafficAnnotationTag traffic_annotation = |
148 url_fetcher_ = | 149 net::DefineNetworkTrafficAnnotation("gcm_checkin", R"( |
149 net::URLFetcher::Create(checkin_url_, net::URLFetcher::POST, this); | 150 semantics { |
| 151 sender: "GCM Driver" |
| 152 description: |
| 153 "Chromium interacts with Google Cloud Messaging to receive push " |
| 154 "messages for various browser features, as well as on behalf of " |
| 155 "websites and extensions. The check-in periodically verifies the " |
| 156 "client's validity with Google servers, and receive updates to " |
| 157 "configuration regarding interacting with Google services." |
| 158 trigger: |
| 159 "Immediately after a feature creates the first Google Cloud " |
| 160 "Messaging registration. By default, Chromium will check in with " |
| 161 "Google Cloud Messaging every two days. Google can adjust this " |
| 162 "interval when it deems necessary." |
| 163 data: |
| 164 "The profile-bound Android ID and associated secret and account " |
| 165 "tokens. A structure containing the Chromium version, channel, and " |
| 166 "platform of the host operating system." |
| 167 destination: GOOGLE_OWNED_SERVICE |
| 168 } |
| 169 policy { |
| 170 cookies_allowed: false |
| 171 setting: |
| 172 "Support for interacting with Google Cloud Messaging is enabled by " |
| 173 "default, and there is no configuration option to completely " |
| 174 "disable it. Websites wishing to receive push messages must " |
| 175 "acquire express permission from the user for the 'Notification' " |
| 176 "permission." |
| 177 policy_exception_justification: |
| 178 "Not implemented, considered not useful." |
| 179 })"); |
| 180 url_fetcher_ = net::URLFetcher::Create(checkin_url_, net::URLFetcher::POST, |
| 181 this, traffic_annotation); |
150 url_fetcher_->SetRequestContext(request_context_getter_); | 182 url_fetcher_->SetRequestContext(request_context_getter_); |
151 url_fetcher_->SetUploadData(kRequestContentType, upload_data); | 183 url_fetcher_->SetUploadData(kRequestContentType, upload_data); |
152 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 184 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
153 net::LOAD_DO_NOT_SAVE_COOKIES); | 185 net::LOAD_DO_NOT_SAVE_COOKIES); |
154 recorder_->RecordCheckinInitiated(request_info_.android_id); | 186 recorder_->RecordCheckinInitiated(request_info_.android_id); |
155 request_start_time_ = base::TimeTicks::Now(); | 187 request_start_time_ = base::TimeTicks::Now(); |
156 url_fetcher_->Start(); | 188 url_fetcher_->Start(); |
157 } | 189 } |
158 | 190 |
159 void CheckinRequest::RetryWithBackoff() { | 191 void CheckinRequest::RetryWithBackoff() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 253 |
222 RecordCheckinStatusAndReportUMA(SUCCESS, recorder_, false); | 254 RecordCheckinStatusAndReportUMA(SUCCESS, recorder_, false); |
223 UMA_HISTOGRAM_COUNTS("GCM.CheckinRetryCount", | 255 UMA_HISTOGRAM_COUNTS("GCM.CheckinRetryCount", |
224 backoff_entry_.failure_count()); | 256 backoff_entry_.failure_count()); |
225 UMA_HISTOGRAM_TIMES("GCM.CheckinCompleteTime", | 257 UMA_HISTOGRAM_TIMES("GCM.CheckinCompleteTime", |
226 base::TimeTicks::Now() - request_start_time_); | 258 base::TimeTicks::Now() - request_start_time_); |
227 callback_.Run(response_status, response_proto); | 259 callback_.Run(response_status, response_proto); |
228 } | 260 } |
229 | 261 |
230 } // namespace gcm | 262 } // namespace gcm |
OLD | NEW |