| 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/browser/fileapi/file_system_quota_client.h" | 5 #include "storage/browser/fileapi/file_system_quota_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 #include "webkit/browser/fileapi/file_system_context.h" | 21 #include "storage/browser/fileapi/file_system_context.h" |
| 22 #include "webkit/browser/fileapi/file_system_quota_util.h" | 22 #include "storage/browser/fileapi/file_system_quota_util.h" |
| 23 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 23 #include "storage/browser/fileapi/file_system_usage_cache.h" |
| 24 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 24 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
| 25 #include "webkit/common/fileapi/file_system_util.h" | 25 #include "storage/common/fileapi/file_system_util.h" |
| 26 | 26 |
| 27 using quota::StorageType; | 27 using quota::StorageType; |
| 28 | 28 |
| 29 namespace fileapi { | 29 namespace storage { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 void GetOriginsForTypeOnFileTaskRunner( | 33 void GetOriginsForTypeOnFileTaskRunner(FileSystemContext* context, |
| 34 FileSystemContext* context, | 34 StorageType storage_type, |
| 35 StorageType storage_type, | 35 std::set<GURL>* origins_ptr) { |
| 36 std::set<GURL>* origins_ptr) { | |
| 37 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 36 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 38 DCHECK(type != kFileSystemTypeUnknown); | 37 DCHECK(type != kFileSystemTypeUnknown); |
| 39 | 38 |
| 40 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); | 39 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); |
| 41 if (!quota_util) | 40 if (!quota_util) |
| 42 return; | 41 return; |
| 43 quota_util->GetOriginsForTypeOnFileTaskRunner(type, origins_ptr); | 42 quota_util->GetOriginsForTypeOnFileTaskRunner(type, origins_ptr); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void GetOriginsForHostOnFileTaskRunner( | 45 void GetOriginsForHostOnFileTaskRunner(FileSystemContext* context, |
| 47 FileSystemContext* context, | 46 StorageType storage_type, |
| 48 StorageType storage_type, | 47 const std::string& host, |
| 49 const std::string& host, | 48 std::set<GURL>* origins_ptr) { |
| 50 std::set<GURL>* origins_ptr) { | |
| 51 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 49 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 52 DCHECK(type != kFileSystemTypeUnknown); | 50 DCHECK(type != kFileSystemTypeUnknown); |
| 53 | 51 |
| 54 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); | 52 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); |
| 55 if (!quota_util) | 53 if (!quota_util) |
| 56 return; | 54 return; |
| 57 quota_util->GetOriginsForHostOnFileTaskRunner(type, host, origins_ptr); | 55 quota_util->GetOriginsForHostOnFileTaskRunner(type, host, origins_ptr); |
| 58 } | 56 } |
| 59 | 57 |
| 60 void DidGetOrigins( | 58 void DidGetOrigins(const quota::QuotaClient::GetOriginsCallback& callback, |
| 61 const quota::QuotaClient::GetOriginsCallback& callback, | 59 std::set<GURL>* origins_ptr) { |
| 62 std::set<GURL>* origins_ptr) { | |
| 63 callback.Run(*origins_ptr); | 60 callback.Run(*origins_ptr); |
| 64 } | 61 } |
| 65 | 62 |
| 66 quota::QuotaStatusCode DeleteOriginOnFileTaskRunner( | 63 quota::QuotaStatusCode DeleteOriginOnFileTaskRunner(FileSystemContext* context, |
| 67 FileSystemContext* context, | 64 const GURL& origin, |
| 68 const GURL& origin, | 65 FileSystemType type) { |
| 69 FileSystemType type) { | |
| 70 FileSystemBackend* provider = context->GetFileSystemBackend(type); | 66 FileSystemBackend* provider = context->GetFileSystemBackend(type); |
| 71 if (!provider || !provider->GetQuotaUtil()) | 67 if (!provider || !provider->GetQuotaUtil()) |
| 72 return quota::kQuotaErrorNotSupported; | 68 return quota::kQuotaErrorNotSupported; |
| 73 base::File::Error result = | 69 base::File::Error result = |
| 74 provider->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner( | 70 provider->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner( |
| 75 context, context->quota_manager_proxy(), origin, type); | 71 context, context->quota_manager_proxy(), origin, type); |
| 76 if (result == base::File::FILE_OK) | 72 if (result == base::File::FILE_OK) |
| 77 return quota::kQuotaStatusOk; | 73 return quota::kQuotaStatusOk; |
| 78 return quota::kQuotaErrorInvalidModification; | 74 return quota::kQuotaErrorInvalidModification; |
| 79 } | 75 } |
| 80 | 76 |
| 81 } // namespace | 77 } // namespace |
| 82 | 78 |
| 83 FileSystemQuotaClient::FileSystemQuotaClient( | 79 FileSystemQuotaClient::FileSystemQuotaClient( |
| 84 FileSystemContext* file_system_context, | 80 FileSystemContext* file_system_context, |
| 85 bool is_incognito) | 81 bool is_incognito) |
| 86 : file_system_context_(file_system_context), | 82 : file_system_context_(file_system_context), is_incognito_(is_incognito) { |
| 87 is_incognito_(is_incognito) { | |
| 88 } | 83 } |
| 89 | 84 |
| 90 FileSystemQuotaClient::~FileSystemQuotaClient() {} | 85 FileSystemQuotaClient::~FileSystemQuotaClient() { |
| 86 } |
| 91 | 87 |
| 92 quota::QuotaClient::ID FileSystemQuotaClient::id() const { | 88 quota::QuotaClient::ID FileSystemQuotaClient::id() const { |
| 93 return quota::QuotaClient::kFileSystem; | 89 return quota::QuotaClient::kFileSystem; |
| 94 } | 90 } |
| 95 | 91 |
| 96 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { | 92 void FileSystemQuotaClient::OnQuotaManagerDestroyed() { |
| 97 delete this; | 93 delete this; |
| 98 } | 94 } |
| 99 | 95 |
| 100 void FileSystemQuotaClient::GetOriginUsage( | 96 void FileSystemQuotaClient::GetOriginUsage(const GURL& origin_url, |
| 101 const GURL& origin_url, | 97 StorageType storage_type, |
| 102 StorageType storage_type, | 98 const GetUsageCallback& callback) { |
| 103 const GetUsageCallback& callback) { | |
| 104 DCHECK(!callback.is_null()); | 99 DCHECK(!callback.is_null()); |
| 105 | 100 |
| 106 if (is_incognito_) { | 101 if (is_incognito_) { |
| 107 // We don't support FileSystem in incognito mode yet. | 102 // We don't support FileSystem in incognito mode yet. |
| 108 callback.Run(0); | 103 callback.Run(0); |
| 109 return; | 104 return; |
| 110 } | 105 } |
| 111 | 106 |
| 112 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 107 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 113 DCHECK(type != kFileSystemTypeUnknown); | 108 DCHECK(type != kFileSystemTypeUnknown); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 142 return; | 137 return; |
| 143 } | 138 } |
| 144 | 139 |
| 145 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 140 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
| 146 file_task_runner()->PostTaskAndReply( | 141 file_task_runner()->PostTaskAndReply( |
| 147 FROM_HERE, | 142 FROM_HERE, |
| 148 base::Bind(&GetOriginsForTypeOnFileTaskRunner, | 143 base::Bind(&GetOriginsForTypeOnFileTaskRunner, |
| 149 file_system_context_, | 144 file_system_context_, |
| 150 storage_type, | 145 storage_type, |
| 151 base::Unretained(origins_ptr)), | 146 base::Unretained(origins_ptr)), |
| 152 base::Bind(&DidGetOrigins, | 147 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
| 153 callback, | |
| 154 base::Owned(origins_ptr))); | |
| 155 } | 148 } |
| 156 | 149 |
| 157 void FileSystemQuotaClient::GetOriginsForHost( | 150 void FileSystemQuotaClient::GetOriginsForHost( |
| 158 StorageType storage_type, | 151 StorageType storage_type, |
| 159 const std::string& host, | 152 const std::string& host, |
| 160 const GetOriginsCallback& callback) { | 153 const GetOriginsCallback& callback) { |
| 161 DCHECK(!callback.is_null()); | 154 DCHECK(!callback.is_null()); |
| 162 | 155 |
| 163 if (is_incognito_) { | 156 if (is_incognito_) { |
| 164 // We don't support FileSystem in incognito mode yet. | 157 // We don't support FileSystem in incognito mode yet. |
| 165 std::set<GURL> origins; | 158 std::set<GURL> origins; |
| 166 callback.Run(origins); | 159 callback.Run(origins); |
| 167 return; | 160 return; |
| 168 } | 161 } |
| 169 | 162 |
| 170 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 163 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
| 171 file_task_runner()->PostTaskAndReply( | 164 file_task_runner()->PostTaskAndReply( |
| 172 FROM_HERE, | 165 FROM_HERE, |
| 173 base::Bind(&GetOriginsForHostOnFileTaskRunner, | 166 base::Bind(&GetOriginsForHostOnFileTaskRunner, |
| 174 file_system_context_, | 167 file_system_context_, |
| 175 storage_type, | 168 storage_type, |
| 176 host, | 169 host, |
| 177 base::Unretained(origins_ptr)), | 170 base::Unretained(origins_ptr)), |
| 178 base::Bind(&DidGetOrigins, | 171 base::Bind(&DidGetOrigins, callback, base::Owned(origins_ptr))); |
| 179 callback, | |
| 180 base::Owned(origins_ptr))); | |
| 181 } | 172 } |
| 182 | 173 |
| 183 void FileSystemQuotaClient::DeleteOriginData( | 174 void FileSystemQuotaClient::DeleteOriginData(const GURL& origin, |
| 184 const GURL& origin, | 175 StorageType type, |
| 185 StorageType type, | 176 const DeletionCallback& callback) { |
| 186 const DeletionCallback& callback) { | |
| 187 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 177 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
| 188 DCHECK(fs_type != kFileSystemTypeUnknown); | 178 DCHECK(fs_type != kFileSystemTypeUnknown); |
| 189 | 179 |
| 190 base::PostTaskAndReplyWithResult( | 180 base::PostTaskAndReplyWithResult( |
| 191 file_task_runner(), | 181 file_task_runner(), |
| 192 FROM_HERE, | 182 FROM_HERE, |
| 193 base::Bind(&DeleteOriginOnFileTaskRunner, | 183 base::Bind( |
| 194 file_system_context_, | 184 &DeleteOriginOnFileTaskRunner, file_system_context_, origin, fs_type), |
| 195 origin, | |
| 196 fs_type), | |
| 197 callback); | 185 callback); |
| 198 } | 186 } |
| 199 | 187 |
| 200 bool FileSystemQuotaClient::DoesSupport(quota::StorageType storage_type) const { | 188 bool FileSystemQuotaClient::DoesSupport(quota::StorageType storage_type) const { |
| 201 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 189 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
| 202 DCHECK(type != kFileSystemTypeUnknown); | 190 DCHECK(type != kFileSystemTypeUnknown); |
| 203 return file_system_context_->IsSandboxFileSystem(type); | 191 return file_system_context_->IsSandboxFileSystem(type); |
| 204 } | 192 } |
| 205 | 193 |
| 206 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { | 194 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { |
| 207 return file_system_context_->default_file_task_runner(); | 195 return file_system_context_->default_file_task_runner(); |
| 208 } | 196 } |
| 209 | 197 |
| 210 } // namespace fileapi | 198 } // namespace storage |
| OLD | NEW |