summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/auto_reset.h25
-rw-r--r--base/message_pump_libevent.cc2
-rw-r--r--chrome/browser/app_controller_mac.mm4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc4
-rw-r--r--chrome/browser/debugger/devtools_manager.cc2
-rw-r--r--chrome/browser/gtk/task_manager_gtk.cc6
-rw-r--r--chrome/browser/renderer_host/render_widget_host.cc2
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/common/web_database_observer_impl.cc2
-rw-r--r--chrome/plugin/plugin_channel_base.cc2
-rw-r--r--ipc/ipc_channel_win.cc2
-rw-r--r--views/focus/focus_util_win.cc2
-rw-r--r--views/widget/widget_gtk.cc2
-rw-r--r--webkit/appcache/appcache_database.cc2
-rw-r--r--webkit/tools/test_shell/simple_database_system.cc2
16 files changed, 33 insertions, 30 deletions
diff --git a/base/auto_reset.h b/base/auto_reset.h
index dd968ef..3925abe 100644
--- a/base/auto_reset.h
+++ b/base/auto_reset.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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,27 +7,30 @@
#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.
+// AutoResetValue 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.
+// This should be obvious, but note that the AutoResetValue instance
+// should have a shorter lifetime than the scoped_variable, to prevent
+// writing to invalid memory when the AutoResetValue goes out of
+// scope.
+template<typename T>
class AutoReset {
public:
- explicit AutoReset(bool* scoped_variable, bool new_value)
+ AutoReset(T* scoped_variable, T 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_;
+ T* scoped_variable_;
+ T original_value_;
DISALLOW_COPY_AND_ASSIGN(AutoReset);
};
diff --git a/base/message_pump_libevent.cc b/base/message_pump_libevent.cc
index 01ebee5..2ad1d97 100644
--- a/base/message_pump_libevent.cc
+++ b/base/message_pump_libevent.cc
@@ -229,7 +229,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!";
- AutoReset auto_reset_in_run(&in_run_, true);
+ AutoReset<bool> 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().
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 1cd02e7..57f8ee8 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -84,7 +84,7 @@ Browser* ActivateBrowser(Profile* profile) {
// to the new |Browser|.
Browser* CreateBrowser(Profile* profile) {
{
- AutoReset auto_reset_in_run(&g_is_opening_new_window, true);
+ AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
Browser::OpenEmptyWindow(profile);
}
@@ -804,7 +804,7 @@ void RecordLastRunAppBundlePath() {
// Otherwise open a new window.
{
- AutoReset auto_reset_in_run(&g_is_opening_new_window, true);
+ AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
Browser::OpenEmptyWindow([self defaultProfile]);
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 6a17f80..38bc75e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -1693,7 +1693,7 @@ LRESULT AutocompleteEditViewWin::OnSetText(const wchar_t* text) {
// We wouldn't need to do this update anyway, because either we're in the
// middle of updating the omnibox already or the caller of SetWindowText()
// is going to update the omnibox next.
- AutoReset auto_reset_ignore_ime_messages(&ignore_ime_messages_, true);
+ AutoReset<bool> auto_reset_ignore_ime_messages(&ignore_ime_messages_, true);
return DefWindowProc(WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
}
@@ -2336,7 +2336,7 @@ void AutocompleteEditViewWin::StartDragIfNecessary(const CPoint& point) {
scoped_refptr<BaseDragSource> drag_source(new BaseDragSource);
DWORD dropped_mode;
- AutoReset auto_reset_in_drag(&in_drag_, true);
+ AutoReset<bool> 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())) {
diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc
index 57db6c3..ff7f267 100644
--- a/chrome/browser/debugger/devtools_manager.cc
+++ b/chrome/browser/debugger/devtools_manager.cc
@@ -363,7 +363,7 @@ 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) {
- AutoReset auto_reset_in_initial_show(&in_initial_show_, true);
+ AutoReset<bool> auto_reset_in_initial_show(&in_initial_show_, true);
window->Show(open_console);
} else
UnregisterDevToolsClientHostFor(inspected_rvh);
diff --git a/chrome/browser/gtk/task_manager_gtk.cc b/chrome/browser/gtk/task_manager_gtk.cc
index aa8577b..93ed4ca 100644
--- a/chrome/browser/gtk/task_manager_gtk.cc
+++ b/chrome/browser/gtk/task_manager_gtk.cc
@@ -316,7 +316,7 @@ void TaskManagerGtk::OnItemsChanged(int start, int length) {
}
void TaskManagerGtk::OnItemsAdded(int start, int length) {
- AutoReset autoreset(&ignore_selection_changed_, true);
+ AutoReset<bool> autoreset(&ignore_selection_changed_, true);
GtkTreeIter iter;
if (start == 0) {
@@ -342,7 +342,7 @@ void TaskManagerGtk::OnItemsAdded(int start, int length) {
void TaskManagerGtk::OnItemsRemoved(int start, int length) {
{
- AutoReset autoreset(&ignore_selection_changed_, true);
+ AutoReset<bool> autoreset(&ignore_selection_changed_, true);
GtkTreeIter iter;
gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(process_list_), &iter,
@@ -848,7 +848,7 @@ void TaskManagerGtk::OnTreeViewRealize(GtkTreeView* treeview,
void TaskManagerGtk::OnSelectionChanged(GtkTreeSelection* selection) {
if (ignore_selection_changed_)
return;
- AutoReset autoreset(&ignore_selection_changed_, true);
+ AutoReset<bool> autoreset(&ignore_selection_changed_, true);
// The set of groups that should be selected.
std::set<std::pair<int, int> > ranges;
diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc
index c55f043..673a237 100644
--- a/chrome/browser/renderer_host/render_widget_host.cc
+++ b/chrome/browser/renderer_host/render_widget_host.cc
@@ -312,7 +312,7 @@ 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!";
- AutoReset auto_reset_in_get_backing_store(&in_get_backing_store_, true);
+ AutoReset<bool> 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 =
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
index 8acda7c..802bbd2 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
@@ -63,7 +63,7 @@ bool SafeBrowsingDatabaseBloom::ResetDatabase() {
if (performing_reset_)
return false; // Don't recurse.
- AutoReset auto_reset_performing_reset(&performing_reset_, true);
+ AutoReset<bool> auto_reset_performing_reset(&performing_reset_, true);
// Delete files on disk.
bool rv = Close();
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 1599737..8e2fff5 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1584,7 +1584,7 @@ void TabContents::DidNavigateMainFramePostCommit(
// Close blocked popups.
if (blocked_popups_) {
- AutoReset auto_reset(&dont_notify_render_view_, true);
+ AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
blocked_popups_->Destroy();
blocked_popups_ = NULL;
}
diff --git a/chrome/common/web_database_observer_impl.cc b/chrome/common/web_database_observer_impl.cc
index 32d358c..8c008e4 100644
--- a/chrome/common/web_database_observer_impl.cc
+++ b/chrome/common/web_database_observer_impl.cc
@@ -45,7 +45,7 @@ void WebDatabaseObserverImpl::databaseClosed(
void WebDatabaseObserverImpl::WaitForAllDatabasesToClose() {
if (!database_connections_.IsEmpty()) {
- AutoReset waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true);
+ AutoReset<bool> waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true);
MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current());
MessageLoop::current()->Run();
}
diff --git a/chrome/plugin/plugin_channel_base.cc b/chrome/plugin/plugin_channel_base.cc
index 712c697..5d18654 100644
--- a/chrome/plugin/plugin_channel_base.cc
+++ b/chrome/plugin/plugin_channel_base.cc
@@ -197,7 +197,7 @@ void PluginChannelBase::RemoveRoute(int route_id) {
DCHECK(plugin_count_ >= 0);
if (!plugin_count_) {
- AutoReset auto_reset_in_remove_route(&in_remove_route_, true);
+ AutoReset<bool> 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) {
diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc
index 701bce8..ba1df9f 100644
--- a/ipc/ipc_channel_win.cc
+++ b/ipc/ipc_channel_win.cc
@@ -392,7 +392,7 @@ void Channel::ChannelImpl::OnIOCompleted(MessageLoopForIO::IOContext* context,
}
// we don't support recursion through OnMessageReceived yet!
DCHECK(!processing_incoming_);
- AutoReset auto_reset_processing_incoming(&processing_incoming_, true);
+ AutoReset<bool> auto_reset_processing_incoming(&processing_incoming_, true);
ok = ProcessIncomingMessages(context, bytes_transfered);
} else {
DCHECK(context == &output_state_.context);
diff --git a/views/focus/focus_util_win.cc b/views/focus/focus_util_win.cc
index 2490528..381d02b 100644
--- a/views/focus/focus_util_win.cc
+++ b/views/focus/focus_util_win.cc
@@ -103,7 +103,7 @@ 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)) {
- AutoReset auto_reset_recursion_break(&recursion_break, true);
+ AutoReset<bool> auto_reset_recursion_break(&recursion_break, true);
SendMessage(window_under_wheel, WM_MOUSEWHEEL, w_param, l_param);
return true;
}
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 1014af7..b166fce 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -721,7 +721,7 @@ 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.
- AutoReset auto_reset_in_paint_now(&in_paint_now_, true);
+ AutoReset<bool> auto_reset_in_paint_now(&in_paint_now_, true);
gdk_window_process_updates(widget_->window, true);
}
}
diff --git a/webkit/appcache/appcache_database.cc b/webkit/appcache/appcache_database.cc
index 42af3dbc..d7210c4 100644
--- a/webkit/appcache/appcache_database.cc
+++ b/webkit/appcache/appcache_database.cc
@@ -1122,7 +1122,7 @@ bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() {
if (is_recreating_)
return false;
- AutoReset auto_reset(&is_recreating_, true);
+ AutoReset<bool> auto_reset(&is_recreating_, true);
return LazyOpen(true);
}
diff --git a/webkit/tools/test_shell/simple_database_system.cc b/webkit/tools/test_shell/simple_database_system.cc
index 8f87dc2..a0645f5 100644
--- a/webkit/tools/test_shell/simple_database_system.cc
+++ b/webkit/tools/test_shell/simple_database_system.cc
@@ -159,7 +159,7 @@ void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) {
void SimpleDatabaseSystem::ClearAllDatabases() {
// Wait for all databases to be closed.
if (!database_connections_.IsEmpty()) {
- AutoReset waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true);
+ AutoReset<bool> waiting_for_dbs_auto_reset(&waiting_for_dbs_to_close_, true);
MessageLoop::ScopedNestableTaskAllower nestable(MessageLoop::current());
MessageLoop::current()->Run();
}