Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: remoting/base/telemetry_log_writer.cc

Issue 2729423003: Network traffic annotation added to chromium_url_request. (Closed)
Patch Set: Annotations updated. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/base/chromium_url_request.cc ('k') | remoting/base/telemetry_log_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/base/telemetry_log_writer.h" 5 #include "remoting/base/telemetry_log_writer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "net/http/http_status_code.h" 11 #include "net/http/http_status_code.h"
12 #include "net/traffic_annotation/network_traffic_annotation.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 const int kMaxSendAttempts = 5; 16 const int kMaxSendAttempts = 5;
16 17
17 TelemetryLogWriter::TelemetryLogWriter( 18 TelemetryLogWriter::TelemetryLogWriter(
18 const std::string& telemetry_base_url, 19 const std::string& telemetry_base_url,
19 std::unique_ptr<UrlRequestFactory> request_factory) 20 std::unique_ptr<UrlRequestFactory> request_factory)
20 : telemetry_base_url_(telemetry_base_url), 21 : telemetry_base_url_(telemetry_base_url),
21 request_factory_(std::move(request_factory)) {} 22 request_factory_(std::move(request_factory)) {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (!serializer.Serialize(log_dictionary)) { 62 if (!serializer.Serialize(log_dictionary)) {
62 LOG(ERROR) << "Failed to serialize log to JSON."; 63 LOG(ERROR) << "Failed to serialize log to JSON.";
63 return; 64 return;
64 } 65 }
65 PostJsonToServer(json); 66 PostJsonToServer(json);
66 } 67 }
67 68
68 void TelemetryLogWriter::PostJsonToServer(const std::string& json) { 69 void TelemetryLogWriter::PostJsonToServer(const std::string& json) {
69 DCHECK(thread_checker_.CalledOnValidThread()); 70 DCHECK(thread_checker_.CalledOnValidThread());
70 DCHECK(!request_); 71 DCHECK(!request_);
71 request_ = request_factory_->CreateUrlRequest(UrlRequest::Type::POST, 72 net::NetworkTrafficAnnotationTag traffic_annotation =
72 telemetry_base_url_); 73 net::DefineNetworkTrafficAnnotation("CRD_telemetry_log", R"(
74 semantics {
75 sender: "Chrome Remote Desktop"
76 description: "Telemetry logs for Chrome Remote Desktop."
77 trigger: "Chrome Remote Desktop is being used."
78 data: "Anonymous usage statistics."
79 destination: GOOGLE_OWNED_SERVICE
80 }
81 policy {
82 cookies_allowed: false/true
83 cookies_store: "..."
84 setting:
85 "This feature cannot be disabled by settings. You can block Chrome "
86 "Remote Desktop as specified here: "
87 "https://support.google.com/chrome/a/answer/2799701?hl=en"
88 policy_exception_justification:
89 "The product is shipped separately from Chromium, except on Chrome "
90 "OS. In future the same code will be used for the host and we "
91 "could potentially add one."
Sergey Ulanov 2017/04/04 00:16:48 Not sure the second sentence is necessary. If you
Ramin Halavati 2017/04/04 07:37:18 Done.
92 })");
93 request_ = request_factory_->CreateUrlRequest(
94 UrlRequest::Type::POST, telemetry_base_url_, traffic_annotation);
73 if (!auth_token_.empty()) { 95 if (!auth_token_.empty()) {
74 request_->AddHeader("Authorization:Bearer " + auth_token_); 96 request_->AddHeader("Authorization:Bearer " + auth_token_);
75 } 97 }
76 98
77 VLOG(1) << "Posting log to telemetry server: " << json; 99 VLOG(1) << "Posting log to telemetry server: " << json;
78 100
79 request_->SetPostData("application/json", json); 101 request_->SetPostData("application/json", json);
80 request_->Start( 102 request_->Start(
81 base::Bind(&TelemetryLogWriter::OnSendLogResult, base::Unretained(this))); 103 base::Bind(&TelemetryLogWriter::OnSendLogResult, base::Unretained(this)));
82 } 104 }
(...skipping 25 matching lines...) Expand all
108 request_.reset(); // This may also destroy the result. 130 request_.reset(); // This may also destroy the result.
109 if (should_call_auth_closure) { 131 if (should_call_auth_closure) {
110 VLOG(1) << "Request is unauthorized. Trying to call the auth closure..."; 132 VLOG(1) << "Request is unauthorized. Trying to call the auth closure...";
111 auth_closure_.Run(); 133 auth_closure_.Run();
112 } else { 134 } else {
113 SendPendingEntries(); 135 SendPendingEntries();
114 } 136 }
115 } 137 }
116 138
117 } // namespace remoting 139 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/chromium_url_request.cc ('k') | remoting/base/telemetry_log_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698