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

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

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