| 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/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/isolated_mount_point_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "webkit/blob/local_file_stream_reader.h" | 15 #include "webkit/blob/local_file_stream_reader.h" |
| 16 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 16 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 17 #include "webkit/fileapi/file_system_context.h" | 17 #include "webkit/fileapi/file_system_context.h" |
| 18 #include "webkit/fileapi/file_system_file_stream_reader.h" | 18 #include "webkit/fileapi/file_system_file_stream_reader.h" |
| 19 #include "webkit/fileapi/file_system_operation.h" | 19 #include "webkit/fileapi/file_system_operation.h" |
| 20 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
| 21 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
| 22 #include "webkit/fileapi/isolated_context.h" | 22 #include "webkit/fileapi/isolated_context.h" |
| 23 #include "webkit/fileapi/isolated_file_util.h" | 23 #include "webkit/fileapi/isolated_file_util.h" |
| 24 #include "webkit/fileapi/local_file_stream_writer.h" | 24 #include "webkit/fileapi/local_file_stream_writer.h" |
| 25 #include "webkit/fileapi/native_file_util.h" | 25 #include "webkit/fileapi/native_file_util.h" |
| 26 | 26 |
| 27 namespace fileapi { | 27 namespace fileapi { |
| 28 | 28 |
| 29 namespace { |
| 30 |
| 31 IsolatedContext* isolated_context() { |
| 32 return IsolatedContext::GetInstance(); |
| 33 } |
| 34 |
| 35 FilePath GetPathFromURL(const GURL& url, bool for_writing) { |
| 36 GURL origin_url; |
| 37 FileSystemType file_system_type = kFileSystemTypeUnknown; |
| 38 FilePath virtual_path; |
| 39 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &virtual_path)) |
| 40 return FilePath(); |
| 41 std::string fsid; |
| 42 FilePath path; |
| 43 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) |
| 44 return FilePath(); |
| 45 if (for_writing && !isolated_context()->IsWritable(fsid)) |
| 46 return FilePath(); |
| 47 return path; |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 29 IsolatedMountPointProvider::IsolatedMountPointProvider() | 52 IsolatedMountPointProvider::IsolatedMountPointProvider() |
| 30 : isolated_file_util_(new IsolatedFileUtil()) { | 53 : isolated_file_util_(new IsolatedFileUtil()) { |
| 31 } | 54 } |
| 32 | 55 |
| 33 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 56 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 34 } | 57 } |
| 35 | 58 |
| 36 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 59 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 37 const GURL& origin_url, | 60 const GURL& origin_url, |
| 38 FileSystemType type, | 61 FileSystemType type, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const FilePath& virtual_path, | 123 const FilePath& virtual_path, |
| 101 FileSystemContext* context) const { | 124 FileSystemContext* context) const { |
| 102 return new FileSystemOperation(context); | 125 return new FileSystemOperation(context); |
| 103 } | 126 } |
| 104 | 127 |
| 105 webkit_blob::FileStreamReader* | 128 webkit_blob::FileStreamReader* |
| 106 IsolatedMountPointProvider::CreateFileStreamReader( | 129 IsolatedMountPointProvider::CreateFileStreamReader( |
| 107 const GURL& url, | 130 const GURL& url, |
| 108 int64 offset, | 131 int64 offset, |
| 109 FileSystemContext* context) const { | 132 FileSystemContext* context) const { |
| 110 FilePath path = GetPathFromURL(url); | 133 FilePath path = GetPathFromURL(url, false); |
| 111 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( | 134 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( |
| 112 context->file_task_runner(), path, offset, base::Time()); | 135 context->file_task_runner(), path, offset, base::Time()); |
| 113 } | 136 } |
| 114 | 137 |
| 115 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 138 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
| 116 const GURL& url, | 139 const GURL& url, |
| 117 int64 offset, | 140 int64 offset, |
| 118 FileSystemContext* context) const { | 141 FileSystemContext* context) const { |
| 119 FilePath path = GetPathFromURL(url); | 142 FilePath path = GetPathFromURL(url, true); |
| 120 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); | 143 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); |
| 121 } | 144 } |
| 122 | 145 |
| 123 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 146 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 124 // No quota support. | 147 // No quota support. |
| 125 return NULL; | 148 return NULL; |
| 126 } | 149 } |
| 127 | 150 |
| 128 IsolatedContext* IsolatedMountPointProvider::isolated_context() const { | |
| 129 return IsolatedContext::GetInstance(); | |
| 130 } | |
| 131 | |
| 132 FilePath IsolatedMountPointProvider::GetPathFromURL(const GURL& url) const { | |
| 133 GURL origin_url; | |
| 134 FileSystemType file_system_type = kFileSystemTypeUnknown; | |
| 135 FilePath virtual_path; | |
| 136 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &virtual_path)) | |
| 137 return FilePath(); | |
| 138 std::string fsid; | |
| 139 FilePath path; | |
| 140 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) | |
| 141 return FilePath(); | |
| 142 return path; | |
| 143 } | |
| 144 | |
| 145 } // namespace fileapi | 151 } // namespace fileapi |
| OLD | NEW |