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/files/file_util.h" | 7 #include "base/files/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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 TEST_F(FileManagerFileWatcherTest, WatchLocalFile) { | 109 TEST_F(FileManagerFileWatcherTest, WatchLocalFile) { |
110 const base::FilePath kVirtualPath = | 110 const base::FilePath kVirtualPath = |
111 base::FilePath::FromUTF8Unsafe("foo/bar.txt"); | 111 base::FilePath::FromUTF8Unsafe("foo/bar.txt"); |
112 const char kExtensionId[] = "extension-id"; | 112 const char kExtensionId[] = "extension-id"; |
113 | 113 |
114 // Create a temporary directory. | 114 // Create a temporary directory. |
115 base::ScopedTempDir temp_dir; | 115 base::ScopedTempDir temp_dir; |
116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
117 | 117 |
118 // See the comment at the end of this function for why scoped_ptr is used. | 118 // See the comment at the end of this function for why scoped_ptr is used. |
119 scoped_ptr<FileWatcher> file_watcher( | 119 std::unique_ptr<FileWatcher> file_watcher(new FileWatcher(kVirtualPath)); |
120 new FileWatcher(kVirtualPath)); | |
121 file_watcher->AddExtension(kExtensionId); | 120 file_watcher->AddExtension(kExtensionId); |
122 | 121 |
123 // Start watching changes in the temporary directory. | 122 // Start watching changes in the temporary directory. |
124 base::FilePath changed_path; | 123 base::FilePath changed_path; |
125 bool watcher_created = false; | 124 bool watcher_created = false; |
126 bool on_change_error = false; | 125 bool on_change_error = false; |
127 base::RunLoop run_loop; | 126 base::RunLoop run_loop; |
128 file_watcher->WatchLocalFile( | 127 file_watcher->WatchLocalFile( |
129 temp_dir.path(), | 128 temp_dir.path(), |
130 CreateQuitCallback( | 129 CreateQuitCallback( |
(...skipping 16 matching lines...) Expand all Loading... |
147 // This is ugly, but FileWatcher should be deleted explicitly here, and | 146 // This is ugly, but FileWatcher should be deleted explicitly here, and |
148 // spin the message loop so the base::FilePathWatcher is deleted. | 147 // spin the message loop so the base::FilePathWatcher is deleted. |
149 // Otherwise, base::FilePathWatcher may detect a change when the temporary | 148 // Otherwise, base::FilePathWatcher may detect a change when the temporary |
150 // directory is deleted, which may result in crash. | 149 // directory is deleted, which may result in crash. |
151 file_watcher.reset(); | 150 file_watcher.reset(); |
152 base::RunLoop().RunUntilIdle(); | 151 base::RunLoop().RunUntilIdle(); |
153 } | 152 } |
154 | 153 |
155 } // namespace | 154 } // namespace |
156 } // namespace file_manager. | 155 } // namespace file_manager. |
OLD | NEW |