diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-06 19:14:48 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-06 19:14:48 +0000 |
commit | eab79c381d2ab62637d2e3b4008334b743117acf (patch) | |
tree | 601e6c0795be3c96e52de179c796b762bff9b539 /base | |
parent | 8007ad499fb26b50b51fab300c7aa2f3900bf8ea (diff) | |
download | chromium_src-eab79c381d2ab62637d2e3b4008334b743117acf.zip chromium_src-eab79c381d2ab62637d2e3b4008334b743117acf.tar.gz chromium_src-eab79c381d2ab62637d2e3b4008334b743117acf.tar.bz2 |
Minor cleanup: Make method private that is only used for testing
r=rtenneti
Review URL: http://codereview.chromium.org/8484003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108817 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/tracked_objects.h | 35 | ||||
-rw-r--r-- | base/tracked_objects_unittest.cc | 9 |
2 files changed, 27 insertions, 17 deletions
diff --git a/base/tracked_objects.h b/base/tracked_objects.h index f66e761..e64c4fa 100644 --- a/base/tracked_objects.h +++ b/base/tracked_objects.h @@ -157,12 +157,13 @@ // // TODO(jar): I need to store DataCollections, and provide facilities for taking // the difference between two gathered DataCollections. For now, I'm just -// adding a hack that Reset()'s to zero all counts and stats. This is also +// adding a hack that Reset()s to zero all counts and stats. This is also // done in a slighly thread-unsafe fashion, as the reseting is done -// asynchronously relative to ongoing updates, and worse yet, some data fields -// are 64bit quantities, and are not atomicly accessed (reset or incremented -// etc.). For basic profiling, this will work "most of the time," and should be +// asynchronously relative to ongoing updates (but all data is 32 bit in size). +// For basic profiling, this will work "most of the time," and should be // sufficient... but storing away DataCollections is the "right way" to do this. +// We'll accomplish this via JavaScript storage of snapshots, and then we'll +// remove the Reset() methods. class MessageLoop; @@ -667,18 +668,11 @@ class BASE_EXPORT ThreadData { // the code). static TrackedTime Now(); - // Cleans up data structures, and returns statics to near pristine (mostly - // uninitialized) state. If there is any chance that other threads are still - // using the data structures, then the |leak| argument should be passed in as - // true, and the data structures (birth maps, death maps, ThreadData - // insntances, etc.) will be leaked and not deleted. If you have joined all - // threads since the time that InitializeAndSetTrackingStatus() was called, - // then you can pass in a |leak| value of false, and this function will - // delete recursively all data structures, starting with the list of - // ThreadData instances. - static void ShutdownSingleThreadedCleanup(bool leak); - private: + // Allow only tests to call ShutdownSingleThreadedCleanup. We NEVER call it + // in production code. + friend class TrackedObjectsTest; + typedef std::stack<const ThreadData*> ThreadDataPool; // Worker thread construction creates a name since there is none. @@ -712,6 +706,17 @@ class BASE_EXPORT ThreadData { // can save all the thread data into a cache of reusable ThreadData instances. void OnThreadTerminationCleanup() const; + // Cleans up data structures, and returns statics to near pristine (mostly + // uninitialized) state. If there is any chance that other threads are still + // using the data structures, then the |leak| argument should be passed in as + // true, and the data structures (birth maps, death maps, ThreadData + // insntances, etc.) will be leaked and not deleted. If you have joined all + // threads since the time that InitializeAndSetTrackingStatus() was called, + // then you can pass in a |leak| value of false, and this function will + // delete recursively all data structures, starting with the list of + // ThreadData instances. + static void ShutdownSingleThreadedCleanup(bool leak); + // We use thread local store to identify which ThreadData to interact with. static base::ThreadLocalStorage::Slot tls_index_; diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc index 482e318..de7451a 100644 --- a/base/tracked_objects_unittest.cc +++ b/base/tracked_objects_unittest.cc @@ -14,7 +14,7 @@ namespace tracked_objects { class TrackedObjectsTest : public testing::Test { - public: + protected: TrackedObjectsTest() { // On entry, leak any database structures in case they are still in use by // prior threads. @@ -26,6 +26,11 @@ class TrackedObjectsTest : public testing::Test { // single threaded, and carefully accounting for items. ThreadData::ShutdownSingleThreadedCleanup(false); } + + // Provide access, since this class is a friend of ThreadData. + void ShutdownSingleThreadedCleanup(bool leak) { + ThreadData::ShutdownSingleThreadedCleanup(leak); + } }; TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { @@ -46,7 +51,7 @@ TEST_F(TrackedObjectsTest, MinimalStartupShutdown) { data->SnapshotDeathMap(&death_map); EXPECT_EQ(0u, death_map.size()); // Cleanup with no leaking. - ThreadData::ShutdownSingleThreadedCleanup(false); + ShutdownSingleThreadedCleanup(false); // Do it again, just to be sure we reset state completely. ThreadData::InitializeAndSetTrackingStatus(true); |