diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/auto_reset.h | 35 | ||||
-rw-r--r-- | base/base.gyp | 2 | ||||
-rw-r--r-- | base/message_pump_libevent.cc | 8 | ||||
-rw-r--r-- | base/ref_counted.cc | 8 | ||||
-rw-r--r-- | base/scoped_bool.h | 24 |
5 files changed, 44 insertions, 33 deletions
diff --git a/base/auto_reset.h b/base/auto_reset.h new file mode 100644 index 0000000..dd968ef --- /dev/null +++ b/base/auto_reset.h @@ -0,0 +1,35 @@ +// Copyright (c) 2009 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_AUTO_RESET_H_ +#define BASE_AUTO_RESET_H_ + +#include "base/basictypes.h" + +// AutoReset is useful for setting a variable to some value only during a +// particular scope. If you have code that has to add "var = false;" or +// "var = old_var;" at all the exit points of a block, for example, you would +// benefit from using this instead. +// +// NOTE: Right now this is hardcoded to work on bools, since that covers all the +// cases where we've used it. It would be reasonable to turn it into a template +// class in the future. + +class AutoReset { + public: + explicit AutoReset(bool* scoped_variable, bool new_value) + : scoped_variable_(scoped_variable), + original_value_(*scoped_variable) { + *scoped_variable_ = new_value; + } + ~AutoReset() { *scoped_variable_ = original_value_; } + + private: + bool* scoped_variable_; + bool original_value_; + + DISALLOW_COPY_AND_ASSIGN(AutoReset); +}; + +#endif // BASE_AUTO_RESET_H_ diff --git a/base/base.gyp b/base/base.gyp index ca71829..777dab1 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -69,6 +69,7 @@ 'atomic_sequence_num.h', 'atomicops.h', 'atomicops_internals_x86_msvc.h', + 'auto_reset.h', 'base_drag_source.cc', 'base_drag_source.h', 'base_drop_target.cc', @@ -252,7 +253,6 @@ 'resource_util.h', 'safe_strerror_posix.cc', 'safe_strerror_posix.h', - 'scoped_bool.h', 'scoped_bstr_win.cc', 'scoped_bstr_win.h', 'scoped_cftyperef.h', diff --git a/base/message_pump_libevent.cc b/base/message_pump_libevent.cc index eae77f4..4e2df5f 100644 --- a/base/message_pump_libevent.cc +++ b/base/message_pump_libevent.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -8,6 +8,7 @@ #include <fcntl.h> #include "eintr_wrapper.h" +#include "base/auto_reset.h" #include "base/logging.h" #include "base/scoped_nsautorelease_pool.h" #include "base/scoped_ptr.h" @@ -224,9 +225,7 @@ static void timer_callback(int fd, short events, void *context) // Reentrant! void MessagePumpLibevent::Run(Delegate* delegate) { DCHECK(keep_running_) << "Quit must have been called outside of Run!"; - - bool old_in_run = in_run_; - in_run_ = true; + AutoReset auto_reset_in_run(&in_run_, true); // event_base_loopexit() + EVLOOP_ONCE is leaky, see http://crbug.com/25641. // Instead, make our own timer and reuse it on each call to event_base_loop(). @@ -277,7 +276,6 @@ void MessagePumpLibevent::Run(Delegate* delegate) { } keep_running_ = true; - in_run_ = old_in_run; } void MessagePumpLibevent::Quit() { diff --git a/base/ref_counted.cc b/base/ref_counted.cc index d272567..ae04281 100644 --- a/base/ref_counted.cc +++ b/base/ref_counted.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -11,10 +11,12 @@ namespace base { namespace subtle { -RefCountedBase::RefCountedBase() : ref_count_(0) { +RefCountedBase::RefCountedBase() + : ref_count_(0) #ifndef NDEBUG - in_dtor_ = false; + , in_dtor_(false) #endif + { } RefCountedBase::~RefCountedBase() { diff --git a/base/scoped_bool.h b/base/scoped_bool.h deleted file mode 100644 index 0622f967..0000000 --- a/base/scoped_bool.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2009 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_SCOPED_BOOL_H_ -#define BASE_SCOPED_BOOL_H_ - -// ScopedBool is useful for setting a flag only during a particular scope. If -// you have code that has to add "var = false;" at all the exit points of a -// function, for example, you would benefit from using this instead. - -class ScopedBool { - public: - explicit ScopedBool(bool* scoped_bool) : scoped_bool_(scoped_bool) { - *scoped_bool_ = true; - } - ~ScopedBool() { *scoped_bool_ = false; } - - private: - bool* scoped_bool_; - DISALLOW_COPY_AND_ASSIGN(ScopedBool); -}; - -#endif // BASE_SCOPED_BOOL_H_ |