Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/feedback/feedback_uploader_chrome.h" | 5 #include "components/feedback/feedback_uploader_chrome.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "components/data_use_measurement/core/data_use_user_data.h" | 14 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 15 #include "components/feedback/feedback_report.h" | 15 #include "components/feedback/feedback_report.h" |
| 16 #include "components/feedback/feedback_switches.h" | 16 #include "components/feedback/feedback_switches.h" |
| 17 #include "components/feedback/feedback_uploader_delegate.h" | 17 #include "components/feedback/feedback_uploader_delegate.h" |
| 18 #include "components/variations/net/variations_http_headers.h" | 18 #include "components/variations/net/variations_http_headers.h" |
| 19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/storage_partition.h" | 21 #include "content/public/browser/storage_partition.h" |
| 22 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 23 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 23 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 | 28 |
| 28 namespace feedback { | 29 namespace feedback { |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 const char kProtoBufMimeType[] = "application/x-protobuf"; | 32 const char kProtoBufMimeType[] = "application/x-protobuf"; |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 FeedbackUploaderChrome::FeedbackUploaderChrome( | 36 FeedbackUploaderChrome::FeedbackUploaderChrome( |
| 36 content::BrowserContext* context) | 37 content::BrowserContext* context) |
| 37 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), | 38 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), |
| 38 BrowserThread::GetBlockingPool()), | 39 BrowserThread::GetBlockingPool()), |
| 39 context_(context) { | 40 context_(context) { |
| 40 CHECK(context_); | 41 CHECK(context_); |
| 41 const base::CommandLine& command_line = | 42 const base::CommandLine& command_line = |
| 42 *base::CommandLine::ForCurrentProcess(); | 43 *base::CommandLine::ForCurrentProcess(); |
| 43 if (command_line.HasSwitch(switches::kFeedbackServer)) | 44 if (command_line.HasSwitch(switches::kFeedbackServer)) |
| 44 url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer); | 45 url_ = command_line.GetSwitchValueASCII(switches::kFeedbackServer); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void FeedbackUploaderChrome::DispatchReport(const std::string& data) { | 48 void FeedbackUploaderChrome::DispatchReport(const std::string& data) { |
| 48 GURL post_url(url_); | 49 GURL post_url(url_); |
| 49 | 50 |
| 51 net::NetworkTrafficAnnotationTag traffic_annotation = | |
| 52 net::DefineNetworkTrafficAnnotation("...", R"( | |
| 53 semantics { | |
| 54 sender: "..." | |
| 55 description: "..." | |
| 56 trigger: "..." | |
| 57 data: "..." | |
| 58 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
|
afakhry
2017/02/25 02:37:37
Why are these placeholders not set? I don't know h
Ramin Halavati
2017/02/27 08:56:30
I am sorry I wasn't clear in my initial message. I
afakhry
2017/03/10 19:17:27
You can use something like this:
net::NetworkTraf
| |
| 59 } | |
| 60 policy { | |
| 61 cookies_allowed: false/true | |
| 62 cookies_store: "..." | |
| 63 setting: "..." | |
| 64 policy { | |
| 65 [POLICY_NAME] { | |
| 66 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
| 67 value: ... | |
| 68 } | |
| 69 } | |
| 70 policy_exception_justification: "..." | |
| 71 })"); | |
| 50 // Note: FeedbackUploaderDelegate deletes itself and the fetcher. | 72 // Note: FeedbackUploaderDelegate deletes itself and the fetcher. |
| 51 net::URLFetcher* fetcher = | 73 net::URLFetcher* fetcher = |
| 52 net::URLFetcher::Create( | 74 net::URLFetcher::Create( |
| 53 post_url, net::URLFetcher::POST, | 75 post_url, net::URLFetcher::POST, |
| 54 new FeedbackUploaderDelegate( | 76 new FeedbackUploaderDelegate( |
| 55 data, base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, | 77 data, base::Bind(&FeedbackUploaderChrome::UpdateUploadTimer, |
| 56 AsWeakPtr()), | 78 AsWeakPtr()), |
| 57 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr()))) | 79 base::Bind(&FeedbackUploaderChrome::RetryReport, AsWeakPtr())), |
| 80 traffic_annotation) | |
| 58 .release(); | 81 .release(); |
| 59 data_use_measurement::DataUseUserData::AttachToFetcher( | 82 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 60 fetcher, data_use_measurement::DataUseUserData::FEEDBACK_UPLOADER); | 83 fetcher, data_use_measurement::DataUseUserData::FEEDBACK_UPLOADER); |
| 61 // Tell feedback server about the variation state of this install. | 84 // Tell feedback server about the variation state of this install. |
| 62 net::HttpRequestHeaders headers; | 85 net::HttpRequestHeaders headers; |
| 63 // Note: It's OK to pass |is_signed_in| false if it's unknown, as it does | 86 // Note: It's OK to pass |is_signed_in| false if it's unknown, as it does |
| 64 // not affect transmission of experiments coming from the variations server. | 87 // not affect transmission of experiments coming from the variations server. |
| 65 bool is_signed_in = false; | 88 bool is_signed_in = false; |
| 66 variations::AppendVariationHeaders(fetcher->GetOriginalURL(), | 89 variations::AppendVariationHeaders(fetcher->GetOriginalURL(), |
| 67 context_->IsOffTheRecord(), false, | 90 context_->IsOffTheRecord(), false, |
| 68 is_signed_in, &headers); | 91 is_signed_in, &headers); |
| 69 fetcher->SetExtraRequestHeaders(headers.ToString()); | 92 fetcher->SetExtraRequestHeaders(headers.ToString()); |
| 70 | 93 |
| 71 fetcher->SetUploadData(kProtoBufMimeType, data); | 94 fetcher->SetUploadData(kProtoBufMimeType, data); |
| 72 fetcher->SetRequestContext( | 95 fetcher->SetRequestContext( |
| 73 content::BrowserContext::GetDefaultStoragePartition(context_)-> | 96 content::BrowserContext::GetDefaultStoragePartition(context_)-> |
| 74 GetURLRequestContext()); | 97 GetURLRequestContext()); |
| 75 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 98 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 76 net::LOAD_DO_NOT_SEND_COOKIES); | 99 net::LOAD_DO_NOT_SEND_COOKIES); |
| 77 fetcher->Start(); | 100 fetcher->Start(); |
| 78 } | 101 } |
| 79 | 102 |
| 80 } // namespace feedback | 103 } // namespace feedback |
| OLD | NEW |