Add enable_media_router check to GN based grit targets.
[chromium-blink-merge.git] / components / feedback / feedback_uploader_chrome.cc
blobe5a52b13c87de5ed889aad477ffd2c7030ead528
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 <string>
9 #include "base/callback.h"
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/task_runner_util.h"
13 #include "base/threading/sequenced_worker_pool.h"
14 #include "components/feedback/feedback_report.h"
15 #include "components/feedback/feedback_switches.h"
16 #include "components/feedback/feedback_uploader_delegate.h"
17 #include "components/variations/net/variations_http_header_provider.h"
18 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "net/base/load_flags.h"
21 #include "net/url_request/url_fetcher.h"
22 #include "url/gurl.h"
24 using content::BrowserThread;
26 namespace feedback {
27 namespace {
29 const char kProtoBufMimeType[] = "application/x-protobuf";
31 } // namespace
33 FeedbackUploaderChrome::FeedbackUploaderChrome(
34 content::BrowserContext* context)
35 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
36 BrowserThread::GetBlockingPool()),
37 context_(context) {
38 CHECK(context_);
39 const base::CommandLine& command_line =
40 *base::CommandLine::ForCurrentProcess();
41 if (command_line.HasSwitch(switches::kFeedbackServer))
42 url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer);
45 void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
46 GURL post_url(url_);
48 // Note: FeedbackUploaderDelegate deletes itself and the fetcher.
49 net::URLFetcher* fetcher = net::URLFetcher::Create(
50 post_url, net::URLFetcher::POST,
51 new FeedbackUploaderDelegate(
52 data,
53 base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, AsWeakPtr()),
54 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())));
56 // Tell feedback server about the variation state of this install.
57 net::HttpRequestHeaders headers;
58 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders(
59 fetcher->GetOriginalURL(), context_->IsOffTheRecord(), false, &headers);
60 fetcher->SetExtraRequestHeaders(headers.ToString());
62 fetcher->SetUploadData(kProtoBufMimeType, data);
63 fetcher->SetRequestContext(context_->GetRequestContext());
64 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
65 net::LOAD_DO_NOT_SEND_COOKIES);
66 fetcher->Start();
69 } // namespace feedback