• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "components/feedback/feedback_uploader_chrome.h"
6 
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"
19 #include "url/gurl.h"
20 
21 using content::BrowserThread;
22 
23 namespace feedback {
24 namespace {
25 
26 const char kProtoBufMimeType[] = "application/x-protobuf";
27 
28 }  // namespace
29 
FeedbackUploaderChrome(content::BrowserContext * context)30 FeedbackUploaderChrome::FeedbackUploaderChrome(
31     content::BrowserContext* context)
32     : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
33                        BrowserThread::GetBlockingPool()),
34       context_(context) {
35   CHECK(context_);
36   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFeedbackServer))
37     url_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
38         switches::kFeedbackServer);
39 }
40 
DispatchReport(const std::string & data)41 void FeedbackUploaderChrome::DispatchReport(const std::string& data) {
42   GURL post_url(url_);
43 
44   net::URLFetcher* fetcher = net::URLFetcher::Create(
45       post_url, net::URLFetcher::POST,
46       new FeedbackUploaderDelegate(
47           data,
48           base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, AsWeakPtr()),
49           base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())));
50 
51   fetcher->SetUploadData(std::string(kProtoBufMimeType), data);
52   fetcher->SetRequestContext(context_->GetRequestContext());
53   fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
54                         net::LOAD_DO_NOT_SEND_COOKIES);
55   fetcher->Start();
56 }
57 
58 }  // namespace feedback
59