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
= net::URLFetcher::Create(
50 post_url
, net::URLFetcher::POST
,
51 new FeedbackUploaderDelegate(
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
);
69 } // namespace feedback