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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "net/tools/gdig/file_net_log.h" | 11 #include "net/tools/gdig/file_net_log.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 FileNetLog::FileNetLog(FILE* destination, LogLevel level) | 15 FileNetLogObserver::FileNetLogObserver(FILE* destination) |
16 : log_level_(level), | 16 : destination_(destination) { |
17 destination_(destination) { | |
18 DCHECK(destination != NULL); | 17 DCHECK(destination != NULL); |
19 // Without calling GetNext() once here, the first GetNext will return 0 | |
20 // that is not a valid id. | |
21 sequence_number_.GetNext(); | |
22 } | 18 } |
23 | 19 |
24 FileNetLog::~FileNetLog() { | 20 FileNetLogObserver::~FileNetLogObserver() { |
25 } | 21 } |
26 | 22 |
27 void FileNetLog::OnAddEntry(const net::NetLog::Entry& entry) { | 23 void FileNetLogObserver::OnAddEntry(const net::NetLog::Entry& entry) { |
28 // Only BoundNetLogs without a NetLog should have an invalid source. | 24 // Only BoundNetLogs without a NetLog should have an invalid source. |
29 DCHECK(entry.source().IsValid()); | 25 DCHECK(entry.source().IsValid()); |
30 | 26 |
31 const char* source = SourceTypeToString(entry.source().type); | 27 const char* source = NetLog::SourceTypeToString(entry.source().type); |
32 const char* type = EventTypeToString(entry.type()); | 28 const char* type = NetLog::EventTypeToString(entry.type()); |
33 | 29 |
34 scoped_ptr<Value> param_value(entry.ParametersToValue()); | 30 scoped_ptr<Value> param_value(entry.ParametersToValue()); |
35 std::string params; | 31 std::string params; |
36 if (param_value.get() != NULL) { | 32 if (param_value.get() != NULL) { |
37 JSONStringValueSerializer serializer(¶ms); | 33 JSONStringValueSerializer serializer(¶ms); |
38 bool ret = serializer.Serialize(*param_value); | 34 bool ret = serializer.Serialize(*param_value); |
39 DCHECK(ret); | 35 DCHECK(ret); |
40 } | 36 } |
41 base::Time now = base::Time::NowFromSystemTime(); | 37 base::Time now = base::Time::NowFromSystemTime(); |
42 base::AutoLock lock(lock_); | 38 base::AutoLock lock(lock_); |
43 if (first_event_time_.is_null()) { | 39 if (first_event_time_.is_null()) { |
44 first_event_time_ = now; | 40 first_event_time_ = now; |
45 } | 41 } |
46 base::TimeDelta elapsed_time = now - first_event_time_; | 42 base::TimeDelta elapsed_time = now - first_event_time_; |
47 fprintf(destination_ , "%u\t%u\t%s\t%s\t%s\n", | 43 fprintf(destination_ , "%u\t%u\t%s\t%s\t%s\n", |
48 static_cast<unsigned>(elapsed_time.InMilliseconds()), | 44 static_cast<unsigned>(elapsed_time.InMilliseconds()), |
49 entry.source().id, source, type, params.c_str()); | 45 entry.source().id, source, type, params.c_str()); |
50 } | 46 } |
51 | 47 |
52 uint32 FileNetLog::NextID() { | |
53 return sequence_number_.GetNext(); | |
54 } | |
55 | |
56 NetLog::LogLevel FileNetLog::GetLogLevel() const { | |
57 return log_level_; | |
58 } | |
59 | |
60 void FileNetLog::AddThreadSafeObserver( | |
61 NetLog::ThreadSafeObserver* observer, | |
62 NetLog::LogLevel log_level) { | |
63 NOTIMPLEMENTED() << "Not currently used by gdig."; | |
64 } | |
65 | |
66 void FileNetLog::SetObserverLogLevel(ThreadSafeObserver* observer, | |
67 LogLevel log_level) { | |
68 NOTIMPLEMENTED() << "Not currently used by gdig."; | |
69 } | |
70 | |
71 void FileNetLog::RemoveThreadSafeObserver( | |
72 NetLog::ThreadSafeObserver* observer) { | |
73 NOTIMPLEMENTED() << "Not currently used by gdig."; | |
74 } | |
75 | |
76 } // namespace net | 48 } // namespace net |
OLD | NEW |