Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: webkit/fileapi/file_system_operation_context.h

Issue 14341004: FileAPI code should not rely on or assume specific MountPointProvider types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | webkit/fileapi/file_system_operation_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/fileapi/media/mtp_device_file_system_config.h" 8 #include "base/supports_user_data.h"
9 #include "webkit/fileapi/task_runner_bound_observer_list.h" 9 #include "webkit/fileapi/task_runner_bound_observer_list.h"
10 #include "webkit/storage/webkit_storage_export.h" 10 #include "webkit/storage/webkit_storage_export.h"
11 11
12 namespace base { 12 namespace base {
13 class SequencedTaskRunner; 13 class SequencedTaskRunner;
14 } 14 }
15 15
16 namespace fileapi { 16 namespace fileapi {
17 17
18 class FileSystemContext; 18 class FileSystemContext;
19 class MediaPathFilter;
20 19
21 // A context class which is carried around by FileSystemOperation and 20 // A context class which is carried around by FileSystemOperation and
22 // its delegated tasks. It is valid to reuse one context instance across 21 // its delegated tasks. It is valid to reuse one context instance across
23 // multiple operations as far as those operations are supposed to share 22 // 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). 23 // 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 24 // Note that the remaining quota bytes (allowed_bytes_growth) may be
26 // updated during the execution of write operations. 25 // updated during the execution of write operations.
27 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext { 26 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOperationContext
27 : public base::SupportsUserData {
28 public: 28 public:
29 explicit FileSystemOperationContext(FileSystemContext* context); 29 explicit FileSystemOperationContext(FileSystemContext* context);
30 ~FileSystemOperationContext(); 30
31 // Specifies |task_runner| which the operation is performed on.
32 FileSystemOperationContext(FileSystemContext* context,
33 base::SequencedTaskRunner* task_runner);
34
35 virtual ~FileSystemOperationContext();
31 36
32 FileSystemContext* file_system_context() const { 37 FileSystemContext* file_system_context() const {
33 return file_system_context_; 38 return file_system_context_;
34 } 39 }
35 40
36 // Updates the current remaining quota. 41 // Updates the current remaining quota.
37 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) { 42 void set_allowed_bytes_growth(const int64& allowed_bytes_growth) {
38 allowed_bytes_growth_ = allowed_bytes_growth; 43 allowed_bytes_growth_ = allowed_bytes_growth;
39 } 44 }
40 45
41 // Returns the current remaining quota. 46 // Returns the current remaining quota.
42 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; } 47 int64 allowed_bytes_growth() const { return allowed_bytes_growth_; }
43 48
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_;
48 }
49 #endif
50
51 // Returns TaskRunner which the operation is performed on. 49 // Returns TaskRunner which the operation is performed on.
52 base::SequencedTaskRunner* task_runner() const { 50 base::SequencedTaskRunner* task_runner() const {
53 return task_runner_.get(); 51 return task_runner_.get();
54 } 52 }
55 53
56 MediaPathFilter* media_path_filter() { return media_path_filter_; }
57 ChangeObserverList* change_observers() { return &change_observers_; } 54 ChangeObserverList* change_observers() { return &change_observers_; }
58 AccessObserverList* access_observers() { return &access_observers_; } 55 AccessObserverList* access_observers() { return &access_observers_; }
59 UpdateObserverList* update_observers() { return &update_observers_; } 56 UpdateObserverList* update_observers() { return &update_observers_; }
60 57
58 // Gets and sets value-type (or not-owned) variable as UserData.
59 template <typename T> T GetUserValue(const char* key) const {
60 ValueAdapter<T>* v = static_cast<ValueAdapter<T>*>(GetUserData(key));
61 return v ? v->value() : T();
62 }
63 template <typename T> void SetUserValue(const char* key, const T& value) {
64 SetUserData(key, new ValueAdapter<T>(value));
65 }
66
61 private: 67 private:
62 // Only MountPointProviders can access these setters. 68 // An adapter for setting a value-type (or not owned) data as UserData.
63 friend class CrosMountPointProvider; 69 template <typename T> class ValueAdapter
70 : public base::SupportsUserData::Data {
71 public:
72 ValueAdapter(const T& value) : value_(value) {}
73 const T& value() const { return value_; }
74 private:
75 T value_;
76 DISALLOW_COPY_AND_ASSIGN(ValueAdapter);
77 };
78
79 // Only regular (and test) MountPointProviders can access following setters.
64 friend class IsolatedMountPointProvider; 80 friend class IsolatedMountPointProvider;
65 friend class SandboxMountPointProvider; 81 friend class SandboxMountPointProvider;
66 friend class TestMountPointProvider; 82 friend class TestMountPointProvider;
67 83
68 // Tests also need access to some setters. 84 // Tests also need access to some setters.
69 friend class FileSystemQuotaClientTest; 85 friend class FileSystemQuotaClientTest;
70 friend class LocalFileSystemOperationTest; 86 friend class LocalFileSystemOperationTest;
71 friend class LocalFileSystemOperationWriteTest; 87 friend class LocalFileSystemOperationWriteTest;
72 friend class LocalFileSystemTestOriginHelper; 88 friend class LocalFileSystemTestOriginHelper;
73 friend class ObfuscatedFileUtilTest; 89 friend class ObfuscatedFileUtilTest;
74 90
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);
78
79 void set_media_path_filter(MediaPathFilter* media_path_filter) {
80 media_path_filter_ = media_path_filter;
81 }
82 void set_change_observers(const ChangeObserverList& list) { 91 void set_change_observers(const ChangeObserverList& list) {
83 change_observers_ = list; 92 change_observers_ = list;
84 } 93 }
85 void set_access_observers(const AccessObserverList& list) { 94 void set_access_observers(const AccessObserverList& list) {
86 access_observers_ = list; 95 access_observers_ = list;
87 } 96 }
88 void set_update_observers(const UpdateObserverList& list) { 97 void set_update_observers(const UpdateObserverList& list) {
89 update_observers_ = list; 98 update_observers_ = list;
90 } 99 }
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;
95 }
96 #endif
97 100
98 FileSystemContext* file_system_context_; 101 FileSystemContext* file_system_context_;
99 scoped_refptr<base::SequencedTaskRunner> task_runner_; 102 scoped_refptr<base::SequencedTaskRunner> task_runner_;
100 103
101 int64 allowed_bytes_growth_; 104 int64 allowed_bytes_growth_;
102 MediaPathFilter* media_path_filter_;
103 105
104 AccessObserverList access_observers_; 106 AccessObserverList access_observers_;
105 ChangeObserverList change_observers_; 107 ChangeObserverList change_observers_;
106 UpdateObserverList update_observers_; 108 UpdateObserverList update_observers_;
107 109
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
113
114 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext); 110 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationContext);
115 }; 111 };
116 112
117 } // namespace fileapi 113 } // namespace fileapi
118 114
119 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_ 115 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_OPERATION_CONTEXT_H_
OLDNEW
« no previous file with comments | « no previous file | webkit/fileapi/file_system_operation_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698