diff options
-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 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/debugger/devtools_manager.cc | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host.cc | 10 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_database_bloom.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_timed_stop.cc | 10 | ||||
-rw-r--r-- | chrome/plugin/plugin_channel_base.cc | 17 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 1 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.h | 5 | ||||
-rw-r--r-- | ipc/ipc_channel_win.cc | 6 | ||||
-rw-r--r-- | views/focus/focus_util_win.cc | 4 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 4 |
16 files changed, 74 insertions, 72 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_ diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc index d30a8af..68fb78f 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc @@ -14,6 +14,7 @@ #include "app/os_exchange_data.h" #include "app/os_exchange_data_provider_win.h" #include "app/win_util.h" +#include "base/auto_reset.h" #include "base/base_drag_source.h" #include "base/base_drop_target.h" #include "base/basictypes.h" @@ -2335,7 +2336,7 @@ void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); DWORD dropped_mode; - in_drag_ = true; + AutoReset auto_reset_in_drag(&in_drag_, true); if (DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source, supported_modes, &dropped_mode) == DRAGDROP_S_DROP) { if ((dropped_mode == DROPEFFECT_MOVE) && (start_text == GetText())) { @@ -2373,7 +2374,6 @@ void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) { (GetKeyState(VK_RBUTTON) != 0))); } - in_drag_ = false; initiated_drag_ = true; tracking_click_ = false; } diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc index 364a2cd..b8fb65d 100644 --- a/chrome/browser/debugger/devtools_manager.cc +++ b/chrome/browser/debugger/devtools_manager.cc @@ -6,6 +6,7 @@ #include <vector> +#include "base/auto_reset.h" #include "base/message_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browsing_instance.h" @@ -362,9 +363,8 @@ void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh, // If window is docked and visible, we hide it on toggle. If window is // undocked, we show (activate) it. if (!window->is_docked() || do_open) { - in_initial_show_ = true; + AutoReset auto_reset_in_initial_show(&in_initial_show_, true); window->Show(open_console); - in_initial_show_ = false; } else { CloseWindow(host); } diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index 7739e9f..1f71cae 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -4,9 +4,10 @@ #include "chrome/browser/renderer_host/render_widget_host.h" +#include "base/auto_reset.h" #include "base/histogram.h" -#include "base/message_loop.h" #include "base/keyboard_codes.h" +#include "base/message_loop.h" #include "chrome/browser/renderer_host/backing_store.h" #include "chrome/browser/renderer_host/backing_store_manager.h" #include "chrome/browser/renderer_host/render_process_host.h" @@ -281,15 +282,13 @@ BackingStore* RenderWidgetHost::GetBackingStore(bool force_create) { // We should never be called recursively; this can theoretically lead to // infinite recursion and almost certainly leads to lower performance. DCHECK(!in_get_backing_store_) << "GetBackingStore called recursively!"; - in_get_backing_store_ = true; + AutoReset auto_reset_in_get_backing_store(&in_get_backing_store_, true); // We might have a cached backing store that we can reuse! BackingStore* backing_store = BackingStoreManager::GetBackingStore(this, current_size_); - if (!force_create) { - in_get_backing_store_ = false; + if (!force_create) return backing_store; - } // If we fail to find a backing store in the cache, send out a request // to the renderer to paint the view if required. @@ -313,7 +312,6 @@ BackingStore* RenderWidgetHost::GetBackingStore(bool force_create) { } } - in_get_backing_store_ = false; return backing_store; } diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc index 650f556..51946eb 100644 --- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc +++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc @@ -4,13 +4,13 @@ #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h" +#include "base/auto_reset.h" #include "base/compiler_specific.h" #include "base/file_util.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/platform_thread.h" #include "base/process_util.h" -#include "base/scoped_bool.h" #include "base/sha2.h" #include "base/stats_counters.h" #include "base/string_util.h" @@ -195,7 +195,7 @@ bool SafeBrowsingDatabaseBloom::ResetDatabase() { if (performing_reset_) return false; // Don't recurse. - ScopedBool preforming_reset_scope_(&performing_reset_); + AutoReset auto_reset_performing_reset(&performing_reset_, true); // Delete files on disk. bool rv = Close(); diff --git a/chrome/browser/sync/engine/syncer_thread_timed_stop.cc b/chrome/browser/sync/engine/syncer_thread_timed_stop.cc index 4bc9916..12f553b 100644 --- a/chrome/browser/sync/engine/syncer_thread_timed_stop.cc +++ b/chrome/browser/sync/engine/syncer_thread_timed_stop.cc @@ -15,6 +15,7 @@ #include <map> #include <queue> +#include "base/auto_reset.h" #include "chrome/browser/sync/engine/auth_watcher.h" #include "chrome/browser/sync/engine/model_safe_worker.h" #include "chrome/browser/sync/engine/net/server_connection_manager.h" @@ -108,10 +109,11 @@ void SyncerThreadTimedStop::ThreadMain() { // The only thing that could be waiting on this value is Stop, and we don't // release the lock until we're far enough along to Stop safely. - in_thread_main_loop_ = true; - vault_field_changed_.Broadcast(); - ThreadMainLoop(); - in_thread_main_loop_ = false; + { + AutoReset auto_reset_in_thread_main_loop(&in_thread_main_loop_, true); + vault_field_changed_.Broadcast(); + ThreadMainLoop(); + } vault_field_changed_.Broadcast(); LOG(INFO) << "Syncer thread ThreadMain is done."; } diff --git a/chrome/plugin/plugin_channel_base.cc b/chrome/plugin/plugin_channel_base.cc index 7da4560..026b9e5 100644 --- a/chrome/plugin/plugin_channel_base.cc +++ b/chrome/plugin/plugin_channel_base.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. @@ -6,6 +6,7 @@ #include <stack> +#include "base/auto_reset.h" #include "base/hash_tables.h" #include "base/lazy_instance.h" #include "chrome/common/child_process.h" @@ -186,17 +187,15 @@ void PluginChannelBase::RemoveRoute(int route_id) { DCHECK(plugin_count_ >= 0); if (!plugin_count_) { - ListenerMap::iterator npobj_iter = npobject_listeners_.begin(); - in_remove_route_ = true; - while (npobj_iter != npobject_listeners_.end()) { + AutoReset auto_reset_in_remove_route(&in_remove_route_, true); + for (ListenerMap::iterator npobj_iter = npobject_listeners_.begin(); + npobj_iter != npobject_listeners_.end(); ++npobj_iter) { if (npobj_iter->second) npobj_iter->second->OnChannelError(); - npobj_iter++; } - in_remove_route_ = false; - PluginChannelMap::iterator iter = g_plugin_channels_.begin(); - while (iter != g_plugin_channels_.end()) { + for (PluginChannelMap::iterator iter = g_plugin_channels_.begin(); + iter != g_plugin_channels_.end(); ++iter) { if (iter->second == this) { #if defined(OS_POSIX) if (channel_valid()) { @@ -206,8 +205,6 @@ void PluginChannelBase::RemoveRoute(int route_id) { g_plugin_channels_.erase(iter); return; } - - iter++; } NOTREACHED(); diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index 5800f92..6b08887 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -260,7 +260,6 @@ Channel::ChannelImpl::ChannelImpl(const std::string& channel_id, Mode mode, #endif listener_(listener), waiting_connect_(true), - processing_incoming_(false), factory_(this) { if (!CreatePipe(channel_id, mode)) { // The pipe may have been closed already. diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h index 2a8bc71..714b150 100644 --- a/ipc/ipc_channel_posix.h +++ b/ipc/ipc_channel_posix.h @@ -126,11 +126,6 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher { // the connect operation in overlapped mode. bool waiting_connect_; - // This flag is set when processing incoming messages. It is used to - // avoid recursing through ProcessIncomingMessages, which could cause - // problems. TODO(darin): make this unnecessary - bool processing_incoming_; - ScopedRunnableMethodFactory<ChannelImpl> factory_; DISALLOW_COPY_AND_ASSIGN(ChannelImpl); diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc index 6a03950..701bce8 100644 --- a/ipc/ipc_channel_win.cc +++ b/ipc/ipc_channel_win.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. @@ -7,6 +7,7 @@ #include <windows.h> #include <sstream> +#include "base/auto_reset.h" #include "base/compiler_specific.h" #include "base/logging.h" #include "base/non_thread_safe.h" @@ -391,9 +392,8 @@ void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context, } // we don't support recursion through OnMessageReceived yet! DCHECK(!processing_incoming_); - processing_incoming_ = true; + AutoReset auto_reset_processing_incoming(&processing_incoming_, true); ok = ProcessIncomingMessages(context, bytes_transfered); - processing_incoming_ = false; } else { DCHECK(context == &output_state_.context); ok = ProcessOutgoingMessages(context, bytes_transfered); diff --git a/views/focus/focus_util_win.cc b/views/focus/focus_util_win.cc index 046df70..2490528 100644 --- a/views/focus/focus_util_win.cc +++ b/views/focus/focus_util_win.cc @@ -6,6 +6,7 @@ #include <windowsx.h> +#include "base/auto_reset.h" #include "base/win_util.h" namespace views { @@ -102,9 +103,8 @@ bool RerouteMouseWheel(HWND window, WPARAM w_param, LPARAM l_param) { // window_under_wheel is a Chrome window. If allowed, redirect. if (IsCompatibleWithMouseWheelRedirection(window_under_wheel)) { - recursion_break = true; + AutoReset auto_reset_recursion_break(&recursion_break, true); SendMessage(window_under_wheel, WM_MOUSEWHEEL, w_param, l_param); - recursion_break = false; return true; } // If redirection is disallowed, try the parent. diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 87fdb8d..26e8ddf 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -8,6 +8,7 @@ #include "app/gfx/path.h" #include "app/os_exchange_data.h" #include "app/os_exchange_data_provider_gtk.h" +#include "base/auto_reset.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "base/string_util.h" @@ -464,9 +465,8 @@ void WidgetGtk::PaintNow(const gfx::Rect& update_rect) { gtk_widget_queue_draw_area(widget_, update_rect.x(), update_rect.y(), update_rect.width(), update_rect.height()); // Force the paint to occur now. - in_paint_now_ = true; + AutoReset auto_reset_in_paint_now(&in_paint_now_, true); gdk_window_process_updates(widget_->window, true); - in_paint_now_ = false; } } |