Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: base/at_exit.h

Issue 10582012: For unit tests, track additions to AtExitManager and warn. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cause an error; for trybot run. Ignore. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/test/test_suite.h » ('j') | base/test/test_suite.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_AT_EXIT_H_ 5 #ifndef BASE_AT_EXIT_H_
6 #define BASE_AT_EXIT_H_ 6 #define BASE_AT_EXIT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <stack> 9 #include <stack>
10 10
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 15
16 namespace base { 16 namespace base {
17 17
18 class TestWatchAtExitManager;
19
18 // This class provides a facility similar to the CRT atexit(), except that 20 // This class provides a facility similar to the CRT atexit(), except that
19 // we control when the callbacks are executed. Under Windows for a DLL they 21 // we control when the callbacks are executed. Under Windows for a DLL they
20 // happen at a really bad time and under the loader lock. This facility is 22 // happen at a really bad time and under the loader lock. This facility is
21 // mostly used by base::Singleton. 23 // mostly used by base::Singleton.
22 // 24 //
23 // The usage is simple. Early in the main() or WinMain() scope create an 25 // The usage is simple. Early in the main() or WinMain() scope create an
24 // AtExitManager object on the stack: 26 // AtExitManager object on the stack:
25 // int main(...) { 27 // int main(...) {
26 // base::AtExitManager exit_manager; 28 // base::AtExitManager exit_manager;
27 // 29 //
(...skipping 23 matching lines...) Expand all
51 static void ProcessCallbacksNow(); 53 static void ProcessCallbacksNow();
52 54
53 protected: 55 protected:
54 // This constructor will allow this instance of AtExitManager to be created 56 // This constructor will allow this instance of AtExitManager to be created
55 // even if one already exists. This should only be used for testing! 57 // even if one already exists. This should only be used for testing!
56 // AtExitManagers are kept on a global stack, and it will be removed during 58 // AtExitManagers are kept on a global stack, and it will be removed during
57 // destruction. This allows you to shadow another AtExitManager. 59 // destruction. This allows you to shadow another AtExitManager.
58 explicit AtExitManager(bool shadow); 60 explicit AtExitManager(bool shadow);
59 61
60 private: 62 private:
63 friend class TestWatchAtExitManager;
64
61 base::Lock lock_; 65 base::Lock lock_;
62 std::stack<base::Closure> stack_; 66 std::stack<base::Closure> stack_;
63 AtExitManager* next_manager_; // Stack of managers to allow shadowing. 67 AtExitManager* next_manager_; // Stack of managers to allow shadowing.
64 68
65 DISALLOW_COPY_AND_ASSIGN(AtExitManager); 69 DISALLOW_COPY_AND_ASSIGN(AtExitManager);
66 }; 70 };
67 71
68 #if defined(UNIT_TEST) 72 #if defined(UNIT_TEST)
69 class ShadowingAtExitManager : public AtExitManager { 73 class ShadowingAtExitManager : public AtExitManager {
70 public: 74 public:
71 ShadowingAtExitManager() : AtExitManager(true) {} 75 ShadowingAtExitManager() : AtExitManager(true) {}
72 }; 76 };
73 #endif // defined(UNIT_TEST) 77 #endif // defined(UNIT_TEST)
74 78
75 } // namespace base 79 } // namespace base
76 80
77 #endif // BASE_AT_EXIT_H_ 81 #endif // BASE_AT_EXIT_H_
OLDNEW
« no previous file with comments | « no previous file | base/test/test_suite.h » ('j') | base/test/test_suite.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698