blob: 9f0f0d5b8810d05906b7c6df8b36bd5fefe526c6 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
David Blackc6460cd22020-11-23 23:39:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Yeunjoo Choief8a4a42022-11-08 04:21:055#ifndef CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_
6#define CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_
David Blackc6460cd22020-11-23 23:39:167
David Black08bddc82023-12-21 23:55:548#include "base/callback_list.h"
David Blackc6460cd22020-11-23 23:39:169#include "base/observer_list.h"
Yeunjoo Choief8a4a42022-11-08 04:21:0510#include "chrome/browser/ash/fileapi/file_change_service_observer.h"
David Blackc6460cd22020-11-23 23:39:1611#include "components/keyed_service/core/keyed_service.h"
David Blackc6460cd22020-11-23 23:39:1612
David Black08bddc82023-12-21 23:55:5413class Profile;
14
Yeunjoo Choi3d9ed38a2022-11-10 02:51:2415namespace ash {
David Blackc6460cd22020-11-23 23:39:1616
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 Black8f8c1eb2020-12-09 04:02:2320class FileChangeService : public KeyedService {
David Blackc6460cd22020-11-23 23:39:1621 public:
David Black08bddc82023-12-21 23:55:5422 explicit FileChangeService(Profile* profile);
David Blackc6460cd22020-11-23 23:39:1623 FileChangeService(const FileChangeService& other) = delete;
24 FileChangeService& operator=(const FileChangeService& other) = delete;
25 ~FileChangeService() override;
26
David Black8f8c1eb2020-12-09 04:02:2327 // Adds/removes the specified `observer` for service events.
28 void AddObserver(FileChangeServiceObserver* observer);
29 void RemoveObserver(FileChangeServiceObserver* observer);
30
Toni Barzic589df9972020-12-30 19:47:5331 // Notifies the service that a file identified by `url` has been modified.
32 void NotifyFileModified(const storage::FileSystemURL& url);
33
David Black8f8c1eb2020-12-09 04:02:2334 // 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 Blackc6460cd22020-11-23 23:39:1637
David Black08bddc82023-12-21 23:55:5438 // 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 Blackc6460cd22020-11-23 23:39:1647 private:
David Black08bddc82023-12-21 23:55:5448 // 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 Black8f8c1eb2020-12-09 04:02:2353 base::ObserverList<FileChangeServiceObserver> observer_list_;
David Blackc6460cd22020-11-23 23:39:1654};
55
Yeunjoo Choi3d9ed38a2022-11-10 02:51:2456} // namespace ash
David Blackc6460cd22020-11-23 23:39:1657
Yeunjoo Choief8a4a42022-11-08 04:21:0558#endif // CHROME_BROWSER_ASH_FILEAPI_FILE_CHANGE_SERVICE_H_