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_
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"
34 namespace file_system_provider
{
39 // Decorates ProvidedFileSystemInterface with throttling capabilities.
40 class ThrottledFileSystem
: public ProvidedFileSystemInterface
{
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
,
63 const OpenFileCallback
& callback
) override
;
64 AbortCallback
CloseFile(
66 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
67 AbortCallback
ReadFile(int file_handle
,
68 net::IOBuffer
* buffer
,
71 const ReadChunkReceivedCallback
& callback
) override
;
72 AbortCallback
CreateDirectory(
73 const base::FilePath
& directory_path
,
75 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
76 AbortCallback
DeleteEntry(
77 const base::FilePath
& entry_path
,
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
,
94 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
95 AbortCallback
WriteFile(
97 net::IOBuffer
* buffer
,
100 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
101 AbortCallback
AddWatcher(
103 const base::FilePath
& entry_path
,
106 const storage::AsyncFileUtil::StatusCallback
& callback
,
107 const storage::WatcherManager::NotificationCallback
&
108 notification_callback
) override
;
111 const base::FilePath
& entry_path
,
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
,
122 storage::WatcherManager::ChangeType change_type
,
123 scoped_ptr
<ProvidedFileSystemObserver::Changes
> changes
,
124 const std::string
& tag
,
125 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
127 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
128 base::WeakPtr
<ProvidedFileSystemInterface
> GetWeakPtr() override
;
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
,
138 base::File::Error result
);
140 // Called when closing a file is completed with either a success or an error.
141 void OnCloseFileCompleted(
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_