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"
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"
24 using content::BrowserThread
;
29 const char kProtoBufMimeType
[] = "application/x-protobuf";
33 FeedbackUploaderChrome::FeedbackUploaderChrome(
34 content::BrowserContext
* context
)
35 : FeedbackUploader(context
? context
->GetPath() : base::FilePath(),
36 BrowserThread::GetBlockingPool()),
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
) {
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
,
55 base::Bind(&FeedbackUploaderChrome::RetryReport
, AsWeakPtr())))
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
);
71 } // namespace feedback