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

Side by Side Diff: net/base/net_log.cc

Issue 7084007: Adds URLRequestJob bytes read to NetLog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/base/net_log.h" 5 #include "net/base/net_log.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 namespace {
17
18 // Parameters for logging data transferred events. Includes bytes transferred
19 // and, if |bytes| is not NULL, the bytes themselves.
20 class NetLogBytesTransferredParameter : public NetLog::EventParameters {
21 public:
22 NetLogBytesTransferredParameter(int byte_count, const char* bytes);
23
24 virtual Value* ToValue() const;
25
26 private:
27 const int byte_count_;
28 std::string hex_encoded_bytes_;
29 bool has_bytes_;
30 };
31
32 NetLogBytesTransferredParameter::NetLogBytesTransferredParameter(
33 int byte_count, const char* transferred_bytes)
34 : byte_count_(byte_count),
35 has_bytes_(false) {
36 if (transferred_bytes) {
37 hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count);
38 has_bytes_ = true;
39 }
40 }
41
42 Value* NetLogBytesTransferredParameter::ToValue() const {
43 DictionaryValue* dict = new DictionaryValue();
44 dict->SetInteger("byte_count", byte_count_);
45 if (has_bytes_ && byte_count_ > 0)
46 dict->SetString("hex_encoded_bytes", hex_encoded_bytes_);
47 return dict;
48 }
49
50 } // namespace
51
16 Value* NetLog::Source::ToValue() const { 52 Value* NetLog::Source::ToValue() const {
17 DictionaryValue* dict = new DictionaryValue(); 53 DictionaryValue* dict = new DictionaryValue();
18 dict->SetInteger("type", static_cast<int>(type)); 54 dict->SetInteger("type", static_cast<int>(type));
19 dict->SetInteger("id", static_cast<int>(id)); 55 dict->SetInteger("id", static_cast<int>(id));
20 return dict; 56 return dict;
21 } 57 }
22 58
23 // static 59 // static
24 std::string NetLog::TickCountToString(const base::TimeTicks& time) { 60 std::string NetLog::TickCountToString(const base::TimeTicks& time) {
25 int64 delta_time = (time - base::TimeTicks()).InMilliseconds(); 61 int64 delta_time = (time - base::TimeTicks()).InMilliseconds();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 DCHECK_NE(net_error, ERR_IO_PENDING); 186 DCHECK_NE(net_error, ERR_IO_PENDING);
151 if (net_error >= 0) { 187 if (net_error >= 0) {
152 EndEvent(event_type, NULL); 188 EndEvent(event_type, NULL);
153 } else { 189 } else {
154 EndEvent( 190 EndEvent(
155 event_type, 191 event_type,
156 make_scoped_refptr(new NetLogIntegerParameter("net_error", net_error))); 192 make_scoped_refptr(new NetLogIntegerParameter("net_error", net_error)));
157 } 193 }
158 } 194 }
159 195
196 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type,
197 int byte_count, char* bytes) const {
198 scoped_refptr<NetLog::EventParameters> params;
199 if (IsLoggingBytes()) {
200 params = new NetLogBytesTransferredParameter(byte_count, bytes);
201 } else {
202 params = new NetLogBytesTransferredParameter(byte_count, NULL);
203 }
204 AddEvent(event_type, params);
205 }
206
160 NetLog::LogLevel BoundNetLog::GetLogLevel() const { 207 NetLog::LogLevel BoundNetLog::GetLogLevel() const {
161 if (net_log_) 208 if (net_log_)
162 return net_log_->GetLogLevel(); 209 return net_log_->GetLogLevel();
163 return NetLog::LOG_BASIC; 210 return NetLog::LOG_BASIC;
164 } 211 }
165 212
166 bool BoundNetLog::IsLoggingBytes() const { 213 bool BoundNetLog::IsLoggingBytes() const {
167 return GetLogLevel() == NetLog::LOG_ALL; 214 return GetLogLevel() == NetLog::LOG_ALL;
168 } 215 }
169 216
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 const scoped_refptr<NetLog::EventParameters>& end_event_params) { 272 const scoped_refptr<NetLog::EventParameters>& end_event_params) {
226 DCHECK(!end_event_params_.get()); 273 DCHECK(!end_event_params_.get());
227 end_event_params_ = end_event_params; 274 end_event_params_ = end_event_params;
228 } 275 }
229 276
230 const BoundNetLog& ScopedNetLogEvent::net_log() const { 277 const BoundNetLog& ScopedNetLogEvent::net_log() const {
231 return net_log_; 278 return net_log_;
232 } 279 }
233 280
234 } // namespace net 281 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698