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

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

Issue 2729423003: Network traffic annotation added to chromium_url_request. (Closed)
Patch Set: Annotation updated. Created 3 years, 7 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:
78 "These requests are sent periodically when a session is connected, "
79 "i.e. CRD app is open and is connected to a host."
80 data:
81 "Anonymous usage statistics. Please see https://cs.chromium.org/"
82 "chromium/src/remoting/base/chromoting_event.h for more details."
83 destination: GOOGLE_OWNED_SERVICE
84 }
85 policy {
86 cookies_allowed: false
87 setting:
88 "This feature cannot be disabled by settings. You can block Chrome "
89 "Remote Desktop as specified here: "
90 "https://support.google.com/chrome/?p=remote_desktop"
91 policy_exception_justification:
92 "The product is shipped separately from Chromium, except on Chrome "
93 "OS."
94 })");
95 request_ = request_factory_->CreateUrlRequest(
96 UrlRequest::Type::POST, telemetry_base_url_, traffic_annotation);
73 if (!auth_token_.empty()) { 97 if (!auth_token_.empty()) {
74 request_->AddHeader("Authorization:Bearer " + auth_token_); 98 request_->AddHeader("Authorization:Bearer " + auth_token_);
75 } 99 }
76 100
77 VLOG(1) << "Posting log to telemetry server: " << json; 101 VLOG(1) << "Posting log to telemetry server: " << json;
78 102
79 request_->SetPostData("application/json", json); 103 request_->SetPostData("application/json", json);
80 request_->Start( 104 request_->Start(
81 base::Bind(&TelemetryLogWriter::OnSendLogResult, base::Unretained(this))); 105 base::Bind(&TelemetryLogWriter::OnSendLogResult, base::Unretained(this)));
82 } 106 }
(...skipping 25 matching lines...) Expand all
108 request_.reset(); // This may also destroy the result. 132 request_.reset(); // This may also destroy the result.
109 if (should_call_auth_closure) { 133 if (should_call_auth_closure) {
110 VLOG(1) << "Request is unauthorized. Trying to call the auth closure..."; 134 VLOG(1) << "Request is unauthorized. Trying to call the auth closure...";
111 auth_closure_.Run(); 135 auth_closure_.Run();
112 } else { 136 } else {
113 SendPendingEntries(); 137 SendPendingEntries();
114 } 138 }
115 } 139 }
116 140
117 } // namespace remoting 141 } // 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