Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / throttled_file_system.h
blob36534694a53fa09fd2c94fe75c66ea616a03d900
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_
8 #include <set>
9 #include <string>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
18 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_observer.h"
19 #include "storage/browser/fileapi/async_file_util.h"
20 #include "storage/browser/fileapi/watcher_manager.h"
21 #include "url/gurl.h"
23 class Profile;
25 namespace net {
26 class IOBuffer;
27 } // namespace net
29 namespace base {
30 class FilePath;
31 } // namespace base
33 namespace chromeos {
34 namespace file_system_provider {
36 class Queue;
37 class RequestManager;
39 // Decorates ProvidedFileSystemInterface with throttling capabilities.
40 class ThrottledFileSystem : public ProvidedFileSystemInterface {
41 public:
42 explicit ThrottledFileSystem(
43 scoped_ptr<ProvidedFileSystemInterface> file_system);
44 ~ThrottledFileSystem() override;
46 // ProvidedFileSystemInterface overrides.
47 AbortCallback RequestUnmount(
48 const storage::AsyncFileUtil::StatusCallback& callback) override;
49 AbortCallback GetMetadata(const base::FilePath& entry_path,
50 MetadataFieldMask fields,
51 const GetMetadataCallback& callback) override;
52 AbortCallback GetActions(const base::FilePath& entry_path,
53 const GetActionsCallback& callback) override;
54 AbortCallback ExecuteAction(
55 const base::FilePath& entry_path,
56 const std::string& action_id,
57 const storage::AsyncFileUtil::StatusCallback& callback) override;
58 AbortCallback ReadDirectory(
59 const base::FilePath& directory_path,
60 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) override;
61 AbortCallback OpenFile(const base::FilePath& file_path,
62 OpenFileMode mode,
63 const OpenFileCallback& callback) override;
64 AbortCallback CloseFile(
65 int file_handle,
66 const storage::AsyncFileUtil::StatusCallback& callback) override;
67 AbortCallback ReadFile(int file_handle,
68 net::IOBuffer* buffer,
69 int64 offset,
70 int length,
71 const ReadChunkReceivedCallback& callback) override;
72 AbortCallback CreateDirectory(
73 const base::FilePath& directory_path,
74 bool recursive,
75 const storage::AsyncFileUtil::StatusCallback& callback) override;
76 AbortCallback DeleteEntry(
77 const base::FilePath& entry_path,
78 bool recursive,
79 const storage::AsyncFileUtil::StatusCallback& callback) override;
80 AbortCallback CreateFile(
81 const base::FilePath& file_path,
82 const storage::AsyncFileUtil::StatusCallback& callback) override;
83 AbortCallback CopyEntry(
84 const base::FilePath& source_path,
85 const base::FilePath& target_path,
86 const storage::AsyncFileUtil::StatusCallback& callback) override;
87 AbortCallback MoveEntry(
88 const base::FilePath& source_path,
89 const base::FilePath& target_path,
90 const storage::AsyncFileUtil::StatusCallback& callback) override;
91 AbortCallback Truncate(
92 const base::FilePath& file_path,
93 int64 length,
94 const storage::AsyncFileUtil::StatusCallback& callback) override;
95 AbortCallback WriteFile(
96 int file_handle,
97 net::IOBuffer* buffer,
98 int64 offset,
99 int length,
100 const storage::AsyncFileUtil::StatusCallback& callback) override;
101 AbortCallback AddWatcher(
102 const GURL& origin,
103 const base::FilePath& entry_path,
104 bool recursive,
105 bool persistent,
106 const storage::AsyncFileUtil::StatusCallback& callback,
107 const storage::WatcherManager::NotificationCallback&
108 notification_callback) override;
109 void RemoveWatcher(
110 const GURL& origin,
111 const base::FilePath& entry_path,
112 bool recursive,
113 const storage::AsyncFileUtil::StatusCallback& callback) override;
114 const ProvidedFileSystemInfo& GetFileSystemInfo() const override;
115 RequestManager* GetRequestManager() override;
116 Watchers* GetWatchers() override;
117 const OpenedFiles& GetOpenedFiles() const override;
118 void AddObserver(ProvidedFileSystemObserver* observer) override;
119 void RemoveObserver(ProvidedFileSystemObserver* observer) override;
120 void Notify(const base::FilePath& entry_path,
121 bool recursive,
122 storage::WatcherManager::ChangeType change_type,
123 scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
124 const std::string& tag,
125 const storage::AsyncFileUtil::StatusCallback& callback) override;
126 void Configure(
127 const storage::AsyncFileUtil::StatusCallback& callback) override;
128 base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
130 private:
131 // Called when an operation enqueued with |queue_token| is aborted.
132 void Abort(int queue_token);
134 // Called when opening a file is completed with either a success or an error.
135 void OnOpenFileCompleted(int queue_token,
136 const OpenFileCallback& callback,
137 int file_handle,
138 base::File::Error result);
140 // Called when closing a file is completed with either a success or an error.
141 void OnCloseFileCompleted(
142 int file_handle,
143 const storage::AsyncFileUtil::StatusCallback& callback,
144 base::File::Error result);
146 scoped_ptr<ProvidedFileSystemInterface> file_system_;
147 scoped_ptr<Queue> open_queue_;
149 // Map from file handles to open queue tokens.
150 std::map<int, int> opened_files_;
152 base::WeakPtrFactory<ThrottledFileSystem> weak_ptr_factory_;
153 DISALLOW_COPY_AND_ASSIGN(ThrottledFileSystem);
156 } // namespace file_system_provider
157 } // namespace chromeos
159 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_