| 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/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 20 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 21 #include "webkit/browser/fileapi/external_mount_points.h" | 21 #include "webkit/browser/fileapi/external_mount_points.h" |
| 22 #include "webkit/browser/fileapi/file_permission_policy.h" | 22 #include "webkit/browser/fileapi/file_permission_policy.h" |
| 23 #include "webkit/browser/fileapi/file_system_backend.h" | 23 #include "webkit/browser/fileapi/file_system_backend.h" |
| 24 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 24 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 25 #include "webkit/browser/fileapi/file_system_options.h" | 25 #include "webkit/browser/fileapi/file_system_options.h" |
| 26 #include "webkit/browser/fileapi/file_system_task_runners.h" | |
| 27 #include "webkit/browser/quota/quota_manager.h" | 26 #include "webkit/browser/quota/quota_manager.h" |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 using fileapi::FileSystemOptions; | 32 using fileapi::FileSystemOptions; |
| 34 | 33 |
| 35 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { | 34 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { |
| 36 FileSystemOptions::ProfileMode profile_mode = | 35 FileSystemOptions::ProfileMode profile_mode = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 51 scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( | 50 scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( |
| 52 BrowserContext* browser_context, | 51 BrowserContext* browser_context, |
| 53 const base::FilePath& profile_path, | 52 const base::FilePath& profile_path, |
| 54 bool is_incognito, | 53 bool is_incognito, |
| 55 quota::QuotaManagerProxy* quota_manager_proxy) { | 54 quota::QuotaManagerProxy* quota_manager_proxy) { |
| 56 | 55 |
| 57 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); | 56 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
| 58 scoped_refptr<base::SequencedTaskRunner> file_task_runner = | 57 scoped_refptr<base::SequencedTaskRunner> file_task_runner = |
| 59 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken("FileAPI")); | 58 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken("FileAPI")); |
| 60 | 59 |
| 61 scoped_ptr<fileapi::FileSystemTaskRunners> task_runners( | |
| 62 new fileapi::FileSystemTaskRunners( | |
| 63 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), | |
| 64 file_task_runner.get())); | |
| 65 | |
| 66 // Setting up additional filesystem backends. | 60 // Setting up additional filesystem backends. |
| 67 ScopedVector<fileapi::FileSystemBackend> additional_backends; | 61 ScopedVector<fileapi::FileSystemBackend> additional_backends; |
| 68 GetContentClient()->browser()->GetAdditionalFileSystemBackends( | 62 GetContentClient()->browser()->GetAdditionalFileSystemBackends( |
| 69 browser_context, | 63 browser_context, |
| 70 profile_path, | 64 profile_path, |
| 71 &additional_backends); | 65 &additional_backends); |
| 72 | 66 |
| 73 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 67 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 74 new fileapi::FileSystemContext( | 68 new fileapi::FileSystemContext( |
| 75 task_runners.Pass(), | 69 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
| 70 file_task_runner.get(), |
| 76 BrowserContext::GetMountPoints(browser_context), | 71 BrowserContext::GetMountPoints(browser_context), |
| 77 browser_context->GetSpecialStoragePolicy(), | 72 browser_context->GetSpecialStoragePolicy(), |
| 78 quota_manager_proxy, | 73 quota_manager_proxy, |
| 79 additional_backends.Pass(), | 74 additional_backends.Pass(), |
| 80 profile_path, | 75 profile_path, |
| 81 CreateBrowserFileSystemOptions(is_incognito)); | 76 CreateBrowserFileSystemOptions(is_incognito)); |
| 82 | 77 |
| 83 std::vector<fileapi::FileSystemType> types; | 78 std::vector<fileapi::FileSystemType> types; |
| 84 file_system_context->GetFileSystemTypes(&types); | 79 file_system_context->GetFileSystemTypes(&types); |
| 85 for (size_t i = 0; i < types.size(); ++i) { | 80 for (size_t i = 0; i < types.size(); ++i) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 114 } |
| 120 | 115 |
| 121 *error = base::PLATFORM_FILE_OK; | 116 *error = base::PLATFORM_FILE_OK; |
| 122 return true; | 117 return true; |
| 123 } | 118 } |
| 124 | 119 |
| 125 void SyncGetPlatformPath(fileapi::FileSystemContext* context, | 120 void SyncGetPlatformPath(fileapi::FileSystemContext* context, |
| 126 int process_id, | 121 int process_id, |
| 127 const GURL& path, | 122 const GURL& path, |
| 128 base::FilePath* platform_path) { | 123 base::FilePath* platform_path) { |
| 129 DCHECK(context->task_runners()->file_task_runner()-> | 124 DCHECK(context->default_file_task_runner()-> |
| 130 RunsTasksOnCurrentThread()); | 125 RunsTasksOnCurrentThread()); |
| 131 DCHECK(platform_path); | 126 DCHECK(platform_path); |
| 132 *platform_path = base::FilePath(); | 127 *platform_path = base::FilePath(); |
| 133 fileapi::FileSystemURL url(context->CrackURL(path)); | 128 fileapi::FileSystemURL url(context->CrackURL(path)); |
| 134 if (!FileSystemURLIsValid(context, url)) | 129 if (!FileSystemURLIsValid(context, url)) |
| 135 return; | 130 return; |
| 136 | 131 |
| 137 // Make sure if this file is ok to be read (in the current architecture | 132 // Make sure if this file is ok to be read (in the current architecture |
| 138 // which means roughly same as the renderer is allowed to get the platform | 133 // which means roughly same as the renderer is allowed to get the platform |
| 139 // path to the file). | 134 // path to the file). |
| 140 ChildProcessSecurityPolicyImpl* policy = | 135 ChildProcessSecurityPolicyImpl* policy = |
| 141 ChildProcessSecurityPolicyImpl::GetInstance(); | 136 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 142 if (!policy->CanReadFileSystemFile(process_id, url)) | 137 if (!policy->CanReadFileSystemFile(process_id, url)) |
| 143 return; | 138 return; |
| 144 | 139 |
| 145 context->operation_runner()->SyncGetPlatformPath(url, platform_path); | 140 context->operation_runner()->SyncGetPlatformPath(url, platform_path); |
| 146 | 141 |
| 147 // The path is to be attached to URLLoader so we grant read permission | 142 // The path is to be attached to URLLoader so we grant read permission |
| 148 // for the file. (We need to check first because a parent directory may | 143 // for the file. (We need to check first because a parent directory may |
| 149 // already have the permissions and we don't need to grant it to the file.) | 144 // already have the permissions and we don't need to grant it to the file.) |
| 150 if (!policy->CanReadFile(process_id, *platform_path)) | 145 if (!policy->CanReadFile(process_id, *platform_path)) |
| 151 policy->GrantReadFile(process_id, *platform_path); | 146 policy->GrantReadFile(process_id, *platform_path); |
| 152 } | 147 } |
| 153 | 148 |
| 154 } // namespace content | 149 } // namespace content |
| OLD | NEW |