Roll ANGLE bc75f36:ef9d63e
[chromium-blink-merge.git] / components / feedback / feedback_uploader_chrome.cc
blob75d6e90143af9325b762e629795cfbcaa66add4a
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_chrome.h"
7 #include "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/task_runner_util.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "components/feedback/feedback_report.h"
13 #include "components/feedback/feedback_switches.h"
14 #include "components/feedback/feedback_uploader_delegate.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "net/base/load_flags.h"
18 #include "net/url_request/url_fetcher.h"
19 #include "url/gurl.h"
21 using content::BrowserThread;
23 namespace feedback {
24 namespace {
26 const char kProtoBufMimeType[] = "application/x-protobuf";
28 } // namespace
30 FeedbackUploaderChrome::FeedbackUploaderChrome(
31 content::BrowserContext* context)
32 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
33 BrowserThread::GetBlockingPool()),
34 context_(context) {
35 CHECK(context_);
36 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFeedbackServer))
37 url_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
38 switches::kFeedbackServer);
41 void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
42 GURL post_url(url_);
44 net::URLFetcher* fetcher = net::URLFetcher::Create(
45 post_url, net::URLFetcher::POST,
46 new FeedbackUploaderDelegate(
47 data,
48 base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, AsWeakPtr()),
49 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())));
51 fetcher->SetUploadData(std::string(kProtoBufMimeType), data);
52 fetcher->SetRequestContext(context_->GetRequestContext());
53 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
54 net::LOAD_DO_NOT_SEND_COOKIES);
55 fetcher->Start();
58 } // namespace feedback