OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_manager/file_watcher.h" | 5 #include "chrome/browser/chromeos/file_manager/file_watcher.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 &run_loop, | 131 &run_loop, |
132 CreateCopyResultCallback(&changed_path, &on_change_error)), | 132 CreateCopyResultCallback(&changed_path, &on_change_error)), |
133 CreateCopyResultCallback(&watcher_created)); | 133 CreateCopyResultCallback(&watcher_created)); |
134 // Spin the message loop so the base::FilePathWatcher is created. | 134 // Spin the message loop so the base::FilePathWatcher is created. |
135 base::RunLoop().RunUntilIdle(); | 135 base::RunLoop().RunUntilIdle(); |
136 ASSERT_TRUE(watcher_created); | 136 ASSERT_TRUE(watcher_created); |
137 | 137 |
138 // Create a temporary file in the temporary directory. The file watcher | 138 // Create a temporary file in the temporary directory. The file watcher |
139 // should detect the change in the directory. | 139 // should detect the change in the directory. |
140 base::FilePath temp_file_path; | 140 base::FilePath temp_file_path; |
141 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), | 141 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path)); |
142 &temp_file_path)); | |
143 // Wait until the directory change is notified. | 142 // Wait until the directory change is notified. |
144 run_loop.Run(); | 143 run_loop.Run(); |
145 ASSERT_FALSE(on_change_error); | 144 ASSERT_FALSE(on_change_error); |
146 ASSERT_EQ(temp_dir.path().value(), changed_path.value()); | 145 ASSERT_EQ(temp_dir.path().value(), changed_path.value()); |
147 | 146 |
148 // This is ugly, but FileWatcher should be deleted explicitly here, and | 147 // This is ugly, but FileWatcher should be deleted explicitly here, and |
149 // spin the message loop so the base::FilePathWatcher is deleted. | 148 // spin the message loop so the base::FilePathWatcher is deleted. |
150 // Otherwise, base::FilePathWatcher may detect a change when the temporary | 149 // Otherwise, base::FilePathWatcher may detect a change when the temporary |
151 // directory is deleted, which may result in crash. | 150 // directory is deleted, which may result in crash. |
152 file_watcher.reset(); | 151 file_watcher.reset(); |
153 base::RunLoop().RunUntilIdle(); | 152 base::RunLoop().RunUntilIdle(); |
154 } | 153 } |
155 | 154 |
156 } // namespace | 155 } // namespace |
157 } // namespace file_manager. | 156 } // namespace file_manager. |
OLD | NEW |