Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / feedback / feedback_uploader_delegate.cc
blob993d590cca46472665bb9004e1eca3e1b4b12537
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.
5 #include "chrome/browser/feedback/feedback_uploader_delegate.h"
7 #include <sstream>
9 #include "base/logging.h"
10 #include "net/url_request/url_fetcher.h"
11 #include "url/gurl.h"
13 namespace feedback {
14 namespace {
16 const int kHttpPostSuccessNoContent = 204;
17 const int kHttpPostFailNoConnection = -1;
18 const int kHttpPostFailClientError = 400;
19 const int kHttpPostFailServerError = 500;
21 } // namespace
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) {
32 FeedbackUploaderDelegate::~FeedbackUploaderDelegate() {}
34 void FeedbackUploaderDelegate::OnURLFetchComplete(
35 const net::URLFetcher* source) {
36 scoped_ptr<const net::URLFetcher> source_scoper(source);
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;
55 error_callback_.Run(post_body_.Pass());
58 LOG(WARNING) << "FEEDBACK: Submission to feedback server ("
59 << source->GetURL() << ") status: " << error_stream.str();
61 // This instance won't be used for anything else, delete us.
62 delete this;
65 } // namespace feedback