| 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 "net/url_request/report_sender.h" | 5 #include "net/url_request/report_sender.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "net/base/elements_upload_data_stream.h" | 10 #include "net/base/elements_upload_data_stream.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 net::ReportSender::SuccessCallback success_callback_; | 37 net::ReportSender::SuccessCallback success_callback_; |
| 38 net::ReportSender::ErrorCallback error_callback_; | 38 net::ReportSender::ErrorCallback error_callback_; |
| 39 }; | 39 }; |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace net { | 42 namespace net { |
| 43 | 43 |
| 44 ReportSender::ReportSender(URLRequestContext* request_context, | 44 ReportSender::ReportSender(URLRequestContext* request_context) |
| 45 CookiesPreference cookies_preference) | 45 : request_context_(request_context) {} |
| 46 : request_context_(request_context), | |
| 47 cookies_preference_(cookies_preference) {} | |
| 48 | 46 |
| 49 ReportSender::~ReportSender() { | 47 ReportSender::~ReportSender() { |
| 50 } | 48 } |
| 51 | 49 |
| 52 void ReportSender::Send(const GURL& report_uri, | 50 void ReportSender::Send(const GURL& report_uri, |
| 53 base::StringPiece content_type, | 51 base::StringPiece content_type, |
| 54 base::StringPiece report, | 52 base::StringPiece report, |
| 55 const SuccessCallback& success_callback, | 53 const SuccessCallback& success_callback, |
| 56 const ErrorCallback& error_callback) { | 54 const ErrorCallback& error_callback) { |
| 57 DCHECK(!content_type.empty()); | 55 DCHECK(!content_type.empty()); |
| 58 std::unique_ptr<URLRequest> url_request = | 56 std::unique_ptr<URLRequest> url_request = |
| 59 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); | 57 request_context_->CreateRequest(report_uri, DEFAULT_PRIORITY, this); |
| 60 url_request->SetUserData( | 58 url_request->SetUserData( |
| 61 &kUserDataKey, | 59 &kUserDataKey, |
| 62 base::MakeUnique<CallbackInfo>(success_callback, error_callback)); | 60 base::MakeUnique<CallbackInfo>(success_callback, error_callback)); |
| 63 | 61 |
| 64 int load_flags = | 62 url_request->SetLoadFlags( |
| 65 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA; | 63 LOAD_BYPASS_CACHE | LOAD_DISABLE_CACHE | LOAD_DO_NOT_SEND_AUTH_DATA | |
| 66 if (cookies_preference_ != SEND_COOKIES) { | 64 LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES); |
| 67 load_flags |= LOAD_DO_NOT_SEND_COOKIES | LOAD_DO_NOT_SAVE_COOKIES; | |
| 68 } | |
| 69 url_request->SetLoadFlags(load_flags); | |
| 70 | 65 |
| 71 HttpRequestHeaders extra_headers; | 66 HttpRequestHeaders extra_headers; |
| 72 extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type); | 67 extra_headers.SetHeader(HttpRequestHeaders::kContentType, content_type); |
| 73 url_request->SetExtraRequestHeaders(extra_headers); | 68 url_request->SetExtraRequestHeaders(extra_headers); |
| 74 | 69 |
| 75 url_request->set_method("POST"); | 70 url_request->set_method("POST"); |
| 76 | 71 |
| 77 std::vector<char> report_data(report.begin(), report.end()); | 72 std::vector<char> report_data(report.begin(), report.end()); |
| 78 std::unique_ptr<UploadElementReader> reader( | 73 std::unique_ptr<UploadElementReader> reader( |
| 79 new UploadOwnedBytesElementReader(&report_data)); | 74 new UploadOwnedBytesElementReader(&report_data)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 callback_info->success_callback().Run(); | 99 callback_info->success_callback().Run(); |
| 105 } | 100 } |
| 106 CHECK_GT(inflight_requests_.erase(request), 0u); | 101 CHECK_GT(inflight_requests_.erase(request), 0u); |
| 107 } | 102 } |
| 108 | 103 |
| 109 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { | 104 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { |
| 110 NOTREACHED(); | 105 NOTREACHED(); |
| 111 } | 106 } |
| 112 | 107 |
| 113 } // namespace net | 108 } // namespace net |
| OLD | NEW |