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