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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_watcher_unittest.cc

Issue 2345473002: Change ScopedTempDir::path() to GetPath() in chrome/browser/chromeos/file_manager (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::unique_ptr<FileWatcher> file_watcher(new FileWatcher(kVirtualPath)); 119 std::unique_ptr<FileWatcher> file_watcher(new FileWatcher(kVirtualPath));
120 file_watcher->AddExtension(kExtensionId); 120 file_watcher->AddExtension(kExtensionId);
121 121
122 // Start watching changes in the temporary directory. 122 // Start watching changes in the temporary directory.
123 base::FilePath changed_path; 123 base::FilePath changed_path;
124 bool watcher_created = false; 124 bool watcher_created = false;
125 bool on_change_error = false; 125 bool on_change_error = false;
126 base::RunLoop run_loop; 126 base::RunLoop run_loop;
127 file_watcher->WatchLocalFile( 127 file_watcher->WatchLocalFile(
128 temp_dir.path(), 128 temp_dir.GetPath(),
129 CreateQuitCallback( 129 CreateQuitCallback(
130 &run_loop, 130 &run_loop, CreateCopyResultCallback(&changed_path, &on_change_error)),
131 CreateCopyResultCallback(&changed_path, &on_change_error)),
132 CreateCopyResultCallback(&watcher_created)); 131 CreateCopyResultCallback(&watcher_created));
133 // Spin the message loop so the base::FilePathWatcher is created. 132 // Spin the message loop so the base::FilePathWatcher is created.
134 base::RunLoop().RunUntilIdle(); 133 base::RunLoop().RunUntilIdle();
135 ASSERT_TRUE(watcher_created); 134 ASSERT_TRUE(watcher_created);
136 135
137 // Create a temporary file in the temporary directory. The file watcher 136 // Create a temporary file in the temporary directory. The file watcher
138 // should detect the change in the directory. 137 // should detect the change in the directory.
139 base::FilePath temp_file_path; 138 base::FilePath temp_file_path;
140 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path)); 139 ASSERT_TRUE(
140 base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file_path));
141 // Wait until the directory change is notified. 141 // Wait until the directory change is notified.
142 run_loop.Run(); 142 run_loop.Run();
143 ASSERT_FALSE(on_change_error); 143 ASSERT_FALSE(on_change_error);
144 ASSERT_EQ(temp_dir.path().value(), changed_path.value()); 144 ASSERT_EQ(temp_dir.GetPath().value(), changed_path.value());
145 145
146 // This is ugly, but FileWatcher should be deleted explicitly here, and 146 // This is ugly, but FileWatcher should be deleted explicitly here, and
147 // spin the message loop so the base::FilePathWatcher is deleted. 147 // spin the message loop so the base::FilePathWatcher is deleted.
148 // Otherwise, base::FilePathWatcher may detect a change when the temporary 148 // Otherwise, base::FilePathWatcher may detect a change when the temporary
149 // directory is deleted, which may result in crash. 149 // directory is deleted, which may result in crash.
150 file_watcher.reset(); 150 file_watcher.reset();
151 base::RunLoop().RunUntilIdle(); 151 base::RunLoop().RunUntilIdle();
152 } 152 }
153 153
154 } // namespace 154 } // namespace
155 } // namespace file_manager. 155 } // namespace file_manager.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698