OLD | NEW |
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/tools/gdig/file_net_log.h" | 5 #include "net/tools/gdig/file_net_log.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "net/log/net_log_entry.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 FileNetLogObserver::FileNetLogObserver(FILE* destination) | 18 FileNetLogObserver::FileNetLogObserver(FILE* destination) |
18 : destination_(destination) { | 19 : destination_(destination) { |
19 DCHECK(destination != NULL); | 20 DCHECK(destination != NULL); |
20 } | 21 } |
21 | 22 |
22 FileNetLogObserver::~FileNetLogObserver() { | 23 FileNetLogObserver::~FileNetLogObserver() { |
23 } | 24 } |
24 | 25 |
25 void FileNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { | 26 void FileNetLogObserver::OnAddEntry(const net::NetLogEntry& entry) { |
26 // Only NetLogWithSources without a NetLog should have an invalid source. | 27 // Only NetLogWithSources without a NetLog should have an invalid source. |
27 DCHECK(entry.source().IsValid()); | 28 DCHECK(entry.source().IsValid()); |
28 | 29 |
29 const char* source = NetLog::SourceTypeToString(entry.source().type); | 30 const char* source = NetLog::SourceTypeToString(entry.source().type); |
30 const char* type = NetLog::EventTypeToString(entry.type()); | 31 const char* type = NetLog::EventTypeToString(entry.type()); |
31 | 32 |
32 std::unique_ptr<base::Value> param_value(entry.ParametersToValue()); | 33 std::unique_ptr<base::Value> param_value(entry.ParametersToValue()); |
33 std::string params; | 34 std::string params; |
34 if (param_value.get() != NULL) { | 35 if (param_value.get() != NULL) { |
35 JSONStringValueSerializer serializer(¶ms); | 36 JSONStringValueSerializer serializer(¶ms); |
36 bool ret = serializer.Serialize(*param_value); | 37 bool ret = serializer.Serialize(*param_value); |
37 DCHECK(ret); | 38 DCHECK(ret); |
38 } | 39 } |
39 base::Time now = base::Time::NowFromSystemTime(); | 40 base::Time now = base::Time::NowFromSystemTime(); |
40 base::AutoLock lock(lock_); | 41 base::AutoLock lock(lock_); |
41 if (first_event_time_.is_null()) { | 42 if (first_event_time_.is_null()) { |
42 first_event_time_ = now; | 43 first_event_time_ = now; |
43 } | 44 } |
44 base::TimeDelta elapsed_time = now - first_event_time_; | 45 base::TimeDelta elapsed_time = now - first_event_time_; |
45 fprintf(destination_ , "%u\t%u\t%s\t%s\t%s\n", | 46 fprintf(destination_ , "%u\t%u\t%s\t%s\t%s\n", |
46 static_cast<unsigned>(elapsed_time.InMilliseconds()), | 47 static_cast<unsigned>(elapsed_time.InMilliseconds()), |
47 entry.source().id, source, type, params.c_str()); | 48 entry.source().id, source, type, params.c_str()); |
48 } | 49 } |
49 | 50 |
50 } // namespace net | 51 } // namespace net |
OLD | NEW |