| OLD | NEW |
| 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/socket/stream_socket.h" | 5 #include "net/socket/stream_socket.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace { | |
| 15 | |
| 16 // Parameters for SOCKET_BYTES_RECEIVED and SOCKET_BYTES_SENT events. | |
| 17 // Includes bytes transferred and, if |bytes| is not NULL, the bytes themselves. | |
| 18 class NetLogBytesTransferredParameter : public NetLog::EventParameters { | |
| 19 public: | |
| 20 NetLogBytesTransferredParameter(int byte_count, const char* bytes); | |
| 21 | |
| 22 virtual Value* ToValue() const; | |
| 23 | |
| 24 private: | |
| 25 const int byte_count_; | |
| 26 std::string hex_encoded_bytes_; | |
| 27 bool has_bytes_; | |
| 28 }; | |
| 29 | |
| 30 NetLogBytesTransferredParameter::NetLogBytesTransferredParameter( | |
| 31 int byte_count, const char* transferred_bytes) | |
| 32 : byte_count_(byte_count), | |
| 33 has_bytes_(false) { | |
| 34 if (transferred_bytes) { | |
| 35 hex_encoded_bytes_ = base::HexEncode(transferred_bytes, byte_count); | |
| 36 has_bytes_ = true; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 Value* NetLogBytesTransferredParameter::ToValue() const { | |
| 41 DictionaryValue* dict = new DictionaryValue(); | |
| 42 dict->SetInteger("byte_count", byte_count_); | |
| 43 if (has_bytes_) | |
| 44 dict->SetString("hex_encoded_bytes", hex_encoded_bytes_); | |
| 45 return dict; | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 StreamSocket::UseHistory::UseHistory() | 14 StreamSocket::UseHistory::UseHistory() |
| 51 : was_ever_connected_(false), | 15 : was_ever_connected_(false), |
| 52 was_used_to_convey_data_(false), | 16 was_used_to_convey_data_(false), |
| 53 omnibox_speculation_(false), | 17 omnibox_speculation_(false), |
| 54 subresource_speculation_(false) { | 18 subresource_speculation_(false) { |
| 55 } | 19 } |
| 56 | 20 |
| 57 StreamSocket::UseHistory::~UseHistory() { | 21 StreamSocket::UseHistory::~UseHistory() { |
| 58 EmitPreconnectionHistograms(); | 22 EmitPreconnectionHistograms(); |
| 59 } | 23 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 static const bool connect_backup_jobs_fieldtrial = | 100 static const bool connect_backup_jobs_fieldtrial = |
| 137 base::FieldTrialList::TrialExists("ConnnectBackupJobs"); | 101 base::FieldTrialList::TrialExists("ConnnectBackupJobs"); |
| 138 if (connect_backup_jobs_fieldtrial) { | 102 if (connect_backup_jobs_fieldtrial) { |
| 139 UMA_HISTOGRAM_ENUMERATION( | 103 UMA_HISTOGRAM_ENUMERATION( |
| 140 base::FieldTrial::MakeName("Net.PreconnectUtilization2", | 104 base::FieldTrial::MakeName("Net.PreconnectUtilization2", |
| 141 "ConnnectBackupJobs"), | 105 "ConnnectBackupJobs"), |
| 142 result, 9); | 106 result, 9); |
| 143 } | 107 } |
| 144 } | 108 } |
| 145 | 109 |
| 146 void StreamSocket::LogByteTransfer(const BoundNetLog& net_log, | |
| 147 NetLog::EventType event_type, | |
| 148 int byte_count, | |
| 149 char* bytes) const { | |
| 150 scoped_refptr<NetLog::EventParameters> params; | |
| 151 if (net_log.IsLoggingBytes()) { | |
| 152 params = new NetLogBytesTransferredParameter(byte_count, bytes); | |
| 153 } else { | |
| 154 params = new NetLogBytesTransferredParameter(byte_count, NULL); | |
| 155 } | |
| 156 net_log.AddEvent(event_type, params); | |
| 157 } | |
| 158 | |
| 159 } // namespace net | 110 } // namespace net |
| OLD | NEW |