OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" | 5 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" | 8 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" |
9 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" | 9 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" |
10 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" | 10 #include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h
" |
11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
12 #include "webkit/browser/fileapi/file_system_context.h" | 12 #include "webkit/browser/fileapi/file_system_context.h" |
13 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" | 13 #include "webkit/browser/fileapi/file_system_file_stream_reader.h" |
14 #include "webkit/browser/fileapi/file_system_operation_impl.h" | 14 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
15 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" | 15 #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" |
16 #include "webkit/browser/fileapi/sandbox_quota_observer.h" | 16 #include "webkit/browser/fileapi/sandbox_quota_observer.h" |
17 #include "webkit/common/fileapi/file_system_util.h" | 17 #include "webkit/common/fileapi/file_system_util.h" |
18 | 18 |
19 namespace sync_file_system { | 19 namespace sync_file_system { |
20 | 20 |
21 SyncFileSystemBackend::SyncFileSystemBackend() | 21 SyncFileSystemBackend::SyncFileSystemBackend() |
22 : sandbox_context_(NULL) { | 22 : delegate_(NULL) { |
23 } | 23 } |
24 | 24 |
25 SyncFileSystemBackend::~SyncFileSystemBackend() { | 25 SyncFileSystemBackend::~SyncFileSystemBackend() { |
26 if (change_tracker_) { | 26 if (change_tracker_) { |
27 sandbox_context_->file_task_runner()->DeleteSoon( | 27 delegate_->file_task_runner()->DeleteSoon( |
28 FROM_HERE, change_tracker_.release()); | 28 FROM_HERE, change_tracker_.release()); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 bool SyncFileSystemBackend::CanHandleType( | 32 bool SyncFileSystemBackend::CanHandleType( |
33 fileapi::FileSystemType type) const { | 33 fileapi::FileSystemType type) const { |
34 return type == fileapi::kFileSystemTypeSyncable || | 34 return type == fileapi::kFileSystemTypeSyncable || |
35 type == fileapi::kFileSystemTypeSyncableForInternalSync; | 35 type == fileapi::kFileSystemTypeSyncableForInternalSync; |
36 } | 36 } |
37 | 37 |
38 void SyncFileSystemBackend::Initialize(fileapi::FileSystemContext* context) { | 38 void SyncFileSystemBackend::Initialize(fileapi::FileSystemContext* context) { |
39 DCHECK(context); | 39 DCHECK(context); |
40 DCHECK(!sandbox_context_); | 40 DCHECK(!delegate_); |
41 sandbox_context_ = context->sandbox_context(); | 41 delegate_ = context->sandbox_delegate(); |
42 update_observers_ = update_observers_.AddObserver( | 42 update_observers_ = update_observers_.AddObserver( |
43 sandbox_context_->quota_observer(), | 43 delegate_->quota_observer(), |
44 sandbox_context_->file_task_runner()); | 44 delegate_->file_task_runner()); |
45 syncable_update_observers_ = syncable_update_observers_.AddObserver( | 45 syncable_update_observers_ = syncable_update_observers_.AddObserver( |
46 sandbox_context_->quota_observer(), | 46 delegate_->quota_observer(), |
47 sandbox_context_->file_task_runner()); | 47 delegate_->file_task_runner()); |
48 } | 48 } |
49 | 49 |
50 void SyncFileSystemBackend::OpenFileSystem( | 50 void SyncFileSystemBackend::OpenFileSystem( |
51 const GURL& origin_url, | 51 const GURL& origin_url, |
52 fileapi::FileSystemType type, | 52 fileapi::FileSystemType type, |
53 fileapi::OpenFileSystemMode mode, | 53 fileapi::OpenFileSystemMode mode, |
54 const OpenFileSystemCallback& callback) { | 54 const OpenFileSystemCallback& callback) { |
55 DCHECK(CanHandleType(type)); | 55 DCHECK(CanHandleType(type)); |
56 DCHECK(sandbox_context_); | 56 DCHECK(delegate_); |
57 sandbox_context_->OpenFileSystem( | 57 delegate_->OpenFileSystem(origin_url, type, mode, callback, |
58 origin_url, type, mode, callback, | 58 GetSyncableFileSystemRootURI(origin_url)); |
59 GetSyncableFileSystemRootURI(origin_url)); | |
60 } | 59 } |
61 | 60 |
62 fileapi::FileSystemFileUtil* SyncFileSystemBackend::GetFileUtil( | 61 fileapi::FileSystemFileUtil* SyncFileSystemBackend::GetFileUtil( |
63 fileapi::FileSystemType type) { | 62 fileapi::FileSystemType type) { |
64 DCHECK(sandbox_context_); | 63 DCHECK(delegate_); |
65 return sandbox_context_->sync_file_util(); | 64 return delegate_->sync_file_util(); |
66 } | 65 } |
67 | 66 |
68 fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( | 67 fileapi::AsyncFileUtil* SyncFileSystemBackend::GetAsyncFileUtil( |
69 fileapi::FileSystemType type) { | 68 fileapi::FileSystemType type) { |
70 DCHECK(sandbox_context_); | 69 DCHECK(delegate_); |
71 return sandbox_context_->file_util(); | 70 return delegate_->file_util(); |
72 } | 71 } |
73 | 72 |
74 fileapi::CopyOrMoveFileValidatorFactory* | 73 fileapi::CopyOrMoveFileValidatorFactory* |
75 SyncFileSystemBackend::GetCopyOrMoveFileValidatorFactory( | 74 SyncFileSystemBackend::GetCopyOrMoveFileValidatorFactory( |
76 fileapi::FileSystemType type, | 75 fileapi::FileSystemType type, |
77 base::PlatformFileError* error_code) { | 76 base::PlatformFileError* error_code) { |
78 DCHECK(error_code); | 77 DCHECK(error_code); |
79 *error_code = base::PLATFORM_FILE_OK; | 78 *error_code = base::PLATFORM_FILE_OK; |
80 return NULL; | 79 return NULL; |
81 } | 80 } |
82 | 81 |
83 fileapi::FileSystemOperation* | 82 fileapi::FileSystemOperation* |
84 SyncFileSystemBackend::CreateFileSystemOperation( | 83 SyncFileSystemBackend::CreateFileSystemOperation( |
85 const fileapi::FileSystemURL& url, | 84 const fileapi::FileSystemURL& url, |
86 fileapi::FileSystemContext* context, | 85 fileapi::FileSystemContext* context, |
87 base::PlatformFileError* error_code) const { | 86 base::PlatformFileError* error_code) const { |
88 DCHECK(CanHandleType(url.type())); | 87 DCHECK(CanHandleType(url.type())); |
89 DCHECK(context); | 88 DCHECK(context); |
90 DCHECK(error_code); | 89 DCHECK(error_code); |
91 if (!sandbox_context_->IsAccessValid(url)) { | 90 if (!delegate_->IsAccessValid(url)) { |
92 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; | 91 *error_code = base::PLATFORM_FILE_ERROR_SECURITY; |
93 return NULL; | 92 return NULL; |
94 } | 93 } |
95 | 94 |
96 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( | 95 scoped_ptr<fileapi::FileSystemOperationContext> operation_context( |
97 new fileapi::FileSystemOperationContext(context)); | 96 new fileapi::FileSystemOperationContext(context)); |
98 | 97 |
99 if (url.type() == fileapi::kFileSystemTypeSyncableForInternalSync) { | 98 if (url.type() == fileapi::kFileSystemTypeSyncableForInternalSync) { |
100 operation_context->set_update_observers(update_observers_); | 99 operation_context->set_update_observers(update_observers_); |
101 operation_context->set_change_observers(change_observers_); | 100 operation_context->set_change_observers(change_observers_); |
102 return new fileapi::FileSystemOperationImpl( | 101 return new fileapi::FileSystemOperationImpl( |
103 url, context, operation_context.Pass()); | 102 url, context, operation_context.Pass()); |
104 } | 103 } |
105 | 104 |
106 operation_context->set_update_observers(syncable_update_observers_); | 105 operation_context->set_update_observers(syncable_update_observers_); |
107 operation_context->set_change_observers(syncable_change_observers_); | 106 operation_context->set_change_observers(syncable_change_observers_); |
108 return new SyncableFileSystemOperation( | 107 return new SyncableFileSystemOperation( |
109 url, context, operation_context.Pass()); | 108 url, context, operation_context.Pass()); |
110 } | 109 } |
111 | 110 |
112 scoped_ptr<webkit_blob::FileStreamReader> | 111 scoped_ptr<webkit_blob::FileStreamReader> |
113 SyncFileSystemBackend::CreateFileStreamReader( | 112 SyncFileSystemBackend::CreateFileStreamReader( |
114 const fileapi::FileSystemURL& url, | 113 const fileapi::FileSystemURL& url, |
115 int64 offset, | 114 int64 offset, |
116 const base::Time& expected_modification_time, | 115 const base::Time& expected_modification_time, |
117 fileapi::FileSystemContext* context) const { | 116 fileapi::FileSystemContext* context) const { |
118 DCHECK(CanHandleType(url.type())); | 117 DCHECK(CanHandleType(url.type())); |
119 if (!sandbox_context_->IsAccessValid(url)) | 118 if (!delegate_->IsAccessValid(url)) |
120 return scoped_ptr<webkit_blob::FileStreamReader>(); | 119 return scoped_ptr<webkit_blob::FileStreamReader>(); |
121 return scoped_ptr<webkit_blob::FileStreamReader>( | 120 return scoped_ptr<webkit_blob::FileStreamReader>( |
122 new fileapi::FileSystemFileStreamReader( | 121 new fileapi::FileSystemFileStreamReader( |
123 context, url, offset, expected_modification_time)); | 122 context, url, offset, expected_modification_time)); |
124 } | 123 } |
125 | 124 |
126 scoped_ptr<fileapi::FileStreamWriter> | 125 scoped_ptr<fileapi::FileStreamWriter> |
127 SyncFileSystemBackend::CreateFileStreamWriter( | 126 SyncFileSystemBackend::CreateFileStreamWriter( |
128 const fileapi::FileSystemURL& url, | 127 const fileapi::FileSystemURL& url, |
129 int64 offset, | 128 int64 offset, |
130 fileapi::FileSystemContext* context) const { | 129 fileapi::FileSystemContext* context) const { |
131 DCHECK(CanHandleType(url.type())); | 130 DCHECK(CanHandleType(url.type())); |
132 if (!sandbox_context_->IsAccessValid(url)) | 131 if (!delegate_->IsAccessValid(url)) |
133 return scoped_ptr<fileapi::FileStreamWriter>(); | 132 return scoped_ptr<fileapi::FileStreamWriter>(); |
134 return scoped_ptr<fileapi::FileStreamWriter>( | 133 return scoped_ptr<fileapi::FileStreamWriter>( |
135 new fileapi::SandboxFileStreamWriter( | 134 new fileapi::SandboxFileStreamWriter( |
136 context, url, offset, update_observers_)); | 135 context, url, offset, update_observers_)); |
137 } | 136 } |
138 | 137 |
139 fileapi::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { | 138 fileapi::FileSystemQuotaUtil* SyncFileSystemBackend::GetQuotaUtil() { |
140 return this; | 139 return this; |
141 } | 140 } |
142 | 141 |
143 base::PlatformFileError SyncFileSystemBackend::DeleteOriginDataOnFileThread( | 142 base::PlatformFileError SyncFileSystemBackend::DeleteOriginDataOnFileThread( |
144 fileapi::FileSystemContext* context, | 143 fileapi::FileSystemContext* context, |
145 quota::QuotaManagerProxy* proxy, | 144 quota::QuotaManagerProxy* proxy, |
146 const GURL& origin_url, | 145 const GURL& origin_url, |
147 fileapi::FileSystemType type) { | 146 fileapi::FileSystemType type) { |
148 DCHECK(CanHandleType(type)); | 147 DCHECK(CanHandleType(type)); |
149 DCHECK(sandbox_context_); | 148 DCHECK(delegate_); |
150 return sandbox_context_->DeleteOriginDataOnFileThread( | 149 return delegate_->DeleteOriginDataOnFileThread( |
151 context, proxy, origin_url, type); | 150 context, proxy, origin_url, type); |
152 } | 151 } |
153 | 152 |
154 void SyncFileSystemBackend::GetOriginsForTypeOnFileThread( | 153 void SyncFileSystemBackend::GetOriginsForTypeOnFileThread( |
155 fileapi::FileSystemType type, | 154 fileapi::FileSystemType type, |
156 std::set<GURL>* origins) { | 155 std::set<GURL>* origins) { |
157 DCHECK(CanHandleType(type)); | 156 DCHECK(CanHandleType(type)); |
158 DCHECK(sandbox_context_); | 157 DCHECK(delegate_); |
159 sandbox_context_->GetOriginsForTypeOnFileThread(type, origins); | 158 delegate_->GetOriginsForTypeOnFileThread(type, origins); |
160 } | 159 } |
161 | 160 |
162 void SyncFileSystemBackend::GetOriginsForHostOnFileThread( | 161 void SyncFileSystemBackend::GetOriginsForHostOnFileThread( |
163 fileapi::FileSystemType type, | 162 fileapi::FileSystemType type, |
164 const std::string& host, | 163 const std::string& host, |
165 std::set<GURL>* origins) { | 164 std::set<GURL>* origins) { |
166 DCHECK(CanHandleType(type)); | 165 DCHECK(CanHandleType(type)); |
167 DCHECK(sandbox_context_); | 166 DCHECK(delegate_); |
168 sandbox_context_->GetOriginsForHostOnFileThread(type, host, origins); | 167 delegate_->GetOriginsForHostOnFileThread(type, host, origins); |
169 } | 168 } |
170 | 169 |
171 int64 SyncFileSystemBackend::GetOriginUsageOnFileThread( | 170 int64 SyncFileSystemBackend::GetOriginUsageOnFileThread( |
172 fileapi::FileSystemContext* context, | 171 fileapi::FileSystemContext* context, |
173 const GURL& origin_url, | 172 const GURL& origin_url, |
174 fileapi::FileSystemType type) { | 173 fileapi::FileSystemType type) { |
175 DCHECK(CanHandleType(type)); | 174 DCHECK(CanHandleType(type)); |
176 DCHECK(sandbox_context_); | 175 DCHECK(delegate_); |
177 return sandbox_context_->GetOriginUsageOnFileThread( | 176 return delegate_->GetOriginUsageOnFileThread(context, origin_url, type); |
178 context, origin_url, type); | |
179 } | 177 } |
180 | 178 |
181 void SyncFileSystemBackend::AddFileUpdateObserver( | 179 void SyncFileSystemBackend::AddFileUpdateObserver( |
182 fileapi::FileSystemType type, | 180 fileapi::FileSystemType type, |
183 fileapi::FileUpdateObserver* observer, | 181 fileapi::FileUpdateObserver* observer, |
184 base::SequencedTaskRunner* task_runner) { | 182 base::SequencedTaskRunner* task_runner) { |
185 DCHECK_EQ(fileapi::kFileSystemTypeSyncable, type); | 183 DCHECK_EQ(fileapi::kFileSystemTypeSyncable, type); |
186 fileapi::UpdateObserverList* list = &syncable_update_observers_; | 184 fileapi::UpdateObserverList* list = &syncable_update_observers_; |
187 *list = list->AddObserver(observer, task_runner); | 185 *list = list->AddObserver(observer, task_runner); |
188 } | 186 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 file_system_context->GetFileSystemBackend( | 231 file_system_context->GetFileSystemBackend( |
234 fileapi::kFileSystemTypeSyncable)); | 232 fileapi::kFileSystemTypeSyncable)); |
235 } | 233 } |
236 | 234 |
237 void SyncFileSystemBackend::SetLocalFileChangeTracker( | 235 void SyncFileSystemBackend::SetLocalFileChangeTracker( |
238 scoped_ptr<LocalFileChangeTracker> tracker) { | 236 scoped_ptr<LocalFileChangeTracker> tracker) { |
239 DCHECK(!change_tracker_); | 237 DCHECK(!change_tracker_); |
240 DCHECK(tracker); | 238 DCHECK(tracker); |
241 change_tracker_ = tracker.Pass(); | 239 change_tracker_ = tracker.Pass(); |
242 | 240 |
243 DCHECK(sandbox_context_); | 241 DCHECK(delegate_); |
244 AddFileUpdateObserver( | 242 AddFileUpdateObserver(fileapi::kFileSystemTypeSyncable, |
245 fileapi::kFileSystemTypeSyncable, | 243 change_tracker_.get(), |
246 change_tracker_.get(), | 244 delegate_->file_task_runner()); |
247 sandbox_context_->file_task_runner()); | 245 AddFileChangeObserver(fileapi::kFileSystemTypeSyncable, |
248 AddFileChangeObserver( | 246 change_tracker_.get(), |
249 fileapi::kFileSystemTypeSyncable, | 247 delegate_->file_task_runner()); |
250 change_tracker_.get(), | |
251 sandbox_context_->file_task_runner()); | |
252 } | 248 } |
253 | 249 |
254 void SyncFileSystemBackend::set_sync_context( | 250 void SyncFileSystemBackend::set_sync_context( |
255 LocalFileSyncContext* sync_context) { | 251 LocalFileSyncContext* sync_context) { |
256 DCHECK(!sync_context_); | 252 DCHECK(!sync_context_); |
257 sync_context_ = sync_context; | 253 sync_context_ = sync_context; |
258 } | 254 } |
259 | 255 |
260 } // namespace sync_file_system | 256 } // namespace sync_file_system |
OLD | NEW |