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 #ifndef BASE_LOCATION_H_ | 5 #ifndef BASE_LOCATION_H_ |
6 #define BASE_LOCATION_H_ | 6 #define BASE_LOCATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 | 11 #include "base/basictypes.h" |
12 namespace base { | |
13 class DictionaryValue; | |
14 } | |
15 | 12 |
16 namespace tracked_objects { | 13 namespace tracked_objects { |
17 | 14 |
18 // Location provides basic info where of an object was constructed, or was | 15 // Location provides basic info where of an object was constructed, or was |
19 // significantly brought to life. | 16 // significantly brought to life. |
20 class BASE_EXPORT Location { | 17 class BASE_EXPORT Location { |
21 public: | 18 public: |
22 // Constructor should be called with a long-lived char*, such as __FILE__. | 19 // Constructor should be called with a long-lived char*, such as __FILE__. |
23 // It assumes the provided value will persist as a global constant, and it | 20 // It assumes the provided value will persist as a global constant, and it |
24 // will not make a copy of it. | 21 // will not make a copy of it. |
(...skipping 29 matching lines...) Expand all Loading... |
54 // Translate the some of the state in this instance into a human readable | 51 // Translate the some of the state in this instance into a human readable |
55 // string with HTML characters in the function names escaped, and append that | 52 // string with HTML characters in the function names escaped, and append that |
56 // string to |output|. Inclusion of the file_name_ and function_name_ are | 53 // string to |output|. Inclusion of the file_name_ and function_name_ are |
57 // optional, and controlled by the boolean arguments. | 54 // optional, and controlled by the boolean arguments. |
58 void Write(bool display_filename, bool display_function_name, | 55 void Write(bool display_filename, bool display_function_name, |
59 std::string* output) const; | 56 std::string* output) const; |
60 | 57 |
61 // Write function_name_ in HTML with '<' and '>' properly encoded. | 58 // Write function_name_ in HTML with '<' and '>' properly encoded. |
62 void WriteFunctionName(std::string* output) const; | 59 void WriteFunctionName(std::string* output) const; |
63 | 60 |
64 // Construct a Value* representation. The caller assumes ownership of the | |
65 // memory in the returned instance. | |
66 base::DictionaryValue* ToValue() const; | |
67 | |
68 private: | 61 private: |
69 const char* function_name_; | 62 const char* function_name_; |
70 const char* file_name_; | 63 const char* file_name_; |
71 int line_number_; | 64 int line_number_; |
72 const void* program_counter_; | 65 const void* program_counter_; |
73 }; | 66 }; |
74 | 67 |
| 68 // A "snapshotted" representation of the Location class that can safely be |
| 69 // passed across process boundaries. |
| 70 struct BASE_EXPORT LocationSnapshot { |
| 71 // The default constructor is exposed to support the IPC serialization macros. |
| 72 LocationSnapshot(); |
| 73 explicit LocationSnapshot(const tracked_objects::Location& location); |
| 74 ~LocationSnapshot(); |
| 75 |
| 76 std::string file_name; |
| 77 std::string function_name; |
| 78 int line_number; |
| 79 }; |
| 80 |
75 BASE_EXPORT const void* GetProgramCounter(); | 81 BASE_EXPORT const void* GetProgramCounter(); |
76 | 82 |
77 // Define a macro to record the current source location. | 83 // Define a macro to record the current source location. |
78 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) | 84 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) |
79 | 85 |
80 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \ | 86 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \ |
81 ::tracked_objects::Location(function_name, \ | 87 ::tracked_objects::Location(function_name, \ |
82 __FILE__, \ | 88 __FILE__, \ |
83 __LINE__, \ | 89 __LINE__, \ |
84 ::tracked_objects::GetProgramCounter()) | 90 ::tracked_objects::GetProgramCounter()) |
85 | 91 |
86 } // namespace tracked_objects | 92 } // namespace tracked_objects |
87 | 93 |
88 #endif // BASE_LOCATION_H_ | 94 #endif // BASE_LOCATION_H_ |
OLD | NEW |