[Eraser strings] Remove/replace some supervised user strings
[chromium-blink-merge.git] / components / feedback / feedback_uploader_chrome.cc
blobaea651f4244b46815299a4b2f50bee45a6b55535
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 =
50 net::URLFetcher::Create(
51 post_url, net::URLFetcher::POST,
52 new FeedbackUploaderDelegate(
53 data, base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer,
54 AsWeakPtr()),
55 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())))
56 .release();
58 // Tell feedback server about the variation state of this install.
59 net::HttpRequestHeaders headers;
60 variations::VariationsHttpHeaderProvider::GetInstance()->AppendHeaders(
61 fetcher->GetOriginalURL(), context_->IsOffTheRecord(), false, &headers);
62 fetcher->SetExtraRequestHeaders(headers.ToString());
64 fetcher->SetUploadData(kProtoBufMimeType, data);
65 fetcher->SetRequestContext(context_->GetRequestContext());
66 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
67 net::LOAD_DO_NOT_SEND_COOKIES);
68 fetcher->Start();
71 } // namespace feedback