OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 5 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 CloudPrintURLFetcherFactory* g_test_factory = nullptr; | 85 CloudPrintURLFetcherFactory* g_test_factory = nullptr; |
86 | 86 |
87 } // namespace | 87 } // namespace |
88 | 88 |
89 // virtual | 89 // virtual |
90 CloudPrintURLFetcherFactory::~CloudPrintURLFetcherFactory() {} | 90 CloudPrintURLFetcherFactory::~CloudPrintURLFetcherFactory() {} |
91 | 91 |
92 // static | 92 // static |
93 CloudPrintURLFetcher* CloudPrintURLFetcher::Create() { | 93 CloudPrintURLFetcher* CloudPrintURLFetcher::Create( |
| 94 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) { |
94 return g_test_factory ? g_test_factory->CreateCloudPrintURLFetcher() | 95 return g_test_factory ? g_test_factory->CreateCloudPrintURLFetcher() |
95 : new CloudPrintURLFetcher; | 96 : new CloudPrintURLFetcher(partial_traffic_annotation); |
96 } | 97 } |
97 | 98 |
98 // static | 99 // static |
99 void CloudPrintURLFetcher::set_test_factory( | 100 void CloudPrintURLFetcher::set_test_factory( |
100 CloudPrintURLFetcherFactory* factory) { | 101 CloudPrintURLFetcherFactory* factory) { |
101 g_test_factory = factory; | 102 g_test_factory = factory; |
102 } | 103 } |
103 | 104 |
104 CloudPrintURLFetcher::ResponseAction | 105 CloudPrintURLFetcher::ResponseAction |
105 CloudPrintURLFetcher::Delegate::HandleRawResponse( | 106 CloudPrintURLFetcher::Delegate::HandleRawResponse( |
(...skipping 15 matching lines...) Expand all Loading... |
121 | 122 |
122 CloudPrintURLFetcher::ResponseAction | 123 CloudPrintURLFetcher::ResponseAction |
123 CloudPrintURLFetcher::Delegate::HandleJSONData( | 124 CloudPrintURLFetcher::Delegate::HandleJSONData( |
124 const net::URLFetcher* source, | 125 const net::URLFetcher* source, |
125 const GURL& url, | 126 const GURL& url, |
126 const base::DictionaryValue* json_data, | 127 const base::DictionaryValue* json_data, |
127 bool succeeded) { | 128 bool succeeded) { |
128 return CONTINUE_PROCESSING; | 129 return CONTINUE_PROCESSING; |
129 } | 130 } |
130 | 131 |
131 CloudPrintURLFetcher::CloudPrintURLFetcher() | 132 CloudPrintURLFetcher::CloudPrintURLFetcher( |
| 133 const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) |
132 : delegate_(NULL), | 134 : delegate_(NULL), |
133 num_retries_(0), | 135 num_retries_(0), |
134 type_(REQUEST_MAX) { | 136 type_(REQUEST_MAX), |
135 } | 137 partial_traffic_annotation_(partial_traffic_annotation) {} |
136 | 138 |
137 bool CloudPrintURLFetcher::IsSameRequest(const net::URLFetcher* source) { | 139 bool CloudPrintURLFetcher::IsSameRequest(const net::URLFetcher* source) { |
138 return (request_.get() == source); | 140 return (request_.get() == source); |
139 } | 141 } |
140 | 142 |
141 void CloudPrintURLFetcher::StartGetRequest( | 143 void CloudPrintURLFetcher::StartGetRequest( |
142 RequestType type, | 144 RequestType type, |
143 const GURL& url, | 145 const GURL& url, |
144 Delegate* delegate, | 146 Delegate* delegate, |
145 int max_retries, | 147 int max_retries, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 int max_retries, | 254 int max_retries, |
253 const std::string& post_data_mime_type, | 255 const std::string& post_data_mime_type, |
254 const std::string& post_data, | 256 const std::string& post_data, |
255 const std::string& additional_headers) { | 257 const std::string& additional_headers) { |
256 DCHECK(delegate); | 258 DCHECK(delegate); |
257 type_ = type; | 259 type_ = type; |
258 UMA_HISTOGRAM_ENUMERATION("CloudPrint.UrlFetcherRequestType", type, | 260 UMA_HISTOGRAM_ENUMERATION("CloudPrint.UrlFetcherRequestType", type, |
259 REQUEST_MAX); | 261 REQUEST_MAX); |
260 // Persist the additional headers in case we need to retry the request. | 262 // Persist the additional headers in case we need to retry the request. |
261 additional_headers_ = additional_headers; | 263 additional_headers_ = additional_headers; |
262 request_ = net::URLFetcher::Create(0, url, request_type, this); | 264 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 265 net::CompleteNetworkTrafficAnnotation("cloud_print", |
| 266 partial_traffic_annotation_, |
| 267 R"( |
| 268 semantics { |
| 269 sender: "Cloud Print" |
| 270 destination: GOOGLE_OWNED_SERVICE |
| 271 } |
| 272 policy { |
| 273 cookies_allowed: false |
| 274 setting: |
| 275 "This feature cannot be disabled by settings." |
| 276 chrome_policy { |
| 277 CloudPrintProxyEnabled { |
| 278 policy_options {mode: MANDATORY} |
| 279 CloudPrintProxyEnabled: false |
| 280 } |
| 281 } |
| 282 })"); |
| 283 request_ = |
| 284 net::URLFetcher::Create(0, url, request_type, this, traffic_annotation); |
263 data_use_measurement::DataUseUserData::AttachToFetcher( | 285 data_use_measurement::DataUseUserData::AttachToFetcher( |
264 request_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); | 286 request_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); |
265 request_->SetRequestContext(GetRequestContextGetter()); | 287 request_->SetRequestContext(GetRequestContextGetter()); |
266 // Since we implement our own retry logic, disable the retry in URLFetcher. | 288 // Since we implement our own retry logic, disable the retry in URLFetcher. |
267 request_->SetAutomaticallyRetryOn5xx(false); | 289 request_->SetAutomaticallyRetryOn5xx(false); |
268 request_->SetMaxRetriesOn5xx(max_retries); | 290 request_->SetMaxRetriesOn5xx(max_retries); |
269 delegate_ = delegate; | 291 delegate_ = delegate; |
270 SetupRequestHeaders(); | 292 SetupRequestHeaders(); |
271 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 293 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
272 net::LOAD_DO_NOT_SAVE_COOKIES); | 294 net::LOAD_DO_NOT_SAVE_COOKIES); |
(...skipping 23 matching lines...) Expand all Loading... |
296 ServiceURLRequestContextGetter* getter = | 318 ServiceURLRequestContextGetter* getter = |
297 g_service_process->GetServiceURLRequestContextGetter(); | 319 g_service_process->GetServiceURLRequestContextGetter(); |
298 // Now set up the user agent for cloudprint. | 320 // Now set up the user agent for cloudprint. |
299 std::string user_agent = getter->user_agent(); | 321 std::string user_agent = getter->user_agent(); |
300 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); | 322 base::StringAppendF(&user_agent, " %s", kCloudPrintUserAgent); |
301 getter->set_user_agent(user_agent); | 323 getter->set_user_agent(user_agent); |
302 return getter; | 324 return getter; |
303 } | 325 } |
304 | 326 |
305 } // namespace cloud_print | 327 } // namespace cloud_print |
OLD | NEW |