Chromium Code Reviews| 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 |
| 12 namespace base { | |
| 13 class DictionaryValue; | |
| 14 } | |
| 15 | |
| 16 namespace tracked_objects { | 12 namespace tracked_objects { |
| 17 | 13 |
| 18 // Location provides basic info where of an object was constructed, or was | 14 // Location provides basic info where of an object was constructed, or was |
| 19 // significantly brought to life. | 15 // significantly brought to life. |
| 20 class BASE_EXPORT Location { | 16 class BASE_EXPORT Location { |
| 21 public: | 17 public: |
| 22 // Constructor should be called with a long-lived char*, such as __FILE__. | 18 // 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 | 19 // It assumes the provided value will persist as a global constant, and it |
| 24 // will not make a copy of it. | 20 // will not make a copy of it. |
| 25 Location(const char* function_name, | 21 Location(const char* function_name, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 54 // Translate the some of the state in this instance into a human readable | 50 // 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 | 51 // 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 | 52 // string to |output|. Inclusion of the file_name_ and function_name_ are |
| 57 // optional, and controlled by the boolean arguments. | 53 // optional, and controlled by the boolean arguments. |
| 58 void Write(bool display_filename, bool display_function_name, | 54 void Write(bool display_filename, bool display_function_name, |
| 59 std::string* output) const; | 55 std::string* output) const; |
| 60 | 56 |
| 61 // Write function_name_ in HTML with '<' and '>' properly encoded. | 57 // Write function_name_ in HTML with '<' and '>' properly encoded. |
| 62 void WriteFunctionName(std::string* output) const; | 58 void WriteFunctionName(std::string* output) const; |
| 63 | 59 |
| 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: | 60 private: |
| 69 const char* function_name_; | 61 const char* function_name_; |
| 70 const char* file_name_; | 62 const char* file_name_; |
| 71 int line_number_; | 63 int line_number_; |
| 72 const void* program_counter_; | 64 const void* program_counter_; |
| 73 }; | 65 }; |
| 74 | 66 |
| 67 // Serialized representation of the Location class that can safely be passed | |
| 68 // across process boundaries. | |
| 69 struct BASE_EXPORT SerializedLocation { | |
|
jar (doing other things)
2012/03/21 18:19:55
IMO: It is much better to use classes, and accesso
Ilya Sherman
2012/03/21 19:23:02
Hmm. If these were to be classes, they would need
| |
| 70 // The default constructor is exposed to support the IPC serialization macros. | |
| 71 SerializedLocation(); | |
| 72 explicit SerializedLocation(const tracked_objects::Location& location); | |
| 73 ~SerializedLocation(); | |
| 74 | |
| 75 std::string file_name; | |
| 76 std::string function_name; | |
| 77 int line_number; | |
| 78 }; | |
| 79 | |
| 75 BASE_EXPORT const void* GetProgramCounter(); | 80 BASE_EXPORT const void* GetProgramCounter(); |
| 76 | 81 |
| 77 // Define a macro to record the current source location. | 82 // Define a macro to record the current source location. |
| 78 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) | 83 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) |
| 79 | 84 |
| 80 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \ | 85 #define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \ |
| 81 ::tracked_objects::Location(function_name, \ | 86 ::tracked_objects::Location(function_name, \ |
| 82 __FILE__, \ | 87 __FILE__, \ |
| 83 __LINE__, \ | 88 __LINE__, \ |
| 84 ::tracked_objects::GetProgramCounter()) | 89 ::tracked_objects::GetProgramCounter()) |
| 85 | 90 |
| 86 } // namespace tracked_objects | 91 } // namespace tracked_objects |
| 87 | 92 |
| 88 #endif // BASE_LOCATION_H_ | 93 #endif // BASE_LOCATION_H_ |
| OLD | NEW |