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

Side by Side Diff: third_party/libphonenumber/cpp/src/base/at_exit.cc

Issue 6803005: Autofill phone number enhancements and integration of Phone Number Util Library: part 1 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/at_exit.h"
6 #include "base/logging.h"
7
8 namespace base {
9
10 // Keep a stack of registered AtExitManagers. We always operate on the most
11 // recent, and we should never have more than one outside of testing, when we
12 // use the shadow version of the constructor. We don't protect this for
13 // thread-safe access, since it will only be modified in testing.
14 static AtExitManager* g_top_manager = NULL;
15
16 AtExitManager::AtExitManager() : next_manager_(NULL) {
17 DCHECK(!g_top_manager);
18 g_top_manager = this;
19 }
20
21 AtExitManager::~AtExitManager() {
22 if (!g_top_manager) {
23 NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager";
24 return;
25 }
26 DCHECK(g_top_manager == this);
27
28 ProcessCallbacksNow();
29 g_top_manager = next_manager_;
30 }
31
32 // static
33 void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) {
34 if (!g_top_manager) {
35 NOTREACHED() << "Tried to RegisterCallback without an AtExitManager";
36 return;
37 }
38
39 DCHECK(func);
40
41 AutoLock lock(g_top_manager->lock_);
42 g_top_manager->stack_.push(CallbackAndParam(func, param));
43 }
44
45 // static
46 void AtExitManager::ProcessCallbacksNow() {
47 if (!g_top_manager) {
48 NOTREACHED() << "Tried to ProcessCallbacksNow without an AtExitManager";
49 return;
50 }
51
52 AutoLock lock(g_top_manager->lock_);
53
54 while (!g_top_manager->stack_.empty()) {
55 CallbackAndParam callback_and_param = g_top_manager->stack_.top();
56 g_top_manager->stack_.pop();
57
58 callback_and_param.func_(callback_and_param.param_);
59 }
60 }
61
62 AtExitManager::AtExitManager(bool shadow) : next_manager_(g_top_manager) {
63 DCHECK(shadow || !g_top_manager);
64 g_top_manager = this;
65 }
66
67 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698