| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/log/net_log_capture_mode.h" | 5 #include "net/log/net_log_capture_mode.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Integer representation for the capture mode. The numeric value is depended on | 13 // Integer representation for the capture mode. The numeric value is depended on |
| 14 // for method of NetLogCaptureMode, which expect that higher values imply more | 14 // for method of NetLogCaptureMode, which expect that higher values imply more |
| 15 // capabilities. | 15 // capabilities. |
| 16 enum InternalValue { | 16 enum InternalValue { |
| 17 // Don't log any events. | |
| 18 NONE, | |
| 19 | |
| 20 // Log all events, but do not include the actual transferred bytes and | 17 // Log all events, but do not include the actual transferred bytes and |
| 21 // remove cookies and HTTP credentials. | 18 // remove cookies and HTTP credentials. |
| 22 DEFAULT, | 19 DEFAULT, |
| 23 | 20 |
| 24 // Log all events, but do not include the actual transferred bytes as | 21 // Log all events, but do not include the actual transferred bytes as |
| 25 // parameters for bytes sent/received events. | 22 // parameters for bytes sent/received events. |
| 26 INCLUDE_COOKIES_AND_CREDENTIALS, | 23 INCLUDE_COOKIES_AND_CREDENTIALS, |
| 27 | 24 |
| 28 // Log everything possible, even if it is slow and memory expensive. | 25 // Log everything possible, even if it is slow and memory expensive. |
| 29 // Includes logging of transferred bytes. | 26 // Includes logging of transferred bytes. |
| 30 INCLUDE_SOCKET_BYTES, | 27 INCLUDE_SOCKET_BYTES, |
| 31 }; | 28 }; |
| 32 | 29 |
| 33 } // namespace | 30 } // namespace |
| 34 | 31 |
| 35 // Default constructor creates an empty capture mode. | 32 NetLogCaptureMode::NetLogCaptureMode() : NetLogCaptureMode(DEFAULT) { |
| 36 NetLogCaptureMode::NetLogCaptureMode() : NetLogCaptureMode(NONE) { | |
| 37 } | |
| 38 | |
| 39 NetLogCaptureMode NetLogCaptureMode::None() { | |
| 40 return NetLogCaptureMode(NONE); | |
| 41 } | 33 } |
| 42 | 34 |
| 43 NetLogCaptureMode NetLogCaptureMode::Default() { | 35 NetLogCaptureMode NetLogCaptureMode::Default() { |
| 44 return NetLogCaptureMode(DEFAULT); | 36 return NetLogCaptureMode(DEFAULT); |
| 45 } | 37 } |
| 46 | 38 |
| 47 NetLogCaptureMode NetLogCaptureMode::IncludeCookiesAndCredentials() { | 39 NetLogCaptureMode NetLogCaptureMode::IncludeCookiesAndCredentials() { |
| 48 return NetLogCaptureMode(INCLUDE_COOKIES_AND_CREDENTIALS); | 40 return NetLogCaptureMode(INCLUDE_COOKIES_AND_CREDENTIALS); |
| 49 } | 41 } |
| 50 | 42 |
| 51 NetLogCaptureMode NetLogCaptureMode::IncludeSocketBytes() { | 43 NetLogCaptureMode NetLogCaptureMode::IncludeSocketBytes() { |
| 52 return NetLogCaptureMode(INCLUDE_SOCKET_BYTES); | 44 return NetLogCaptureMode(INCLUDE_SOCKET_BYTES); |
| 53 } | 45 } |
| 54 | 46 |
| 55 NetLogCaptureMode NetLogCaptureMode::Max(NetLogCaptureMode mode1, | |
| 56 NetLogCaptureMode mode2) { | |
| 57 return NetLogCaptureMode(std::max(mode1.value_, mode2.value_)); | |
| 58 } | |
| 59 | |
| 60 bool NetLogCaptureMode::enabled() const { | |
| 61 return value_ != NONE; | |
| 62 } | |
| 63 | |
| 64 bool NetLogCaptureMode::include_cookies_and_credentials() const { | 47 bool NetLogCaptureMode::include_cookies_and_credentials() const { |
| 65 return value_ >= INCLUDE_COOKIES_AND_CREDENTIALS; | 48 return value_ >= INCLUDE_COOKIES_AND_CREDENTIALS; |
| 66 } | 49 } |
| 67 | 50 |
| 68 bool NetLogCaptureMode::include_socket_bytes() const { | 51 bool NetLogCaptureMode::include_socket_bytes() const { |
| 69 return value_ >= INCLUDE_SOCKET_BYTES; | 52 return value_ >= INCLUDE_SOCKET_BYTES; |
| 70 } | 53 } |
| 71 | 54 |
| 72 bool NetLogCaptureMode::operator==(NetLogCaptureMode mode) const { | 55 bool NetLogCaptureMode::operator==(NetLogCaptureMode mode) const { |
| 73 return value_ == mode.value_; | 56 return value_ == mode.value_; |
| 74 } | 57 } |
| 75 | 58 |
| 76 bool NetLogCaptureMode::operator!=(NetLogCaptureMode mode) const { | 59 bool NetLogCaptureMode::operator!=(NetLogCaptureMode mode) const { |
| 77 return !(*this == mode); | 60 return !(*this == mode); |
| 78 } | 61 } |
| 79 | 62 |
| 80 int32_t NetLogCaptureMode::ToInternalValueForTesting() const { | 63 int32_t NetLogCaptureMode::ToInternalValueForTesting() const { |
| 81 return ToInternalValue(); | 64 return value_; |
| 82 } | 65 } |
| 83 | 66 |
| 84 NetLogCaptureMode::NetLogCaptureMode(uint32_t value) : value_(value) { | 67 NetLogCaptureMode::NetLogCaptureMode(uint32_t value) : value_(value) { |
| 85 } | 68 } |
| 86 | 69 |
| 87 NetLogCaptureMode NetLogCaptureMode::FromInternalValue(int32_t value) { | |
| 88 return NetLogCaptureMode(value); | |
| 89 } | |
| 90 | |
| 91 int32_t NetLogCaptureMode::ToInternalValue() const { | |
| 92 return value_; | |
| 93 } | |
| 94 | |
| 95 } // namespace net | 70 } // namespace net |
| OLD | NEW |