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