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

Unified Diff: base/files/file_path_watcher_browsertest.cc

Issue 10912017: Fix stack corruption bug in FilePathWatcherTest.Callback. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/policy/async_policy_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_path_watcher_browsertest.cc
diff --git a/base/files/file_path_watcher_browsertest.cc b/base/files/file_path_watcher_browsertest.cc
index 5eea88c5fd7e0ce58fd3aea876098ca3173426b8..57679201fec968beb6dd172f12ac8bb10a971d4d 100644
--- a/base/files/file_path_watcher_browsertest.cc
+++ b/base/files/file_path_watcher_browsertest.cc
@@ -15,6 +15,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -259,7 +260,7 @@ TEST_F(FilePathWatcherTest, DeletedFile) {
}
TEST_F(FilePathWatcherTest, Callback) {
- FilePathWatcher watcher;
+ FilePathWatcher* watcher = new FilePathWatcher();
bool called_back = false;
MessageLoop* file_loop = file_thread_.message_loop();
@@ -273,7 +274,7 @@ TEST_F(FilePathWatcherTest, Callback) {
// has been installed.
file_thread_.message_loop_proxy()->PostTaskAndReply(
FROM_HERE,
- base::Bind(SetupWatchCallback, test_file(), &watcher, callback),
+ base::Bind(SetupWatchCallback, test_file(), watcher, callback),
base::Bind(&MessageLoop::Quit, base::Unretained(&loop_)));
loop_.Run();
@@ -282,6 +283,19 @@ TEST_F(FilePathWatcherTest, Callback) {
ASSERT_TRUE(WriteFile(test_file(), "content"));
loop_.Run();
EXPECT_TRUE(called_back);
+
+ // Multiple events might have triggered, meaning that multiple
+ // QuitLoopWatchCallback have been posted. The FilePathWatcher can only cancel
+ // on the FILE thread, and thus that callback might still trigger after this
+ // function returns. Make sure the |watcher| is deleted before returning and
+ // destroying |called_back|.
+ // A better fix requires significant changes to the FilePathWatcher.
Mattias Nissler (ping if slow) 2012/08/30 19:09:31 TODO + bug.
+ file_thread_.message_loop_proxy()->DeleteSoon(FROM_HERE, watcher);
+ file_thread_.message_loop_proxy()->PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(base::DoNothing),
+ base::Bind(&MessageLoop::Quit, base::Unretained(&loop_)));
+ loop_.Run();
}
// Used by the DeleteDuringNotify test below.
« no previous file with comments | « no previous file | chrome/browser/policy/async_policy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698