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

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

Issue 10539094: NetLogEventParameter to Callback refactoring 1, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove unneeded line Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 27 matching lines...) Expand all
38 return params->ToValue(); 38 return params->ToValue();
39 } 39 }
40 40
41 Value* SourceEventParametersCallback(const NetLog::Source source, 41 Value* SourceEventParametersCallback(const NetLog::Source source,
42 NetLog::LogLevel /* log_level */) { 42 NetLog::LogLevel /* log_level */) {
43 DictionaryValue* event_params = new DictionaryValue(); 43 DictionaryValue* event_params = new DictionaryValue();
44 source.AddToEventParameters(event_params); 44 source.AddToEventParameters(event_params);
45 return event_params; 45 return event_params;
46 } 46 }
47 47
48 Value* SingleIntegerCallback(const char* name, 48 Value* NetLogIntegerCallback(const char* name,
49 int value, 49 int value,
50 NetLog::LogLevel /* log_level */) { 50 NetLog::LogLevel /* log_level */) {
51 if (!value)
52 return NULL;
53 DictionaryValue* event_params = new DictionaryValue(); 51 DictionaryValue* event_params = new DictionaryValue();
54 event_params->SetInteger(name, value); 52 event_params->SetInteger(name, value);
55 return event_params; 53 return event_params;
56 } 54 }
57 55
56 Value* NetLogStringCallback(const char* name,
57 const std::string* value,
58 NetLog::LogLevel /* log_level */) {
59 DictionaryValue* event_params = new DictionaryValue();
60 event_params->SetString(name, *value);
61 return event_params;
62 }
63
58 } // namespace 64 } // namespace
59 65
60 Value* NetLog::Source::ToValue() const { 66 Value* NetLog::Source::ToValue() const {
61 DictionaryValue* dict = new DictionaryValue(); 67 DictionaryValue* dict = new DictionaryValue();
62 dict->SetInteger("type", static_cast<int>(type)); 68 dict->SetInteger("type", static_cast<int>(type));
63 dict->SetInteger("id", static_cast<int>(id)); 69 dict->SetInteger("id", static_cast<int>(id));
64 return dict; 70 return dict;
65 } 71 }
66 72
67 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const { 73 void NetLog::Source::AddToEventParameters(DictionaryValue* event_params) const {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 262 }
257 263
258 // static 264 // static
259 bool NetLog::IsLoggingAllEvents(LogLevel log_level) { 265 bool NetLog::IsLoggingAllEvents(LogLevel log_level) {
260 return log_level <= NetLog::LOG_ALL_BUT_BYTES; 266 return log_level <= NetLog::LOG_ALL_BUT_BYTES;
261 } 267 }
262 268
263 // static 269 // static
264 NetLog::ParametersCallback NetLog::IntegerCallback(const char* name, 270 NetLog::ParametersCallback NetLog::IntegerCallback(const char* name,
265 int value) { 271 int value) {
266 return base::Bind(&SingleIntegerCallback, name, value); 272 return base::Bind(&NetLogIntegerCallback, name, value);
273 }
274
275 // static
276 NetLog::ParametersCallback NetLog::StringCallback(const char* name,
277 const std::string* value) {
278 DCHECK(value);
279 return base::Bind(&NetLogStringCallback, name, value);
267 } 280 }
268 281
269 void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) { 282 void NetLog::OnAddObserver(ThreadSafeObserver* observer, LogLevel log_level) {
270 DCHECK(!observer->net_log_); 283 DCHECK(!observer->net_log_);
271 observer->net_log_ = this; 284 observer->net_log_ = this;
272 observer->log_level_ = log_level; 285 observer->log_level_ = log_level;
273 } 286 }
274 287
275 void NetLog::OnSetObserverLogLevel(ThreadSafeObserver* observer, 288 void NetLog::OnSetObserverLogLevel(ThreadSafeObserver* observer,
276 LogLevel log_level) { 289 LogLevel log_level) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type, 382 void BoundNetLog::AddEventWithNetErrorCode(NetLog::EventType event_type,
370 int net_error) const { 383 int net_error) const {
371 DCHECK_GT(0, net_error); 384 DCHECK_GT(0, net_error);
372 DCHECK_NE(ERR_IO_PENDING, net_error); 385 DCHECK_NE(ERR_IO_PENDING, net_error);
373 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); 386 AddEvent(event_type, NetLog::IntegerCallback("net_error", net_error));
374 } 387 }
375 388
376 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type, 389 void BoundNetLog::EndEventWithNetErrorCode(NetLog::EventType event_type,
377 int net_error) const { 390 int net_error) const {
378 DCHECK_NE(ERR_IO_PENDING, net_error); 391 DCHECK_NE(ERR_IO_PENDING, net_error);
379 EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error)); 392 if (net_error >= 0) {
393 EndEvent(event_type);
394 } else {
395 EndEvent(event_type, NetLog::IntegerCallback("net_error", net_error));
396 }
380 } 397 }
381 398
382 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type, 399 void BoundNetLog::AddByteTransferEvent(NetLog::EventType event_type,
383 int byte_count, 400 int byte_count,
384 const char* bytes) const { 401 const char* bytes) const {
385 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes)); 402 AddEvent(event_type, base::Bind(BytesTransferredCallback, byte_count, bytes));
386 } 403 }
387 404
388 NetLog::LogLevel BoundNetLog::GetLogLevel() const { 405 NetLog::LogLevel BoundNetLog::GetLogLevel() const {
389 if (net_log_) 406 if (net_log_)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 447 }
431 448
432 Value* NetLogSourceParameter::ToValue() const { 449 Value* NetLogSourceParameter::ToValue() const {
433 DictionaryValue* dict = new DictionaryValue(); 450 DictionaryValue* dict = new DictionaryValue();
434 if (value_.is_valid()) 451 if (value_.is_valid())
435 dict->Set(name_, value_.ToValue()); 452 dict->Set(name_, value_.ToValue());
436 return dict; 453 return dict;
437 } 454 }
438 455
439 } // namespace net 456 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698