Fix experimental app list search box disappearing on profile switch.
[chromium-blink-merge.git] / components / feedback / feedback_uploader_chrome.cc
blob7ecbf030be40644202e4964b7895f123b8d984a3
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 const base::CommandLine& command_line =
37 *base::CommandLine::ForCurrentProcess();
38 if (command_line.HasSwitch(switches::kFeedbackServer))
39 url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer);
42 void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
43 GURL post_url(url_);
45 net::URLFetcher* fetcher = net::URLFetcher::Create(
46 post_url, net::URLFetcher::POST,
47 new FeedbackUploaderDelegate(
48 data,
49 base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, AsWeakPtr()),
50 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())));
52 fetcher->SetUploadData(std::string(kProtoBufMimeType), data);
53 fetcher->SetRequestContext(context_->GetRequestContext());
54 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
55 net::LOAD_DO_NOT_SEND_COOKIES);
56 fetcher->Start();
59 } // namespace feedback