Chromium Code Reviews| 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 scoped_ptr<std::string> post_body, | |
| 25 const base::Closure& success_callback, | |
| 26 const ReportDataCallback& error_callback) | |
| 27 : post_body_(post_body.Pass()), | |
| 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 std::stringstream error_stream; | |
| 37 int response_code = source->GetResponseCode(); | |
| 38 if (response_code == kHttpPostSuccessNoContent) { | |
| 39 error_stream << "Success"; | |
| 40 success_callback_.Run(); | |
| 41 } else { | |
| 42 // Process the error for debug output | |
| 43 if (response_code == kHttpPostFailNoConnection) { | |
| 44 error_stream << "No connection to server."; | |
| 45 } else if ((response_code > kHttpPostFailClientError) && | |
| 46 (response_code < kHttpPostFailServerError)) { | |
| 47 error_stream << "Client error: HTTP response code " << response_code; | |
| 48 } else if (response_code > kHttpPostFailServerError) { | |
| 49 error_stream << "Server error: HTTP response code " << response_code; | |
| 50 } else { | |
| 51 error_stream << "Unknown error: HTTP response code " << response_code; | |
| 52 } | |
| 53 error_callback_.Run(post_body_.Pass()); | |
| 54 } | |
| 55 | |
| 56 LOG(WARNING) << "FEEDBACK: Submission to feedback server (" | |
| 57 << source->GetURL() << ") status: " << error_stream.str(); | |
| 58 | |
| 59 // Delete the URLFetcher. | |
| 60 delete source; | |
|
Zachary Kuznia
2013/12/17 01:12:57
If you put this in a scoped_ptr at the beginning o
rkc
2013/12/17 23:26:00
Done.
| |
| 61 // And then delete ourselves. | |
| 62 delete this; | |
| 63 } | |
| 64 | |
| 65 } // namespace feedback | |
| OLD | NEW |