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

Side by Side Diff: base/files/file_path_watcher_browsertest.cc

Issue 10065037: RefCounted types should not have public destructors, base/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/files/file_path_watcher.h" 5 #include "base/files/file_path_watcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 void Reset() { 59 void Reset() {
60 signaled_.clear(); 60 signaled_.clear();
61 } 61 }
62 62
63 bool Success() { 63 bool Success() {
64 return signaled_ == delegates_; 64 return signaled_ == delegates_;
65 } 65 }
66 66
67 private: 67 private:
68 friend class base::RefCountedThreadSafe<NotificationCollector>;
69 ~NotificationCollector() {}
70
68 void RecordChange(TestDelegate* delegate) { 71 void RecordChange(TestDelegate* delegate) {
69 ASSERT_TRUE(loop_->BelongsToCurrentThread()); 72 ASSERT_TRUE(loop_->BelongsToCurrentThread());
70 ASSERT_TRUE(delegates_.count(delegate)); 73 ASSERT_TRUE(delegates_.count(delegate));
71 signaled_.insert(delegate); 74 signaled_.insert(delegate);
72 75
73 // Check whether all delegates have been signaled. 76 // Check whether all delegates have been signaled.
74 if (signaled_ == delegates_) 77 if (signaled_ == delegates_)
75 loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 78 loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
76 } 79 }
77 80
(...skipping 23 matching lines...) Expand all
101 104
102 virtual void OnFilePathChanged(const FilePath&) { 105 virtual void OnFilePathChanged(const FilePath&) {
103 collector_->OnChange(this); 106 collector_->OnChange(this);
104 } 107 }
105 108
106 virtual void OnFilePathError(const FilePath& path) { 109 virtual void OnFilePathError(const FilePath& path) {
107 ADD_FAILURE() << "Error " << path.value(); 110 ADD_FAILURE() << "Error " << path.value();
108 } 111 }
109 112
110 private: 113 private:
114 virtual ~TestDelegate() {}
115
111 scoped_refptr<NotificationCollector> collector_; 116 scoped_refptr<NotificationCollector> collector_;
112 117
113 DISALLOW_COPY_AND_ASSIGN(TestDelegate); 118 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
114 }; 119 };
115 120
116 void SetupWatchCallback(const FilePath& target, 121 void SetupWatchCallback(const FilePath& target,
117 FilePathWatcher* watcher, 122 FilePathWatcher* watcher,
118 FilePathWatcher::Delegate* delegate, 123 FilePathWatcher::Delegate* delegate,
119 bool* result, 124 bool* result,
120 base::WaitableEvent* completion) { 125 base::WaitableEvent* completion) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 loop_(loop) { 247 loop_(loop) {
243 } 248 }
244 249
245 virtual void OnFilePathChanged(const FilePath& path) { 250 virtual void OnFilePathChanged(const FilePath& path) {
246 watcher_.reset(); 251 watcher_.reset();
247 loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 252 loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure());
248 } 253 }
249 254
250 scoped_ptr<FilePathWatcher> watcher_; 255 scoped_ptr<FilePathWatcher> watcher_;
251 MessageLoop* loop_; 256 MessageLoop* loop_;
257
258 private:
259 virtual ~Deleter() {}
252 }; 260 };
253 261
254 // Verify that deleting a watcher during the callback doesn't crash. 262 // Verify that deleting a watcher during the callback doesn't crash.
255 TEST_F(FilePathWatcherTest, DeleteDuringNotify) { 263 TEST_F(FilePathWatcherTest, DeleteDuringNotify) {
256 FilePathWatcher* watcher = new FilePathWatcher; 264 FilePathWatcher* watcher = new FilePathWatcher;
257 // Takes ownership of watcher. 265 // Takes ownership of watcher.
258 scoped_refptr<Deleter> deleter(new Deleter(watcher, &loop_)); 266 scoped_refptr<Deleter> deleter(new Deleter(watcher, &loop_));
259 ASSERT_TRUE(SetupWatch(test_file(), watcher, deleter.get())); 267 ASSERT_TRUE(SetupWatch(test_file(), watcher, deleter.get()));
260 268
261 ASSERT_TRUE(WriteFile(test_file(), "content")); 269 ASSERT_TRUE(WriteFile(test_file(), "content"));
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false)); 774 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, false));
767 ASSERT_TRUE(WaitForEvents()); 775 ASSERT_TRUE(WaitForEvents());
768 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true)); 776 ASSERT_TRUE(ChangeFilePermissions(test_dir1, Execute, true));
769 } 777 }
770 778
771 #endif // OS_MACOSX 779 #endif // OS_MACOSX
772 } // namespace 780 } // namespace
773 781
774 } // namespace files 782 } // namespace files
775 } // namespace base 783 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698