blob: 0de322a796125d35d1e75c5aadd5543e0068d523 [file] [log] [blame]
[email protected]77f7fe892014-03-18 00:00:061// 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.
4
[email protected]1eab4e92014-05-09 02:17:195#include "components/feedback/feedback_uploader_chrome.h"
[email protected]77f7fe892014-03-18 00:00:066
asvitkinee6f7a58b12015-02-23 21:24:537#include <string>
8
[email protected]77f7fe892014-03-18 00:00:069#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"
rajendrant06be1a72016-10-16 20:24:0514#include "components/data_use_measurement/core/data_use_user_data.h"
[email protected]1eab4e92014-05-09 02:17:1915#include "components/feedback/feedback_report.h"
16#include "components/feedback/feedback_switches.h"
17#include "components/feedback/feedback_uploader_delegate.h"
asvitkine9a279832015-12-18 02:35:5018#include "components/variations/net/variations_http_headers.h"
[email protected]77f7fe892014-03-18 00:00:0619#include "content/public/browser/browser_context.h"
20#include "content/public/browser/browser_thread.h"
jamb84299e2016-04-12 16:58:5921#include "content/public/browser/storage_partition.h"
[email protected]77f7fe892014-03-18 00:00:0622#include "net/base/load_flags.h"
23#include "net/url_request/url_fetcher.h"
24#include "url/gurl.h"
25
26using content::BrowserThread;
27
28namespace feedback {
29namespace {
30
31const char kProtoBufMimeType[] = "application/x-protobuf";
32
33} // namespace
34
35FeedbackUploaderChrome::FeedbackUploaderChrome(
36 content::BrowserContext* context)
37 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
38 BrowserThread::GetBlockingPool()),
39 context_(context) {
40 CHECK(context_);
kkosztyo.u-szegedb33617c2014-12-04 09:54:3641 const base::CommandLine& command_line =
42 *base::CommandLine::ForCurrentProcess();
43 if (command_line.HasSwitch(switches::kFeedbackServer))
44 url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer);
[email protected]77f7fe892014-03-18 00:00:0645}
46
47void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
48 GURL post_url(url_);
49
asvitkinee6f7a58b12015-02-23 21:24:5350 // Note: FeedbackUploaderDelegate deletes itself and the fetcher.
dtapuskadafcf892015-05-01 13:58:2551 net::URLFetcher* fetcher =
52 net::URLFetcher::Create(
53 post_url, net::URLFetcher::POST,
54 new FeedbackUploaderDelegate(
55 data, base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer,
56 AsWeakPtr()),
57 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())))
58 .release();
rajendrant06be1a72016-10-16 20:24:0559 data_use_measurement::DataUseUserData::AttachToFetcher(
60 fetcher, data_use_measurement::DataUseUserData::FEEDBACK_UPLOADER);
asvitkinee6f7a58b12015-02-23 21:24:5361 // Tell feedback server about the variation state of this install.
62 net::HttpRequestHeaders headers;
asvitkine9a279832015-12-18 02:35:5063 variations::AppendVariationHeaders(
asvitkinee6f7a58b12015-02-23 21:24:5364 fetcher->GetOriginalURL(), context_->IsOffTheRecord(), false, &headers);
65 fetcher->SetExtraRequestHeaders(headers.ToString());
66
67 fetcher->SetUploadData(kProtoBufMimeType, data);
jamb84299e2016-04-12 16:58:5968 fetcher->SetRequestContext(
69 content::BrowserContext::GetDefaultStoragePartition(context_)->
70 GetURLRequestContext());
[email protected]77f7fe892014-03-18 00:00:0671 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
72 net::LOAD_DO_NOT_SEND_COOKIES);
73 fetcher->Start();
74}
75
76} // namespace feedback