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
ReadDirectory(
53 const base::FilePath
& directory_path
,
54 const storage::AsyncFileUtil::ReadDirectoryCallback
& callback
) override
;
55 AbortCallback
OpenFile(const base::FilePath
& file_path
,
57 const OpenFileCallback
& callback
) override
;
58 AbortCallback
CloseFile(
60 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
61 AbortCallback
ReadFile(int file_handle
,
62 net::IOBuffer
* buffer
,
65 const ReadChunkReceivedCallback
& callback
) override
;
66 AbortCallback
CreateDirectory(
67 const base::FilePath
& directory_path
,
69 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
70 AbortCallback
DeleteEntry(
71 const base::FilePath
& entry_path
,
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
,
88 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
89 AbortCallback
WriteFile(
91 net::IOBuffer
* buffer
,
94 const storage::AsyncFileUtil::StatusCallback
& callback
) override
;
95 AbortCallback
AddWatcher(
97 const base::FilePath
& entry_path
,
100 const storage::AsyncFileUtil::StatusCallback
& callback
,
101 const storage::WatcherManager::NotificationCallback
&
102 notification_callback
) override
;
105 const base::FilePath
& entry_path
,
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
,
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
;
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
,
130 base::File::Error result
);
132 // Called when closing a file is completed with either a success or an error.
133 void OnCloseFileCompleted(
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_