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

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

Issue 2966713002: file_manager: Migrate FILE thread to TaskScheduler (Closed)
Patch Set: fix unit test Created 3 years, 5 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/bind.h" 7 #include "base/bind.h"
8 #include "base/task_runner_util.h"
9 #include "base/task_scheduler/post_task.h"
8 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
9 #include "google_apis/drive/task_util.h" 11 #include "google_apis/drive/task_util.h"
10 12
11 using content::BrowserThread; 13 using content::BrowserThread;
12 14
13 namespace file_manager { 15 namespace file_manager {
14 namespace { 16 namespace {
15 17
16 // Creates a base::FilePathWatcher and starts watching at |watch_path| with 18 // Creates a base::FilePathWatcher and starts watching at |watch_path| with
17 // |callback|. Returns NULL on failure. 19 // |callback|. Returns NULL on failure.
18 base::FilePathWatcher* CreateAndStartFilePathWatcher( 20 base::FilePathWatcher* CreateAndStartFilePathWatcher(
19 const base::FilePath& watch_path, 21 const base::FilePath& watch_path,
20 const base::FilePathWatcher::Callback& callback) { 22 const base::FilePathWatcher::Callback& callback) {
21 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
22 DCHECK(!callback.is_null()); 23 DCHECK(!callback.is_null());
23 24
24 std::unique_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher); 25 std::unique_ptr<base::FilePathWatcher> watcher(new base::FilePathWatcher);
25 if (!watcher->Watch(watch_path, false /* recursive */, callback)) 26 if (!watcher->Watch(watch_path, false /* recursive */, callback))
26 return NULL; 27 return NULL;
27 28
28 return watcher.release(); 29 return watcher.release();
29 } 30 }
30 31
31 } // namespace 32 } // namespace
32 33
33 FileWatcher::FileWatcher(const base::FilePath& virtual_path) 34 FileWatcher::FileWatcher(const base::FilePath& virtual_path)
34 : local_file_watcher_(NULL), 35 : sequenced_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
36 {base::MayBlock(), base::TaskPriority::USER_VISIBLE})),
37 local_file_watcher_(NULL),
35 virtual_path_(virtual_path), 38 virtual_path_(virtual_path),
36 weak_ptr_factory_(this) { 39 weak_ptr_factory_(this) {
37 DCHECK_CURRENTLY_ON(BrowserThread::UI); 40 DCHECK_CURRENTLY_ON(BrowserThread::UI);
38 } 41 }
39 42
40 FileWatcher::~FileWatcher() { 43 FileWatcher::~FileWatcher() {
41 DCHECK_CURRENTLY_ON(BrowserThread::UI); 44 DCHECK_CURRENTLY_ON(BrowserThread::UI);
42 45
43 BrowserThread::DeleteSoon(BrowserThread::FILE, 46 sequenced_task_runner_->DeleteSoon(FROM_HERE, local_file_watcher_);
44 FROM_HERE,
45 local_file_watcher_);
46 } 47 }
47 48
48 void FileWatcher::AddExtension(const std::string& extension_id) { 49 void FileWatcher::AddExtension(const std::string& extension_id) {
49 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
50 51
51 extensions_[extension_id]++; 52 extensions_[extension_id]++;
52 } 53 }
53 54
54 void FileWatcher::RemoveExtension(const std::string& extension_id) { 55 void FileWatcher::RemoveExtension(const std::string& extension_id) {
55 DCHECK_CURRENTLY_ON(BrowserThread::UI); 56 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 23 matching lines...) Expand all
79 } 80 }
80 81
81 void FileWatcher::WatchLocalFile( 82 void FileWatcher::WatchLocalFile(
82 const base::FilePath& local_path, 83 const base::FilePath& local_path,
83 const base::FilePathWatcher::Callback& file_watcher_callback, 84 const base::FilePathWatcher::Callback& file_watcher_callback,
84 const BoolCallback& callback) { 85 const BoolCallback& callback) {
85 DCHECK_CURRENTLY_ON(BrowserThread::UI); 86 DCHECK_CURRENTLY_ON(BrowserThread::UI);
86 DCHECK(!callback.is_null()); 87 DCHECK(!callback.is_null());
87 DCHECK(!local_file_watcher_); 88 DCHECK(!local_file_watcher_);
88 89
89 BrowserThread::PostTaskAndReplyWithResult( 90 base::PostTaskAndReplyWithResult(
90 BrowserThread::FILE, 91 sequenced_task_runner_.get(), FROM_HERE,
91 FROM_HERE, 92 base::Bind(&CreateAndStartFilePathWatcher, local_path,
92 base::Bind(&CreateAndStartFilePathWatcher,
93 local_path,
94 google_apis::CreateRelayCallback(file_watcher_callback)), 93 google_apis::CreateRelayCallback(file_watcher_callback)),
95 base::Bind(&FileWatcher::OnWatcherStarted, 94 base::Bind(&FileWatcher::OnWatcherStarted, weak_ptr_factory_.GetWeakPtr(),
96 weak_ptr_factory_.GetWeakPtr(),
97 callback)); 95 callback));
98 } 96 }
99 97
100 void FileWatcher::OnWatcherStarted( 98 void FileWatcher::OnWatcherStarted(
101 const BoolCallback& callback, 99 const BoolCallback& callback,
102 base::FilePathWatcher* file_watcher) { 100 base::FilePathWatcher* file_watcher) {
103 DCHECK_CURRENTLY_ON(BrowserThread::UI); 101 DCHECK_CURRENTLY_ON(BrowserThread::UI);
104 DCHECK(!callback.is_null()); 102 DCHECK(!callback.is_null());
105 DCHECK(!local_file_watcher_); 103 DCHECK(!local_file_watcher_);
106 104
107 if (file_watcher) { 105 if (file_watcher) {
108 local_file_watcher_ = file_watcher; 106 local_file_watcher_ = file_watcher;
109 callback.Run(true); 107 callback.Run(true);
110 } else { 108 } else {
111 callback.Run(false); 109 callback.Run(false);
112 } 110 }
113 } 111 }
114 112
115 } // namespace file_manager 113 } // namespace file_manager
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_watcher.h ('k') | chrome/browser/chromeos/file_manager/file_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698