Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: net/url_request/report_sender.cc

Issue 2648713002: Add response code to the success callback of ReportSender (Closed)
Patch Set: eroman and estark comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/url_request/report_sender.h ('k') | net/url_request/report_sender_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/base/elements_upload_data_stream.h" 9 #include "net/base/elements_upload_data_stream.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/base/request_priority.h" 11 #include "net/base/request_priority.h"
12 #include "net/base/upload_bytes_element_reader.h" 12 #include "net/base/upload_bytes_element_reader.h"
13 #include "net/http/http_status_code.h"
13 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
14 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
15 16
16 namespace { 17 namespace {
17 const void* const kUserDataKey = &kUserDataKey; 18 const void* const kUserDataKey = &kUserDataKey;
18 19
19 class CallbackInfo : public base::SupportsUserData::Data { 20 class CallbackInfo : public base::SupportsUserData::Data {
20 public: 21 public:
21 CallbackInfo(const net::ReportSender::SuccessCallback& success_callback, 22 CallbackInfo(const net::ReportSender::SuccessCallback& success_callback,
22 const net::ReportSender::ErrorCallback& error_callback) 23 const net::ReportSender::ErrorCallback& error_callback)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 85
85 void ReportSender::OnResponseStarted(URLRequest* request, int net_error) { 86 void ReportSender::OnResponseStarted(URLRequest* request, int net_error) {
86 DCHECK_NE(ERR_IO_PENDING, net_error); 87 DCHECK_NE(ERR_IO_PENDING, net_error);
87 88
88 CallbackInfo* callback_info = 89 CallbackInfo* callback_info =
89 static_cast<CallbackInfo*>(request->GetUserData(&kUserDataKey)); 90 static_cast<CallbackInfo*>(request->GetUserData(&kUserDataKey));
90 DCHECK(callback_info); 91 DCHECK(callback_info);
91 if (net_error != OK) { 92 if (net_error != OK) {
92 DVLOG(1) << "Failed to send report for " << request->url().host(); 93 DVLOG(1) << "Failed to send report for " << request->url().host();
93 if (!callback_info->error_callback().is_null()) 94 if (!callback_info->error_callback().is_null())
94 callback_info->error_callback().Run(request->url(), net_error); 95 callback_info->error_callback().Run(request->url(), net_error, -1);
95 } else if (!callback_info->success_callback().is_null()) { 96 } else if (request->GetResponseCode() != net::HTTP_OK) {
96 callback_info->success_callback().Run(); 97 if (!callback_info->error_callback().is_null())
98 callback_info->error_callback().Run(request->url(), OK,
99 request->GetResponseCode());
100 } else {
101 if (!callback_info->success_callback().is_null())
102 callback_info->success_callback().Run();
97 } 103 }
98
99 CHECK_GT(inflight_requests_.erase(request), 0u); 104 CHECK_GT(inflight_requests_.erase(request), 0u);
100 } 105 }
101 106
102 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) { 107 void ReportSender::OnReadCompleted(URLRequest* request, int bytes_read) {
103 NOTREACHED(); 108 NOTREACHED();
104 } 109 }
105 110
106 } // namespace net 111 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/report_sender.h ('k') | net/url_request/report_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698