OLD | NEW |
| (Empty) |
1 // Copyright 2013 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. | |
4 | |
5 #include "chrome/browser/feedback/feedback_uploader_delegate.h" | |
6 | |
7 #include <sstream> | |
8 | |
9 #include "base/logging.h" | |
10 #include "net/url_request/url_fetcher.h" | |
11 #include "url/gurl.h" | |
12 | |
13 namespace feedback { | |
14 namespace { | |
15 | |
16 const int kHttpPostSuccessNoContent = 204; | |
17 const int kHttpPostFailNoConnection = -1; | |
18 const int kHttpPostFailClientError = 400; | |
19 const int kHttpPostFailServerError = 500; | |
20 | |
21 } // namespace | |
22 | |
23 FeedbackUploaderDelegate::FeedbackUploaderDelegate( | |
24 const std::string& post_body, | |
25 const base::Closure& success_callback, | |
26 const ReportDataCallback& error_callback) | |
27 : post_body_(post_body), | |
28 success_callback_(success_callback), | |
29 error_callback_(error_callback) { | |
30 } | |
31 | |
32 FeedbackUploaderDelegate::~FeedbackUploaderDelegate() {} | |
33 | |
34 void FeedbackUploaderDelegate::OnURLFetchComplete( | |
35 const net::URLFetcher* source) { | |
36 scoped_ptr<const net::URLFetcher> source_scoper(source); | |
37 | |
38 std::stringstream error_stream; | |
39 int response_code = source->GetResponseCode(); | |
40 if (response_code == kHttpPostSuccessNoContent) { | |
41 error_stream << "Success"; | |
42 success_callback_.Run(); | |
43 } else { | |
44 // Process the error for debug output | |
45 if (response_code == kHttpPostFailNoConnection) { | |
46 error_stream << "No connection to server."; | |
47 } else if ((response_code > kHttpPostFailClientError) && | |
48 (response_code < kHttpPostFailServerError)) { | |
49 error_stream << "Client error: HTTP response code " << response_code; | |
50 } else if (response_code > kHttpPostFailServerError) { | |
51 error_stream << "Server error: HTTP response code " << response_code; | |
52 } else { | |
53 error_stream << "Unknown error: HTTP response code " << response_code; | |
54 } | |
55 error_callback_.Run(post_body_); | |
56 } | |
57 | |
58 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" | |
59 << source->GetURL() << ") status: " << error_stream.str(); | |
60 | |
61 // This instance won't be used for anything else, delete us. | |
62 delete this; | |
63 } | |
64 | |
65 } // namespace feedback | |
OLD | NEW |