Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / throttled_file_system.h
blob3d4e50951a5bfb015a470435f6058c785f90df40
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 ReadDirectory(
53 const base::FilePath& directory_path,
54 const storage::AsyncFileUtil::ReadDirectoryCallback& callback) override;
55 AbortCallback OpenFile(const base::FilePath& file_path,
56 OpenFileMode mode,
57 const OpenFileCallback& callback) override;
58 AbortCallback CloseFile(
59 int file_handle,
60 const storage::AsyncFileUtil::StatusCallback& callback) override;
61 AbortCallback ReadFile(int file_handle,
62 net::IOBuffer* buffer,
63 int64 offset,
64 int length,
65 const ReadChunkReceivedCallback& callback) override;
66 AbortCallback CreateDirectory(
67 const base::FilePath& directory_path,
68 bool recursive,
69 const storage::AsyncFileUtil::StatusCallback& callback) override;
70 AbortCallback DeleteEntry(
71 const base::FilePath& entry_path,
72 bool recursive,
73 const storage::AsyncFileUtil::StatusCallback& callback) override;
74 AbortCallback CreateFile(
75 const base::FilePath& file_path,
76 const storage::AsyncFileUtil::StatusCallback& callback) override;
77 AbortCallback CopyEntry(
78 const base::FilePath& source_path,
79 const base::FilePath& target_path,
80 const storage::AsyncFileUtil::StatusCallback& callback) override;
81 AbortCallback MoveEntry(
82 const base::FilePath& source_path,
83 const base::FilePath& target_path,
84 const storage::AsyncFileUtil::StatusCallback& callback) override;
85 AbortCallback Truncate(
86 const base::FilePath& file_path,
87 int64 length,
88 const storage::AsyncFileUtil::StatusCallback& callback) override;
89 AbortCallback WriteFile(
90 int file_handle,
91 net::IOBuffer* buffer,
92 int64 offset,
93 int length,
94 const storage::AsyncFileUtil::StatusCallback& callback) override;
95 AbortCallback AddWatcher(
96 const GURL& origin,
97 const base::FilePath& entry_path,
98 bool recursive,
99 bool persistent,
100 const storage::AsyncFileUtil::StatusCallback& callback,
101 const storage::WatcherManager::NotificationCallback&
102 notification_callback) override;
103 void RemoveWatcher(
104 const GURL& origin,
105 const base::FilePath& entry_path,
106 bool recursive,
107 const storage::AsyncFileUtil::StatusCallback& callback) override;
108 const ProvidedFileSystemInfo& GetFileSystemInfo() const override;
109 RequestManager* GetRequestManager() override;
110 Watchers* GetWatchers() override;
111 const OpenedFiles& GetOpenedFiles() const override;
112 void AddObserver(ProvidedFileSystemObserver* observer) override;
113 void RemoveObserver(ProvidedFileSystemObserver* observer) override;
114 void Notify(const base::FilePath& entry_path,
115 bool recursive,
116 storage::WatcherManager::ChangeType change_type,
117 scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
118 const std::string& tag,
119 const storage::AsyncFileUtil::StatusCallback& callback) override;
120 base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() override;
122 private:
123 // Called when an operation enqueued with |queue_token| is aborted.
124 void Abort(int queue_token);
126 // Called when opening a file is completed with either a success or an error.
127 void OnOpenFileCompleted(int queue_token,
128 const OpenFileCallback& callback,
129 int file_handle,
130 base::File::Error result);
132 // Called when closing a file is completed with either a success or an error.
133 void OnCloseFileCompleted(
134 int file_handle,
135 const storage::AsyncFileUtil::StatusCallback& callback,
136 base::File::Error result);
138 scoped_ptr<ProvidedFileSystemInterface> file_system_;
139 scoped_ptr<Queue> open_queue_;
141 // Map from file handles to open queue tokens.
142 std::map<int, int> opened_files_;
144 base::WeakPtrFactory<ThrottledFileSystem> weak_ptr_factory_;
145 DISALLOW_COPY_AND_ASSIGN(ThrottledFileSystem);
148 } // namespace file_system_provider
149 } // namespace chromeos
151 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_THROTTLED_FILE_SYSTEM_H_