| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ |
| 7 | 7 |
| 8 #include "base/supports_user_data.h" | 8 #include "base/supports_user_data.h" |
| 9 #include "base/threading/thread_checker.h" |
| 9 #include "webkit/fileapi/task_runner_bound_observer_list.h" | 10 #include "webkit/fileapi/task_runner_bound_observer_list.h" |
| 10 #include "webkit/quota/quota_types.h" | 11 #include "webkit/quota/quota_types.h" |
| 11 #include "webkit/storage/webkit_storage_export.h" | 12 #include "webkit/storage/webkit_storage_export.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 class SequencedTaskRunner; | 15 class SequencedTaskRunner; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace fileapi { | 18 namespace fileapi { |
| 18 | 19 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 FileSystemOperationContext(FileSystemContext* context, | 34 FileSystemOperationContext(FileSystemContext* context, |
| 34 base::SequencedTaskRunner* task_runner); | 35 base::SequencedTaskRunner* task_runner); |
| 35 | 36 |
| 36 virtual ~FileSystemOperationContext(); | 37 virtual ~FileSystemOperationContext(); |
| 37 | 38 |
| 38 FileSystemContext* file_system_context() const { | 39 FileSystemContext* file_system_context() const { |
| 39 return file_system_context_; | 40 return file_system_context_; |
| 40 } | 41 } |
| 41 | 42 |
| 42 // Updates the current remaining quota. | 43 // Updates the current remaining quota. |
| 44 // This can be called to update the remaining quota during the operation. |
| 43 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) { | 45 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) { |
| 44 allowed_bytes_growth_ = allowed_bytes_growth; | 46 allowed_bytes_growth_ = allowed_bytes_growth; |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Returns the current remaining quota. | 49 // Returns the current remaining quota. |
| 48 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } | 50 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } |
| 49 | 51 |
| 50 quota::QuotaLimitType quota_limit_type() const { | 52 quota::QuotaLimitType quota_limit_type() const { |
| 51 return quota_limit_type_; | 53 return quota_limit_type_; |
| 52 } | 54 } |
| 53 | 55 |
| 54 // Returns TaskRunner which the operation is performed on. | 56 // Returns TaskRunner which the operation is performed on. |
| 55 base::SequencedTaskRunner* task_runner() const { | 57 base::SequencedTaskRunner* task_runner() const { |
| 56 return task_runner_.get(); | 58 return task_runner_.get(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 ChangeObserverList* change_observers() { return &change_observers_; } | 61 ChangeObserverList* change_observers() { return &change_observers_; } |
| 60 AccessObserverList* access_observers() { return &access_observers_; } | 62 AccessObserverList* access_observers() { return &access_observers_; } |
| 61 UpdateObserverList* update_observers() { return &update_observers_; } | 63 UpdateObserverList* update_observers() { return &update_observers_; } |
| 62 | 64 |
| 65 // Following setters should be called only on the same thread as the |
| 66 // FileSystemOperationContext is created (i.e. are not supposed be updated |
| 67 // after the context's passed onto other task runners). |
| 68 void set_change_observers(const ChangeObserverList& list) { |
| 69 DCHECK(setter_thread_checker_.CalledOnValidThread()); |
| 70 change_observers_ = list; |
| 71 } |
| 72 void set_access_observers(const AccessObserverList& list) { |
| 73 DCHECK(setter_thread_checker_.CalledOnValidThread()); |
| 74 access_observers_ = list; |
| 75 } |
| 76 void set_update_observers(const UpdateObserverList& list) { |
| 77 DCHECK(setter_thread_checker_.CalledOnValidThread()); |
| 78 update_observers_ = list; |
| 79 } |
| 80 void set_quota_limit_type(quota::QuotaLimitType limit_type) { |
| 81 DCHECK(setter_thread_checker_.CalledOnValidThread()); |
| 82 quota_limit_type_ = limit_type; |
| 83 } |
| 84 |
| 63 // Gets and sets value-type (or not-owned) variable as UserData. | 85 // Gets and sets value-type (or not-owned) variable as UserData. |
| 86 // (SetUserValue can be called only on the same thread as this context |
| 87 // is created as well as other setters.) |
| 64 template <typename T> T GetUserValue(const char* key) const { | 88 template <typename T> T GetUserValue(const char* key) const { |
| 65 ValueAdapter<T>* v = static_cast<ValueAdapter<T>*>(GetUserData(key)); | 89 ValueAdapter<T>* v = static_cast<ValueAdapter<T>*>(GetUserData(key)); |
| 66 return v ? v->value() : T(); | 90 return v ? v->value() : T(); |
| 67 } | 91 } |
| 68 template <typename T> void SetUserValue(const char* key, const T& value) { | 92 template <typename T> void SetUserValue(const char* key, const T& value) { |
| 93 DCHECK(setter_thread_checker_.CalledOnValidThread()); |
| 69 SetUserData(key, new ValueAdapter<T>(value)); | 94 SetUserData(key, new ValueAdapter<T>(value)); |
| 70 } | 95 } |
| 71 | 96 |
| 72 private: | 97 private: |
| 73 // An adapter for setting a value-type (or not owned) data as UserData. | 98 // An adapter for setting a value-type (or not owned) data as UserData. |
| 74 template <typename T> class ValueAdapter | 99 template <typename T> class ValueAdapter |
| 75 : public base::SupportsUserData::Data { | 100 : public base::SupportsUserData::Data { |
| 76 public: | 101 public: |
| 77 ValueAdapter(const T& value) : value_(value) {} | 102 ValueAdapter(const T& value) : value_(value) {} |
| 78 const T& value() const { return value_; } | 103 const T& value() const { return value_; } |
| 79 private: | 104 private: |
| 80 T value_; | 105 T value_; |
| 81 DISALLOW_COPY_AND_ASSIGN(ValueAdapter); | 106 DISALLOW_COPY_AND_ASSIGN(ValueAdapter); |
| 82 }; | 107 }; |
| 83 | 108 |
| 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_; | 109 FileSystemContext* file_system_context_; |
| 110 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 110 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 111 | 111 |
| 112 int64 allowed_bytes_growth_; | 112 int64 allowed_bytes_growth_; |
| 113 quota::QuotaLimitType quota_limit_type_; | 113 quota::QuotaLimitType quota_limit_type_; |
| 114 | 114 |
| 115 AccessObserverList access_observers_; | 115 AccessObserverList access_observers_; |
| 116 ChangeObserverList change_observers_; | 116 ChangeObserverList change_observers_; |
| 117 UpdateObserverList update_observers_; | 117 UpdateObserverList update_observers_; |
| 118 | 118 |
| 119 // Used to check its setters are not called on arbitrary thread. |
| 120 base::ThreadChecker setter_thread_checker_; |
| 121 |
| 119 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext); | 122 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext); |
| 120 }; | 123 }; |
| 121 | 124 |
| 122 } // namespace fileapi | 125 } // namespace fileapi |
| 123 | 126 |
| 124 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ | 127 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ |
| OLD | NEW |