| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/disk_cache/trace.h" | 5 #include "net/disk_cache/trace.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 OutputDebugStringA(msg); | 35 OutputDebugStringA(msg); |
| 36 #else | 36 #else |
| 37 NOTIMPLEMENTED(); | 37 NOTIMPLEMENTED(); |
| 38 #endif | 38 #endif |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // namespace | 41 } // namespace |
| 42 | 42 |
| 43 namespace disk_cache { | 43 namespace disk_cache { |
| 44 | 44 |
| 45 // s_trace_buffer and s_trace_object are not singletons because I want the |
| 46 // buffer to be destroyed and re-created when the last user goes away, and it |
| 47 // must be straightforward to access the buffer from the debugger. |
| 48 static TraceObject* s_trace_object = NULL; |
| 49 |
| 50 // Static. |
| 51 TraceObject* TraceObject::GetTraceObject() { |
| 52 if (s_trace_object) |
| 53 return s_trace_object; |
| 54 |
| 55 s_trace_object = new TraceObject(); |
| 56 return s_trace_object; |
| 57 } |
| 58 |
| 45 #if ENABLE_TRACING | 59 #if ENABLE_TRACING |
| 46 | 60 |
| 47 static TraceBuffer* s_trace_buffer = NULL; | 61 static TraceBuffer* s_trace_buffer = NULL; |
| 48 | 62 |
| 49 bool InitTrace(void) { | 63 void InitTrace(void) { |
| 50 DCHECK(!s_trace_buffer); | |
| 51 if (s_trace_buffer) | 64 if (s_trace_buffer) |
| 52 return false; | 65 return; |
| 53 | 66 |
| 54 s_trace_buffer = new TraceBuffer; | 67 s_trace_buffer = new TraceBuffer; |
| 55 memset(s_trace_buffer, 0, sizeof(*s_trace_buffer)); | 68 memset(s_trace_buffer, 0, sizeof(*s_trace_buffer)); |
| 56 return true; | |
| 57 } | 69 } |
| 58 | 70 |
| 59 void DestroyTrace(void) { | 71 void DestroyTrace(void) { |
| 60 DCHECK(s_trace_buffer); | 72 DCHECK(s_trace_buffer); |
| 61 delete s_trace_buffer; | 73 delete s_trace_buffer; |
| 62 s_trace_buffer = NULL; | 74 s_trace_buffer = NULL; |
| 75 s_trace_object = NULL; |
| 63 } | 76 } |
| 64 | 77 |
| 65 void Trace(const char* format, ...) { | 78 void Trace(const char* format, ...) { |
| 66 DCHECK(s_trace_buffer); | 79 DCHECK(s_trace_buffer); |
| 67 va_list ap; | 80 va_list ap; |
| 68 va_start(ap, format); | 81 va_start(ap, format); |
| 69 | 82 |
| 70 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
| 71 vsprintf_s(s_trace_buffer->buffer[s_trace_buffer->current], format, ap); | 84 vsprintf_s(s_trace_buffer->buffer[s_trace_buffer->current], format, ap); |
| 72 #else | 85 #else |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (current == kNumberOfEntries) | 124 if (current == kNumberOfEntries) |
| 112 current = 0; | 125 current = 0; |
| 113 } | 126 } |
| 114 } | 127 } |
| 115 | 128 |
| 116 DebugOutput("End of Traces\n"); | 129 DebugOutput("End of Traces\n"); |
| 117 } | 130 } |
| 118 | 131 |
| 119 #else // ENABLE_TRACING | 132 #else // ENABLE_TRACING |
| 120 | 133 |
| 121 bool InitTrace(void) { | 134 void InitTrace(void) { |
| 122 return true; | 135 return; |
| 123 } | 136 } |
| 124 | 137 |
| 125 void DestroyTrace(void) { | 138 void DestroyTrace(void) { |
| 139 s_trace_object = NULL; |
| 126 } | 140 } |
| 127 | 141 |
| 128 void Trace(const char* format, ...) { | 142 void Trace(const char* format, ...) { |
| 129 } | 143 } |
| 130 | 144 |
| 131 #endif // ENABLE_TRACING | 145 #endif // ENABLE_TRACING |
| 132 | 146 |
| 133 } // namespace disk_cache | 147 } // namespace disk_cache |
| OLD | NEW |