Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / fileapi / file_system_operation_context.h
blob2cd2c6b960ae792d84ab3f999591f5410c768d5e
1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_
8 #include "webkit/fileapi/media/mtp_device_file_system_config.h"
9 #include "webkit/fileapi/task_runner_bound_observer_list.h"
10 #include "webkit/storage/webkit_storage_export.h"
12 namespace base {
13 class SequencedTaskRunner;
16 namespace fileapi {
18 class FileSystemContext;
19 class MediaPathFilter;
21 // A context class which is carried around by FileSystemOperation and
22 // its delegated tasks. It is valid to reuse one context instance across
23 // multiple operations as far as those operations are supposed to share
24 // the same context (e.g. use the same task runner, share the quota etc).
25 // Note that the remaining quota bytes (allowed_bytes_growth) may be
26 // updated during the execution of write operations.
27 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext {
28 public:
29 explicit FileSystemOperationContext(FileSystemContext* context);
30 ~FileSystemOperationContext();
32 FileSystemContext* file_system_context() const {
33 return file_system_context_;
36 // Updates the current remaining quota.
37 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) {
38 allowed_bytes_growth_ = allowed_bytes_growth;
41 // Returns the current remaining quota.
42 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; }
44 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
45 // Reads |mtp_device_delegate_url_| on |task_runner_|.
46 const std::string& mtp_device_delegate_url() const {
47 return mtp_device_delegate_url_;
49 #endif
51 // Returns TaskRunner which the operation is performed on.
52 base::SequencedTaskRunner* task_runner() const {
53 return task_runner_.get();
56 MediaPathFilter* media_path_filter() { return media_path_filter_; }
57 ChangeObserverList* change_observers() { return &change_observers_; }
58 AccessObserverList* access_observers() { return &access_observers_; }
59 UpdateObserverList* update_observers() { return &update_observers_; }
61 private:
62 // Only MountPointProviders can access these setters.
63 friend class CrosMountPointProvider;
64 friend class IsolatedMountPointProvider;
65 friend class SandboxMountPointProvider;
66 friend class TestMountPointProvider;
68 // Tests also need access to some setters.
69 friend class FileSystemQuotaClientTest;
70 friend class LocalFileSystemOperationTest;
71 friend class LocalFileSystemOperationWriteTest;
72 friend class LocalFileSystemTestOriginHelper;
73 friend class ObfuscatedFileUtilTest;
75 // Overrides TaskRunner which the operation is performed on.
76 // file_system_context_->task_runners()->file_task_runner() is used otherwise.
77 void set_task_runner(base::SequencedTaskRunner* task_runner);
79 void set_media_path_filter(MediaPathFilter* media_path_filter) {
80 media_path_filter_ = media_path_filter;
82 void set_change_observers(const ChangeObserverList& list) {
83 change_observers_ = list;
85 void set_access_observers(const AccessObserverList& list) {
86 access_observers_ = list;
88 void set_update_observers(const UpdateObserverList& list) {
89 update_observers_ = list;
91 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
92 // Initializes |mtp_device_delegate_url_| on the IO thread.
93 void set_mtp_device_delegate_url(const std::string& delegate_url) {
94 mtp_device_delegate_url_ = delegate_url;
96 #endif
98 FileSystemContext* file_system_context_;
99 scoped_refptr<base::SequencedTaskRunner> task_runner_;
101 int64 allowed_bytes_growth_;
102 MediaPathFilter* media_path_filter_;
104 AccessObserverList access_observers_;
105 ChangeObserverList change_observers_;
106 UpdateObserverList update_observers_;
108 #if defined(SUPPORT_MTP_DEVICE_FILESYSTEM)
109 // URL for the media transfer protocol (MTP) device delegate.
110 // Initialized on IO thread and used on |task_runner_|.
111 std::string mtp_device_delegate_url_;
112 #endif
114 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext);
117 } // namespace fileapi
119 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_