| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | |
| 7 | |
| 8 #include "base/supports_user_data.h" | |
| 9 #include "webkit/fileapi/task_runner_bound_observer_list.h" | |
| 10 #include "webkit/quota/quota_types.h" | |
| 11 #include "webkit/storage/webkit_storage_export.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class SequencedTaskRunner; | |
| 15 } | |
| 16 | |
| 17 namespace fileapi { | |
| 18 | |
| 19 class FileSystemContext; | |
| 20 | |
| 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 base::SupportsUserData { | |
| 29 public: | |
| 30 explicit FileSystemOperationContext(FileSystemContext* context); | |
| 31 | |
| 32 // Specifies |task_runner| which the operation is performed on. | |
| 33 FileSystemOperationContext(FileSystemContext* context, | |
| 34 base::SequencedTaskRunner* task_runner); | |
| 35 | |
| 36 virtual ~FileSystemOperationContext(); | |
| 37 | |
| 38 FileSystemContext* file_system_context() const { | |
| 39 return file_system_context_; | |
| 40 } | |
| 41 | |
| 42 // Updates the current remaining quota. | |
| 43 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) { | |
| 44 allowed_bytes_growth_ = allowed_bytes_growth; | |
| 45 } | |
| 46 | |
| 47 // Returns the current remaining quota. | |
| 48 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } | |
| 49 | |
| 50 quota::QuotaLimitType quota_limit_type() const { | |
| 51 return quota_limit_type_; | |
| 52 } | |
| 53 | |
| 54 // Returns TaskRunner which the operation is performed on. | |
| 55 base::SequencedTaskRunner* task_runner() const { | |
| 56 return task_runner_.get(); | |
| 57 } | |
| 58 | |
| 59 ChangeObserverList* change_observers() { return &change_observers_; } | |
| 60 AccessObserverList* access_observers() { return &access_observers_; } | |
| 61 UpdateObserverList* update_observers() { return &update_observers_; } | |
| 62 | |
| 63 // Gets and sets value-type (or not-owned) variable as UserData. | |
| 64 template <typename T> T GetUserValue(const char* key) const { | |
| 65 ValueAdapter<T>* v = static_cast<ValueAdapter<T>*>(GetUserData(key)); | |
| 66 return v ? v->value() : T(); | |
| 67 } | |
| 68 template <typename T> void SetUserValue(const char* key, const T& value) { | |
| 69 SetUserData(key, new ValueAdapter<T>(value)); | |
| 70 } | |
| 71 | |
| 72 private: | |
| 73 // An adapter for setting a value-type (or not owned) data as UserData. | |
| 74 template <typename T> class ValueAdapter | |
| 75 : public base::SupportsUserData::Data { | |
| 76 public: | |
| 77 ValueAdapter(const T& value) : value_(value) {} | |
| 78 const T& value() const { return value_; } | |
| 79 private: | |
| 80 T value_; | |
| 81 DISALLOW_COPY_AND_ASSIGN(ValueAdapter); | |
| 82 }; | |
| 83 | |
| 84 // Only regular (and test) MountPointProviders can access following setters. | |
| 85 friend class IsolatedMountPointProvider; | |
| 86 friend class SandboxMountPointProvider; | |
| 87 friend class TestMountPointProvider; | |
| 88 | |
| 89 // Tests also need access to some setters. | |
| 90 friend class FileSystemQuotaClientTest; | |
| 91 friend class LocalFileSystemOperationTest; | |
| 92 friend class LocalFileSystemOperationWriteTest; | |
| 93 friend class LocalFileSystemTestOriginHelper; | |
| 94 friend class ObfuscatedFileUtilTest; | |
| 95 | |
| 96 void set_change_observers(const ChangeObserverList& list) { | |
| 97 change_observers_ = list; | |
| 98 } | |
| 99 void set_access_observers(const AccessObserverList& list) { | |
| 100 access_observers_ = list; | |
| 101 } | |
| 102 void set_update_observers(const UpdateObserverList& list) { | |
| 103 update_observers_ = list; | |
| 104 } | |
| 105 void set_quota_limit_type(quota::QuotaLimitType limit_type) { | |
| 106 quota_limit_type_ = limit_type; | |
| 107 } | |
| 108 | |
| 109 FileSystemContext* file_system_context_; | |
| 110 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 111 | |
| 112 int64 allowed_bytes_growth_; | |
| 113 quota::QuotaLimitType quota_limit_type_; | |
| 114 | |
| 115 AccessObserverList access_observers_; | |
| 116 ChangeObserverList change_observers_; | |
| 117 UpdateObserverList update_observers_; | |
| 118 | |
| 119 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext); | |
| 120 }; | |
| 121 | |
| 122 } // namespace fileapi | |
| 123 | |
| 124 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | |
| OLD | NEW |