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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/watcher_manager.cc

Issue 2712613002: Call WatcherManager functions on the IO thread. (Closed)
Patch Set: Updated comments as per mtomasz's request. Created 3 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_system_provider/fileapi/watcher_manager.h " 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/watcher_manager.h "
6 6
7 #include "base/files/file.h"
7 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" 8 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
8 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 9 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 #include "storage/browser/fileapi/file_system_url.h" 11 #include "storage/browser/fileapi/file_system_url.h"
11 12
12 using content::BrowserThread; 13 using content::BrowserThread;
13 14
14 namespace chromeos { 15 namespace chromeos {
15 namespace file_system_provider { 16 namespace file_system_provider {
16 17
17 WatcherManager::WatcherManager() { 18 namespace {
18 } 19
19 WatcherManager::~WatcherManager() { 20 using StatusCallback = storage::WatcherManager::StatusCallback;
21 using NotificationCallback = storage::WatcherManager::NotificationCallback;
22 using ChangeType = storage::WatcherManager::ChangeType;
23
24 void CallStatusCallbackOnIOThread(const StatusCallback& callback,
25 base::File::Error error) {
26 DCHECK_CURRENTLY_ON(BrowserThread::UI);
27 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
28 base::Bind(callback, error));
20 } 29 }
21 30
22 void WatcherManager::AddWatcher( 31 void CallNotificationCallbackOnIOThread(const NotificationCallback& callback,
23 const storage::FileSystemURL& url, 32 ChangeType type) {
24 bool recursive, 33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
25 const StatusCallback& callback, 34 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
26 const NotificationCallback& notification_callback) { 35 base::Bind(callback, type));
36 }
37
38 void AddWatcherOnUIThread(const storage::FileSystemURL& url,
39 bool recursive,
40 const StatusCallback& callback,
41 const NotificationCallback& notification_callback) {
27 DCHECK_CURRENTLY_ON(BrowserThread::UI); 42 DCHECK_CURRENTLY_ON(BrowserThread::UI);
28 43
29 util::FileSystemURLParser parser(url); 44 util::FileSystemURLParser parser(url);
30 if (!parser.Parse()) { 45 if (!parser.Parse()) {
31 callback.Run(base::File::FILE_ERROR_SECURITY); 46 callback.Run(base::File::FILE_ERROR_SECURITY);
32 return; 47 return;
33 } 48 }
34 49
35 parser.file_system()->AddWatcher(url.origin(), 50 parser.file_system()->AddWatcher(url.origin(),
36 parser.file_path(), 51 parser.file_path(),
37 recursive, 52 recursive,
38 false /* persistent */, 53 false /* persistent */,
39 callback, 54 callback,
40 notification_callback); 55 notification_callback);
41 } 56 }
42 57
43 void WatcherManager::RemoveWatcher(const storage::FileSystemURL& url, 58 void RemoveWatcherOnUIThread(const storage::FileSystemURL& url,
44 bool recursive, 59 bool recursive,
45 const StatusCallback& callback) { 60 const StatusCallback& callback) {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 62
48 util::FileSystemURLParser parser(url); 63 util::FileSystemURLParser parser(url);
49 if (!parser.Parse()) { 64 if (!parser.Parse()) {
50 callback.Run(base::File::FILE_ERROR_SECURITY); 65 callback.Run(base::File::FILE_ERROR_SECURITY);
51 return; 66 return;
52 } 67 }
53 68
54 parser.file_system()->RemoveWatcher( 69 parser.file_system()->RemoveWatcher(
55 url.origin(), parser.file_path(), recursive, callback); 70 url.origin(), parser.file_path(), recursive, callback);
56 } 71 }
57 72
73 } // namespace
74
75 WatcherManager::WatcherManager() {}
hidehiko 2017/02/23 11:05:58 s/{}/= default/, please.
Shuhei Takahashi 2017/02/24 05:13:25 Done. (FYI, I just left this as-is; see the left s
hidehiko 2017/02/24 05:51:56 Oh, I didn't find it, and I misunderstood that the
76 WatcherManager::~WatcherManager() {}
77
78 void WatcherManager::AddWatcher(
79 const storage::FileSystemURL& url,
80 bool recursive,
81 const StatusCallback& callback,
82 const NotificationCallback& notification_callback) {
83 DCHECK_CURRENTLY_ON(BrowserThread::IO);
84 BrowserThread::PostTask(
85 BrowserThread::UI, FROM_HERE,
86 base::Bind(&AddWatcherOnUIThread, url, recursive,
87 base::Bind(&CallStatusCallbackOnIOThread, callback),
88 base::Bind(&CallNotificationCallbackOnIOThread,
89 notification_callback)));
90 }
91
92 void WatcherManager::RemoveWatcher(const storage::FileSystemURL& url,
93 bool recursive,
94 const StatusCallback& callback) {
95 DCHECK_CURRENTLY_ON(BrowserThread::IO);
96 BrowserThread::PostTask(
97 BrowserThread::UI, FROM_HERE,
98 base::Bind(&RemoveWatcherOnUIThread, url, recursive,
99 base::Bind(&CallStatusCallbackOnIOThread, callback)));
100 }
101
58 } // namespace file_system_provider 102 } // namespace file_system_provider
59 } // namespace chromeos 103 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698