| 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 "content/browser/fileapi/browser_file_system_helper.h" | 5 #include "content/browser/fileapi/browser_file_system_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
| 19 #include "webkit/fileapi/external_mount_points.h" | 19 #include "webkit/fileapi/external_mount_points.h" |
| 20 #include "webkit/fileapi/file_permission_policy.h" | 20 #include "webkit/fileapi/file_permission_policy.h" |
| 21 #include "webkit/fileapi/file_system_options.h" | 21 #include "webkit/fileapi/file_system_options.h" |
| 22 #include "webkit/fileapi/file_system_task_runners.h" | 22 #include "webkit/fileapi/file_system_task_runners.h" |
| 23 #include "webkit/fileapi/isolated_context.h" |
| 23 #include "webkit/fileapi/local_file_system_operation.h" | 24 #include "webkit/fileapi/local_file_system_operation.h" |
| 25 #include "webkit/fileapi/mount_points.h" |
| 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 26 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 25 #include "webkit/quota/quota_manager.h" | 27 #include "webkit/quota/quota_manager.h" |
| 26 | 28 |
| 29 #if defined(OS_CHROMEOS) |
| 30 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 31 #endif |
| 32 |
| 27 namespace content { | 33 namespace content { |
| 28 | 34 |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 using fileapi::FileSystemOptions; | 37 using fileapi::FileSystemOptions; |
| 32 | 38 |
| 33 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { | 39 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { |
| 34 FileSystemOptions::ProfileMode profile_mode = | 40 FileSystemOptions::ProfileMode profile_mode = |
| 35 is_incognito ? FileSystemOptions::PROFILE_MODE_INCOGNITO | 41 is_incognito ? FileSystemOptions::PROFILE_MODE_INCOGNITO |
| 36 : FileSystemOptions::PROFILE_MODE_NORMAL; | 42 : FileSystemOptions::PROFILE_MODE_NORMAL; |
| 37 std::vector<std::string> additional_allowed_schemes; | 43 std::vector<std::string> additional_allowed_schemes; |
| 38 GetContentClient()->browser()->GetAdditionalAllowedSchemesForFileSystem( | 44 GetContentClient()->browser()->GetAdditionalAllowedSchemesForFileSystem( |
| 39 &additional_allowed_schemes); | 45 &additional_allowed_schemes); |
| 40 if (CommandLine::ForCurrentProcess()->HasSwitch( | 46 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 41 switches::kAllowFileAccessFromFiles)) { | 47 switches::kAllowFileAccessFromFiles)) { |
| 42 additional_allowed_schemes.push_back(chrome::kFileScheme); | 48 additional_allowed_schemes.push_back(chrome::kFileScheme); |
| 43 } | 49 } |
| 44 return FileSystemOptions(profile_mode, additional_allowed_schemes); | 50 return FileSystemOptions(profile_mode, additional_allowed_schemes); |
| 45 } | 51 } |
| 46 | 52 |
| 47 } // namespace | 53 } // namespace |
| 48 | 54 |
| 49 scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( | 55 scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( |
| 50 const base::FilePath& profile_path, bool is_incognito, | 56 const base::FilePath& partition_path, |
| 51 fileapi::ExternalMountPoints* external_mount_points, | 57 bool is_incognito, |
| 52 quota::SpecialStoragePolicy* special_storage_policy, | 58 fileapi::ExternalMountPoints* external_mount_points, |
| 53 quota::QuotaManagerProxy* quota_manager_proxy) { | 59 quota::SpecialStoragePolicy* special_storage_policy, |
| 60 quota::QuotaManagerProxy* quota_manager_proxy) { |
| 54 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 61 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 55 base::SequencedWorkerPool::SequenceToken media_sequence_token = | 62 base::SequencedWorkerPool::SequenceToken media_sequence_token = |
| 56 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); | 63 pool->GetNamedSequenceToken(fileapi::kMediaTaskRunnerName); |
| 57 | 64 |
| 58 scoped_ptr<fileapi::FileSystemTaskRunners> task_runners( | 65 scoped_ptr<fileapi::FileSystemTaskRunners> task_runners( |
| 59 new fileapi::FileSystemTaskRunners( | 66 new fileapi::FileSystemTaskRunners( |
| 60 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 67 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 61 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 68 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 62 pool->GetSequencedTaskRunner(media_sequence_token))); | 69 pool->GetSequencedTaskRunner(media_sequence_token))); |
| 63 | 70 |
| 71 fileapi::FileSystemOptions options( |
| 72 CreateBrowserFileSystemOptions(is_incognito)); |
| 73 |
| 74 // Setting up mount points. |
| 75 std::vector<fileapi::MountPoints*> additional_mount_points; |
| 76 if (external_mount_points) |
| 77 additional_mount_points.push_back(external_mount_points); |
| 78 |
| 79 // Setting up additional mount point providers. |
| 80 ScopedVector<fileapi::FileSystemMountPointProvider> additional_providers; |
| 81 #if defined(OS_CHROMEOS) |
| 82 // TODO(kinuko): Move this to chrome/. |
| 83 additional_providers.push_back( |
| 84 new chromeos::CrosMountPointProvider( |
| 85 special_storage_policy, |
| 86 external_mount_points, |
| 87 fileapi::ExternalMountPoints::GetSystemInstance())); |
| 88 #endif |
| 89 |
| 64 return new fileapi::FileSystemContext( | 90 return new fileapi::FileSystemContext( |
| 65 task_runners.Pass(), | 91 task_runners.Pass(), |
| 66 external_mount_points, | |
| 67 special_storage_policy, | |
| 68 quota_manager_proxy, | 92 quota_manager_proxy, |
| 69 profile_path, | 93 additional_providers.Pass(), |
| 70 CreateBrowserFileSystemOptions(is_incognito)); | 94 additional_mount_points, |
| 95 partition_path, |
| 96 options); |
| 71 } | 97 } |
| 72 | 98 |
| 73 bool CheckFileSystemPermissionsForProcess( | 99 bool CheckFileSystemPermissionsForProcess( |
| 74 fileapi::FileSystemContext* context, int process_id, | 100 fileapi::FileSystemContext* context, int process_id, |
| 75 const fileapi::FileSystemURL& url, int permissions, | 101 const fileapi::FileSystemURL& url, int permissions, |
| 76 base::PlatformFileError* error) { | 102 base::PlatformFileError* error) { |
| 77 DCHECK(error); | 103 DCHECK(error); |
| 78 *error = base::PLATFORM_FILE_OK; | 104 *error = base::PLATFORM_FILE_OK; |
| 79 | 105 |
| 80 if (!url.is_valid()) { | 106 if (!url.is_valid()) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // for the file. (We first need to check if it can already be read not to | 183 // for the file. (We first need to check if it can already be read not to |
| 158 // overwrite existing permissions) | 184 // overwrite existing permissions) |
| 159 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 185 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 160 process_id, *platform_path)) { | 186 process_id, *platform_path)) { |
| 161 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | 187 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 162 process_id, *platform_path); | 188 process_id, *platform_path); |
| 163 } | 189 } |
| 164 } | 190 } |
| 165 | 191 |
| 166 } // namespace content | 192 } // namespace content |
| OLD | NEW |