Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_ |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 7 | |
David Black | 08bddc8 | 2023-12-21 23:55:54 | [diff] [blame] | 8 | #include "base/callback_list.h" |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 9 | #include "base/observer_list.h" |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 10 | #include "chrome/browser/ash/fileapi/file_change_service_observer.h" |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 11 | #include "components/keyed_service/core/keyed_service.h" |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 12 | |
David Black | 08bddc8 | 2023-12-21 23:55:54 | [diff] [blame] | 13 | class Profile; |
| 14 | |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 15 | namespace ash { |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 16 | |
| 17 | // A service which notifies observers of file change events from external file |
| 18 | // systems. This serves as a bridge to allow for observation of file system |
| 19 | // changes across all file system contexts within a browser context. |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 20 | class FileChangeService : public KeyedService { |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 21 | public: |
David Black | 08bddc8 | 2023-12-21 23:55:54 | [diff] [blame] | 22 | explicit FileChangeService(Profile* profile); |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 23 | FileChangeService(const FileChangeService& other) = delete; |
| 24 | FileChangeService& operator=(const FileChangeService& other) = delete; |
| 25 | ~FileChangeService() override; |
| 26 | |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 27 | // Adds/removes the specified `observer` for service events. |
| 28 | void AddObserver(FileChangeServiceObserver* observer); |
| 29 | void RemoveObserver(FileChangeServiceObserver* observer); |
| 30 | |
Toni Barzic | 589df997 | 2020-12-30 19:47:53 | [diff] [blame] | 31 | // Notifies the service that a file identified by `url` has been modified. |
| 32 | void NotifyFileModified(const storage::FileSystemURL& url); |
| 33 | |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 34 | // Notifies the service that a file has been moved from `src` to `dst`. |
| 35 | void NotifyFileMoved(const storage::FileSystemURL& src, |
| 36 | const storage::FileSystemURL& dst); |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 37 | |
David Black | 08bddc8 | 2023-12-21 23:55:54 | [diff] [blame] | 38 | // Notifies the service that a file has been created at `url` in fulfillment |
| 39 | // of a `window.showSaveFilePicker()` request from the given |
| 40 | // `file_picker_binding_context`. |
| 41 | // |
| 42 | // See `content::FileSystemAccessEntryFactory::BindingContext`. |
| 43 | void NotifyFileCreatedFromShowSaveFilePicker( |
| 44 | const GURL& file_picker_binding_context, |
| 45 | const storage::FileSystemURL& url); |
| 46 | |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 47 | private: |
David Black | 08bddc8 | 2023-12-21 23:55:54 | [diff] [blame] | 48 | // Subscription to be notified of file creation events originating from |
| 49 | // `window.showSaveFilePicker()`. |
| 50 | base::CallbackListSubscription |
| 51 | file_created_from_show_save_file_picker_subscription_; |
| 52 | |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 53 | base::ObserverList<FileChangeServiceObserver> observer_list_; |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 54 | }; |
| 55 | |
Yeunjoo Choi | 3d9ed38a | 2022-11-10 02:51:24 | [diff] [blame] | 56 | } // namespace ash |
David Black | c6460cd2 | 2020-11-23 23:39:16 | [diff] [blame] | 57 | |
Yeunjoo Choi | ef8a4a4 | 2022-11-08 04:21:05 | [diff] [blame] | 58 | #endif // CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_ |