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 "base/callback.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/task_runner_util.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "components/feedback/feedback_report.h"
13 #include "components/feedback/feedback_switches.h"
14 #include "components/feedback/feedback_uploader_delegate.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "net/base/load_flags.h"
18 #include "net/url_request/url_fetcher.h"
21 using content::BrowserThread
;
26 const char kProtoBufMimeType
[] = "application/x-protobuf";
30 FeedbackUploaderChrome::FeedbackUploaderChrome(
31 content::BrowserContext
* context
)
32 : FeedbackUploader(context
? context
->GetPath() : base::FilePath(),
33 BrowserThread::GetBlockingPool()),
36 const base::CommandLine
& command_line
=
37 *base::CommandLine::ForCurrentProcess();
38 if (command_line
.HasSwitch(switches::kFeedbackServer
))
39 url_
= command_line
.GetSwitchValueASCII(switches::kFeedbackServer
);
42 void FeedbackUploaderChrome::DispatchReport(const std::string
& data
) {
45 net::URLFetcher
* fetcher
= net::URLFetcher::Create(
46 post_url
, net::URLFetcher::POST
,
47 new FeedbackUploaderDelegate(
49 base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer
, AsWeakPtr()),
50 base::Bind(&FeedbackUploaderChrome::RetryReport
, AsWeakPtr())));
52 fetcher
->SetUploadData(std::string(kProtoBufMimeType
), data
);
53 fetcher
->SetRequestContext(context_
->GetRequestContext());
54 fetcher
->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES
|
55 net::LOAD_DO_NOT_SEND_COOKIES
);
59 } // namespace feedback