Adds shutdown when FrameTreeServer goes away
[chromium-blink-merge.git] / components / feedback / feedback_uploader_delegate.cc
blob6fdca6be255ff4aab6abaeb719ba5c6b7f659d4f
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"
7 #include <sstream>
9 #include "base/logging.h"
10 #include "net/url_request/url_fetcher.h"
12 namespace feedback {
13 namespace {
15 const int kHttpPostSuccessNoContent = 204;
16 const int kHttpPostFailNoConnection = -1;
17 const int kHttpPostFailClientError = 400;
18 const int kHttpPostFailServerError = 500;
20 } // namespace
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();
42 } else {
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;
51 } else {
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.
61 delete this;
64 } // namespace feedback