diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-21 18:05:41 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-21 18:05:41 +0000 |
commit | c62dd9d42bd87964a131adc688d0c70f63cc4cac (patch) | |
tree | b57f3bc0843d2acace088498ecb40e0bfc213b6c /base/location.h | |
parent | b6bb36e2e8c9a09b4fd733bf74b60a6f02a5a7e9 (diff) | |
download | chromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.zip chromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.tar.gz chromium_src-c62dd9d42bd87964a131adc688d0c70f63cc4cac.tar.bz2 |
Delete Tracked, and move Location to its own file.
The Birth/Death tracking of tasks has been moved out-of-band into MessageLoop's PendingTask structure.
Thus, Task no longer needs to inherit from Tracked. Since Task was the only child of Tracked, delete the Tracked class and move Location to its own file.
BUG=none
TEST=builds
Review URL: http://codereview.chromium.org/7879006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102132 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/location.h')
-rw-r--r-- | base/location.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/base/location.h b/base/location.h new file mode 100644 index 0000000..fab8f4f --- /dev/null +++ b/base/location.h @@ -0,0 +1,80 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BASE_LOCATION_H_ +#define BASE_LOCATION_H_ + +#include <string> + +#include "base/base_export.h" + +#ifndef NDEBUG +#ifndef TRACK_ALL_TASK_OBJECTS +#define TRACK_ALL_TASK_OBJECTS +#endif // TRACK_ALL_TASK_OBJECTS +#endif // NDEBUG + +namespace tracked_objects { + +// Location provides basic info where of an object was constructed, or was +// significantly brought to life. +class BASE_EXPORT Location { + public: + // Constructor should be called with a long-lived char*, such as __FILE__. + // It assumes the provided value will persist as a global constant, and it + // will not make a copy of it. + Location(const char* function_name, + const char* file_name, + int line_number, + const void* program_counter); + + // Provide a default constructor for easy of debugging. + Location(); + + // Comparison operator for insertion into a std::map<> hash tables. + // All we need is *some* (any) hashing distinction. Strings should already + // be unique, so we don't bother with strcmp or such. + // Use line number as the primary key (because it is fast, and usually gets us + // a difference), and then pointers as secondary keys (just to get some + // distinctions). + bool operator < (const Location& other) const { + if (line_number_ != other.line_number_) + return line_number_ < other.line_number_; + if (file_name_ != other.file_name_) + return file_name_ < other.file_name_; + return function_name_ < other.function_name_; + } + + const char* function_name() const { return function_name_; } + const char* file_name() const { return file_name_; } + int line_number() const { return line_number_; } + const void* program_counter() const { return program_counter_; } + + std::string ToString() const; + + void Write(bool display_filename, bool display_function_name, + std::string* output) const; + + // Write function_name_ in HTML with '<' and '>' properly encoded. + void WriteFunctionName(std::string* output) const; + + private: + const char* const function_name_; + const char* const file_name_; + const int line_number_; + const void* const program_counter_; +}; + +BASE_EXPORT const void* GetProgramCounter(); + +// Define a macro to record the current source location. +#define FROM_HERE tracked_objects::Location( \ + __FUNCTION__, \ + __FILE__, \ + __LINE__, \ + tracked_objects::GetProgramCounter()) \ + +} // namespace tracked_objects + +#endif // BASE_LOCATION_H_ |