Commit 2ee96a27 authored by Marton Hunyady's avatar Marton Hunyady Committed by Commit Bot

Add network annotations for upload job

Bug: 785275
Change-Id: I30e401025d78ef5e9771c9ee11b3570b8968beb6
Reviewed-on: https://chromium-review.googlesource.com/888624Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarJulian Pastarmov <pastarmovj@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Commit-Queue: Marton Hunyady <hunyadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532896}
parent 2c9bb8ea
......@@ -59,11 +59,30 @@ std::unique_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob(
device_oauth2_token_service->GetRobotAccountId();
SYSLOG(INFO) << "Creating upload job for screenshot";
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("remote_command_screenshot", R"(
semantics {
sender: "Chrome OS Remote Commands"
description: "Admins of kiosks are able to request screenshots "
"of the current screen shown on the kiosk, which is uploaded to "
"the device management server."
trigger: "Admin requests remote screenshot on the Admin Console."
data: "Screenshot of the current screen shown on the kiosk."
destination: GOOGLE_OWNED_SERVICE
}
policy {
cookies_allowed: NO
setting: "This feature cannot be disabled in settings, however this "
"request will only happen on explicit admin request and when no "
"user interaction or media capture happened since last reboot."
policy_exception_justification: "Requires explicit admin action."
}
)");
return std::unique_ptr<UploadJob>(new UploadJobImpl(
upload_url, robot_account_id, device_oauth2_token_service,
system_request_context, delegate,
base::WrapUnique(new UploadJobImpl::RandomMimeBoundaryGenerator),
base::ThreadTaskRunnerHandle::Get()));
traffic_annotation, base::ThreadTaskRunnerHandle::Get()));
}
void ScreenshotDelegate::StoreScreenshot(
......
......@@ -149,11 +149,32 @@ std::unique_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
device_oauth2_token_service->GetRobotAccountId();
SYSLOG(INFO) << "Creating upload job for system log";
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("policy_system_logs", R"(
semantics {
sender: "Chrome OS system log uploader"
description:
"Admins can ask that their devices regularly upload their system "
"logs."
trigger: "After reboot and every 12 hours."
data: "Non-user specific, anonymized system logs from /var/log/."
destination: GOOGLE_OWNED_SERVICE
}
policy {
cookies_allowed: NO
setting: "This feature cannot be disabled in settings."
chrome_policy {
LogUploadEnabled {
LogUploadEnabled: false
}
}
}
)");
return std::make_unique<UploadJobImpl>(
upload_url, robot_account_id, device_oauth2_token_service,
system_request_context, delegate,
std::make_unique<UploadJobImpl::RandomMimeBoundaryGenerator>(),
task_runner_);
traffic_annotation, task_runner_);
}
// Returns the system log upload frequency.
......
......@@ -18,6 +18,7 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/base/mime_util.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_status.h"
namespace policy {
......@@ -153,6 +154,7 @@ UploadJobImpl::UploadJobImpl(
scoped_refptr<net::URLRequestContextGetter> url_context_getter,
Delegate* delegate,
std::unique_ptr<MimeBoundaryGenerator> boundary_generator,
net::NetworkTrafficAnnotationTag traffic_annotation,
scoped_refptr<base::SequencedTaskRunner> task_runner)
: OAuth2TokenService::Consumer("cros_upload_job"),
upload_url_(upload_url),
......@@ -161,6 +163,7 @@ UploadJobImpl::UploadJobImpl(
url_context_getter_(url_context_getter),
delegate_(delegate),
boundary_generator_(std::move(boundary_generator)),
traffic_annotation_(traffic_annotation),
state_(IDLE),
retry_(0),
task_runner_(task_runner),
......@@ -305,8 +308,8 @@ void UploadJobImpl::CreateAndStartURLFetcher(const std::string& access_token) {
content_type.append("; boundary=");
content_type.append(*mime_boundary_.get());
upload_fetcher_ =
net::URLFetcher::Create(upload_url_, net::URLFetcher::POST, this);
upload_fetcher_ = net::URLFetcher::Create(upload_url_, net::URLFetcher::POST,
this, traffic_annotation_);
upload_fetcher_->SetRequestContext(url_context_getter_.get());
upload_fetcher_->SetUploadData(content_type, *post_data_);
upload_fetcher_->AddExtraRequestHeader(
......
......@@ -62,7 +62,8 @@ class UploadJobImpl : public UploadJob,
scoped_refptr<net::URLRequestContextGetter> url_context_getter,
Delegate* delegate,
std::unique_ptr<MimeBoundaryGenerator> boundary_generator,
const scoped_refptr<base::SequencedTaskRunner> task_runner);
net::NetworkTrafficAnnotationTag traffic_annotation,
scoped_refptr<base::SequencedTaskRunner> task_runner);
~UploadJobImpl() override;
// UploadJob:
......@@ -145,6 +146,10 @@ class UploadJobImpl : public UploadJob,
// SetUpMultipart().
std::unique_ptr<MimeBoundaryGenerator> boundary_generator_;
// Network traffic annotation set by the delegate describing what kind of data
// is uploaded.
net::NetworkTrafficAnnotationTag traffic_annotation_;
// Current state the uploader is in.
State state_;
......
......@@ -26,6 +26,7 @@
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -200,7 +201,7 @@ class UploadJobTestBase : public testing::Test, public UploadJob::Delegate {
std::unique_ptr<UploadJob> upload_job(new UploadJobImpl(
GetServerURL(), kRobotAccountId, &oauth2_service_,
request_context_getter_.get(), this, std::move(mime_boundary_generator),
base::ThreadTaskRunnerHandle::Get()));
TRAFFIC_ANNOTATION_FOR_TESTS, base::ThreadTaskRunnerHandle::Get()));
std::map<std::string, std::string> header_entries;
header_entries.insert(std::make_pair(kCustomField1, "CUSTOM1"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment