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
3 // found in the LICENSE file.
5 #include "components/feedback/feedback_uploader_delegate.h"
9 #include "base/logging.h"
10 #include "net/url_request/url_fetcher.h"
15 const int kHttpPostSuccessNoContent
= 204;
16 const int kHttpPostFailNoConnection
= -1;
17 const int kHttpPostFailClientError
= 400;
18 const int kHttpPostFailServerError
= 500;
22 FeedbackUploaderDelegate::FeedbackUploaderDelegate(
23 const std::string
& post_body
,
24 const base::Closure
& success_callback
,
25 const ReportDataCallback
& error_callback
)
26 : post_body_(post_body
),
27 success_callback_(success_callback
),
28 error_callback_(error_callback
) {
31 FeedbackUploaderDelegate::~FeedbackUploaderDelegate() {}
33 void FeedbackUploaderDelegate::OnURLFetchComplete(
34 const net::URLFetcher
* source
) {
35 scoped_ptr
<const net::URLFetcher
> source_scoper(source
);
37 std::stringstream error_stream
;
38 int response_code
= source
->GetResponseCode();
39 if (response_code
== kHttpPostSuccessNoContent
) {
40 error_stream
<< "Success";
41 success_callback_
.Run();
43 // Process the error for debug output
44 if (response_code
== kHttpPostFailNoConnection
) {
45 error_stream
<< "No connection to server.";
46 } else if ((response_code
> kHttpPostFailClientError
) &&
47 (response_code
< kHttpPostFailServerError
)) {
48 error_stream
<< "Client error: HTTP response code " << response_code
;
49 } else if (response_code
> kHttpPostFailServerError
) {
50 error_stream
<< "Server error: HTTP response code " << response_code
;
52 error_stream
<< "Unknown error: HTTP response code " << response_code
;
54 error_callback_
.Run(post_body_
);
57 LOG(WARNING
) << "FEEDBACK: Submission to feedback server ("
58 << source
->GetURL() << ") status: " << error_stream
.str();
60 // This instance won't be used for anything else, delete us.
64 } // namespace feedback