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 #include "webkit/fileapi/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
13 #include "webkit/blob/shareable_file_reference.h" | 13 #include "webkit/blob/shareable_file_reference.h" |
14 #include "webkit/fileapi/file_system_context.h" | 14 #include "webkit/fileapi/file_system_context.h" |
15 #include "webkit/fileapi/file_system_file_util_proxy.h" | 15 #include "webkit/fileapi/file_system_file_util_proxy.h" |
16 #include "webkit/fileapi/file_system_mount_point_provider.h" | 16 #include "webkit/fileapi/file_system_mount_point_provider.h" |
17 #include "webkit/fileapi/file_system_operation_context.h" | 17 #include "webkit/fileapi/file_system_operation_context.h" |
18 #include "webkit/fileapi/file_system_quota_util.h" | 18 #include "webkit/fileapi/file_system_quota_util.h" |
19 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
20 #include "webkit/fileapi/file_system_url.h" | 20 #include "webkit/fileapi/file_system_url.h" |
21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
22 #include "webkit/fileapi/file_writer_delegate.h" | 22 #include "webkit/fileapi/file_writer_delegate.h" |
23 #include "webkit/fileapi/sandbox_file_stream_writer.h" | 23 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
24 #include "webkit/quota/quota_manager.h" | 24 #include "webkit/quota/quota_manager.h" |
25 #include "webkit/quota/quota_types.h" | 25 #include "webkit/quota/quota_types.h" |
26 | 26 |
27 namespace fileapi { | 27 namespace fileapi { |
28 | 28 |
29 namespace { | |
30 | |
31 bool IsMediaFileSystemType(FileSystemType type) { | |
32 return type == kFileSystemTypeNativeMedia || | |
33 type == kFileSystemTypeDeviceMedia; | |
34 } | |
35 | |
36 // TODO(tzik): Cleanup this. | |
37 base::PlatformFileError IsCompatibleFileSystemPair(FileSystemType src_type, | |
kinuko
2012/08/03 23:13:39
nit: IsCrossOperationAllowed(src, dest) ...? Also
tzik
2012/08/04 00:24:21
Done.
| |
38 FileSystemType dest_type) { | |
39 return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type) ? | |
40 base::PLATFORM_FILE_OK : | |
41 base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
42 | |
kinuko
2012/08/03 23:13:39
nit: extra empty line
tzik
2012/08/04 00:24:21
Done.
| |
43 } | |
44 | |
45 } // namespace | |
46 | |
29 class LocalFileSystemOperation::ScopedQuotaNotifier { | 47 class LocalFileSystemOperation::ScopedQuotaNotifier { |
30 public: | 48 public: |
31 ScopedQuotaNotifier(FileSystemContext* context, | 49 ScopedQuotaNotifier(FileSystemContext* context, |
32 const GURL& origin_url, | 50 const GURL& origin_url, |
33 FileSystemType type); | 51 FileSystemType type); |
34 ~ScopedQuotaNotifier(); | 52 ~ScopedQuotaNotifier(); |
35 | 53 |
36 private: | 54 private: |
37 // Not owned; owned by the owner of this instance | 55 // Not owned; owned by the owner of this instance |
38 // (i.e. LocalFileSystemOperation). | 56 // (i.e. LocalFileSystemOperation). |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 127 } |
110 | 128 |
111 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, | 129 void LocalFileSystemOperation::Copy(const FileSystemURL& src_url, |
112 const FileSystemURL& dest_url, | 130 const FileSystemURL& dest_url, |
113 const StatusCallback& callback) { | 131 const StatusCallback& callback) { |
114 DCHECK(SetPendingOperationType(kOperationCopy)); | 132 DCHECK(SetPendingOperationType(kOperationCopy)); |
115 | 133 |
116 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); | 134 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ); |
117 if (result == base::PLATFORM_FILE_OK) | 135 if (result == base::PLATFORM_FILE_OK) |
118 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 136 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
137 if (result == base::PLATFORM_FILE_OK) | |
138 result = IsCompatibleFileSystemPair(src_url.type(), dest_url.type()); | |
119 if (result != base::PLATFORM_FILE_OK) { | 139 if (result != base::PLATFORM_FILE_OK) { |
120 callback.Run(result); | 140 callback.Run(result); |
121 delete this; | 141 delete this; |
122 return; | 142 return; |
123 } | 143 } |
124 | 144 |
125 GetUsageAndQuotaThenRunTask( | 145 GetUsageAndQuotaThenRunTask( |
126 dest_url, | 146 dest_url, |
127 base::Bind(&LocalFileSystemOperation::DoCopy, | 147 base::Bind(&LocalFileSystemOperation::DoCopy, |
128 base::Unretained(this), src_url, dest_url, callback), | 148 base::Unretained(this), src_url, dest_url, callback), |
129 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); | 149 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED)); |
130 } | 150 } |
131 | 151 |
132 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, | 152 void LocalFileSystemOperation::Move(const FileSystemURL& src_url, |
133 const FileSystemURL& dest_url, | 153 const FileSystemURL& dest_url, |
134 const StatusCallback& callback) { | 154 const StatusCallback& callback) { |
135 DCHECK(SetPendingOperationType(kOperationMove)); | 155 DCHECK(SetPendingOperationType(kOperationMove)); |
136 scoped_ptr<LocalFileSystemOperation> deleter(this); | 156 scoped_ptr<LocalFileSystemOperation> deleter(this); |
137 | 157 |
138 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); | 158 base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE); |
139 if (result == base::PLATFORM_FILE_OK) | 159 if (result == base::PLATFORM_FILE_OK) |
140 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); | 160 result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE); |
161 if (result == base::PLATFORM_FILE_OK) | |
162 result = IsCompatibleFileSystemPair(src_url.type(), dest_url.type()); | |
141 if (result != base::PLATFORM_FILE_OK) { | 163 if (result != base::PLATFORM_FILE_OK) { |
142 callback.Run(result); | 164 callback.Run(result); |
143 return; | 165 return; |
144 } | 166 } |
145 | 167 |
146 // Temporarily disables cross-filesystem move for sandbox filesystems. | 168 // Temporarily disables cross-filesystem move for sandbox filesystems. |
147 // TODO(kinuko,tzik,kinaba): This special handling must be removed once | 169 // TODO(kinuko,tzik,kinaba): This special handling must be removed once |
148 // we support saner cross-filesystem operation. | 170 // we support saner cross-filesystem operation. |
149 // (See http://crbug.com/130055) | 171 // (See http://crbug.com/130055) |
150 if (src_url.type() != dest_url.type() && | 172 if (src_url.type() != dest_url.type() && |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 } | 754 } |
733 | 755 |
734 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { | 756 bool LocalFileSystemOperation::SetPendingOperationType(OperationType type) { |
735 if (pending_operation_ != kOperationNone) | 757 if (pending_operation_ != kOperationNone) |
736 return false; | 758 return false; |
737 pending_operation_ = type; | 759 pending_operation_ = type; |
738 return true; | 760 return true; |
739 } | 761 } |
740 | 762 |
741 } // namespace fileapi | 763 } // namespace fileapi |
OLD | NEW |