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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_file_system.h

Issue 2712613002: Call WatcherManager functions on the IO thread. (Closed)
Patch Set: Addressed hidehiko's comments. 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 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 // This file provides file system related API functions. 5 // This file provides file system related API functions.
6 6
7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_ H_ 7 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_ H_
8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_ H_ 8 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYSTEM_ H_
9 9
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 12
13 #include <memory>
14 #include <set>
13 #include <string> 15 #include <string>
16 #include <vector>
14 17
18 #include "base/callback_forward.h"
15 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h" 21 #include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
17 #include "chrome/browser/extensions/chrome_extension_function.h" 22 #include "chrome/browser/extensions/chrome_extension_function.h"
18 #include "chrome/browser/extensions/chrome_extension_function_details.h" 23 #include "chrome/browser/extensions/chrome_extension_function_details.h"
19 #include "components/drive/file_errors.h" 24 #include "components/drive/file_errors.h"
20 #include "device/media_transfer_protocol/mtp_storage_info.pb.h" 25 #include "device/media_transfer_protocol/mtp_storage_info.pb.h"
21 #include "extensions/browser/extension_function.h" 26 #include "extensions/browser/extension_function.h"
22 #include "storage/browser/fileapi/file_system_url.h" 27 #include "storage/browser/fileapi/file_system_url.h"
23 28
24 namespace storage { 29 namespace storage {
25 class FileSystemContext; 30 class FileSystemContext;
26 class FileSystemURL; 31 class FileSystemURL;
32 class WatcherManager;
27 } // namespace storage 33 } // namespace storage
28 34
29 namespace file_manager { 35 namespace file_manager {
36 class EventRouter;
30 namespace util { 37 namespace util {
31 struct EntryDefinition; 38 struct EntryDefinition;
32 typedef std::vector<EntryDefinition> EntryDefinitionList; 39 typedef std::vector<EntryDefinition> EntryDefinitionList;
33 } // namespace util 40 } // namespace util
34 } // namespace file_manager 41 } // namespace file_manager
35 42
36 namespace drive { 43 namespace drive {
37 namespace util { 44 namespace util {
38 class FileStreamMd5Digester; 45 class FileStreamMd5Digester;
39 } // namespace util 46 } // namespace util
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateGrantAccessFunction); 82 DISALLOW_COPY_AND_ASSIGN(FileManagerPrivateGrantAccessFunction);
76 }; 83 };
77 84
78 // Base class for FileManagerPrivateInternalAddFileWatchFunction and 85 // Base class for FileManagerPrivateInternalAddFileWatchFunction and
79 // FileManagerPrivateInternalRemoveFileWatchFunction. Although it's called 86 // FileManagerPrivateInternalRemoveFileWatchFunction. Although it's called
80 // "FileWatch", 87 // "FileWatch",
81 // the class and its sub classes are used only for watching changes in 88 // the class and its sub classes are used only for watching changes in
82 // directories. 89 // directories.
83 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction { 90 class FileWatchFunctionBase : public LoggedAsyncExtensionFunction {
84 public: 91 public:
92 using ResponseCallback = base::Callback<void(bool success)>;
93
85 // Calls SendResponse() with |success| converted to base::Value. 94 // Calls SendResponse() with |success| converted to base::Value.
86 void Respond(bool success); 95 void Respond(bool success);
87 96
88 protected: 97 protected:
89 ~FileWatchFunctionBase() override {} 98 ~FileWatchFunctionBase() override {}
90 99
91 // Performs a file watch operation (ex. adds or removes a file watch). 100 // Performs a file watch operation (ex. adds or removes a file watch) on
92 virtual void PerformFileWatchOperation( 101 // the IO thread with storage::WatcherManager.
102 virtual void PerformFileWatchOperationOnIOThread(
93 scoped_refptr<storage::FileSystemContext> file_system_context, 103 scoped_refptr<storage::FileSystemContext> file_system_context,
104 storage::WatcherManager* watcher_manager,
94 const storage::FileSystemURL& file_system_url, 105 const storage::FileSystemURL& file_system_url,
95 const std::string& extension_id) = 0; 106 base::WeakPtr<file_manager::EventRouter> event_router) = 0;
107
108 // Performs a file watch operation (ex. adds or removes a file watch) on
109 // the UI thread with file_manager::EventRouter. This is a fallback operation
110 // called only when WatcherManager is unavailable.
111 virtual void PerformFallbackFileWatchOperationOnUIThread(
112 const storage::FileSystemURL& file_system_url,
113 base::WeakPtr<file_manager::EventRouter> event_router) = 0;
96 114
97 // AsyncExtensionFunction overrides. 115 // AsyncExtensionFunction overrides.
98 bool RunAsync() override; 116 bool RunAsync() override;
117
118 private:
119 void RunAsyncOnIOThread(
120 scoped_refptr<storage::FileSystemContext> file_system_context,
121 const storage::FileSystemURL& file_system_url,
122 base::WeakPtr<file_manager::EventRouter> event_router);
99 }; 123 };
100 124
101 // Implements the chrome.fileManagerPrivate.addFileWatch method. 125 // Implements the chrome.fileManagerPrivate.addFileWatch method.
102 // Starts watching changes in directories. 126 // Starts watching changes in directories.
103 class FileManagerPrivateInternalAddFileWatchFunction 127 class FileManagerPrivateInternalAddFileWatchFunction
104 : public FileWatchFunctionBase { 128 : public FileWatchFunctionBase {
105 public: 129 public:
106 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.addFileWatch", 130 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.addFileWatch",
107 FILEMANAGERPRIVATEINTERNAL_ADDFILEWATCH) 131 FILEMANAGERPRIVATEINTERNAL_ADDFILEWATCH)
108 132
109 protected: 133 protected:
110 ~FileManagerPrivateInternalAddFileWatchFunction() override {} 134 ~FileManagerPrivateInternalAddFileWatchFunction() override {}
111 135
112 // FileWatchFunctionBase override. 136 // FileWatchFunctionBase override.
113 void PerformFileWatchOperation( 137 void PerformFileWatchOperationOnIOThread(
114 scoped_refptr<storage::FileSystemContext> file_system_context, 138 scoped_refptr<storage::FileSystemContext> file_system_context,
139 storage::WatcherManager* watcher_manager,
115 const storage::FileSystemURL& file_system_url, 140 const storage::FileSystemURL& file_system_url,
116 const std::string& extension_id) override; 141 base::WeakPtr<file_manager::EventRouter> event_router) override;
142 void PerformFallbackFileWatchOperationOnUIThread(
143 const storage::FileSystemURL& file_system_url,
144 base::WeakPtr<file_manager::EventRouter> event_router) override;
117 }; 145 };
118 146
119 147
120 // Implements the chrome.fileManagerPrivate.removeFileWatch method. 148 // Implements the chrome.fileManagerPrivate.removeFileWatch method.
121 // Stops watching changes in directories. 149 // Stops watching changes in directories.
122 class FileManagerPrivateInternalRemoveFileWatchFunction 150 class FileManagerPrivateInternalRemoveFileWatchFunction
123 : public FileWatchFunctionBase { 151 : public FileWatchFunctionBase {
124 public: 152 public:
125 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.removeFileWatch", 153 DECLARE_EXTENSION_FUNCTION("fileManagerPrivateInternal.removeFileWatch",
126 FILEMANAGERPRIVATEINTERNAL_REMOVEFILEWATCH) 154 FILEMANAGERPRIVATEINTERNAL_REMOVEFILEWATCH)
127 155
128 protected: 156 protected:
129 ~FileManagerPrivateInternalRemoveFileWatchFunction() override {} 157 ~FileManagerPrivateInternalRemoveFileWatchFunction() override {}
130 158
131 // FileWatchFunctionBase override. 159 // FileWatchFunctionBase override.
132 void PerformFileWatchOperation( 160 void PerformFileWatchOperationOnIOThread(
133 scoped_refptr<storage::FileSystemContext> file_system_context, 161 scoped_refptr<storage::FileSystemContext> file_system_context,
162 storage::WatcherManager* watcher_manager,
134 const storage::FileSystemURL& file_system_url, 163 const storage::FileSystemURL& file_system_url,
135 const std::string& extension_id) override; 164 base::WeakPtr<file_manager::EventRouter> event_router) override;
165 void PerformFallbackFileWatchOperationOnUIThread(
166 const storage::FileSystemURL& file_system_url,
167 base::WeakPtr<file_manager::EventRouter> event_router) override;
136 }; 168 };
137 169
138 // Implements the chrome.fileManagerPrivate.getSizeStats method. 170 // Implements the chrome.fileManagerPrivate.getSizeStats method.
139 class FileManagerPrivateGetSizeStatsFunction 171 class FileManagerPrivateGetSizeStatsFunction
140 : public LoggedAsyncExtensionFunction { 172 : public LoggedAsyncExtensionFunction {
141 public: 173 public:
142 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats", 174 DECLARE_EXTENSION_FUNCTION("fileManagerPrivate.getSizeStats",
143 FILEMANAGERPRIVATE_GETSIZESTATS) 175 FILEMANAGERPRIVATE_GETSIZESTATS)
144 176
145 protected: 177 protected:
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 374
343 void OnDirectorySizeRetrieved(int64_t size); 375 void OnDirectorySizeRetrieved(int64_t size);
344 376
345 // AsyncExtensionFunction overrides 377 // AsyncExtensionFunction overrides
346 bool RunAsync() override; 378 bool RunAsync() override;
347 }; 379 };
348 380
349 } // namespace extensions 381 } // namespace extensions
350 382
351 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYST EM_H_ 383 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_FILE_SYST EM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698