| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/plugin_private_file_system_backend.h" | 5 #include "storage/browser/fileapi/plugin_private_file_system_backend.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/files/file_enumerator.h" |
| 14 #include "base/files/file_path.h" |
| 13 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 14 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 15 #include "base/task_runner_util.h" | 17 #include "base/task_runner_util.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "net/base/url_util.h" | 19 #include "net/base/url_util.h" |
| 18 #include "storage/browser/fileapi/async_file_util_adapter.h" | 20 #include "storage/browser/fileapi/async_file_util_adapter.h" |
| 19 #include "storage/browser/fileapi/file_stream_reader.h" | 21 #include "storage/browser/fileapi/file_stream_reader.h" |
| 20 #include "storage/browser/fileapi/file_stream_writer.h" | 22 #include "storage/browser/fileapi/file_stream_writer.h" |
| 21 #include "storage/browser/fileapi/file_system_context.h" | 23 #include "storage/browser/fileapi/file_system_context.h" |
| 22 #include "storage/browser/fileapi/file_system_operation.h" | 24 #include "storage/browser/fileapi/file_system_operation.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 while (!(origin = enumerator->Next()).is_empty()) { | 261 while (!(origin = enumerator->Next()).is_empty()) { |
| 260 if (host == net::GetHostOrSpecFromURL(origin)) | 262 if (host == net::GetHostOrSpecFromURL(origin)) |
| 261 origins->insert(origin); | 263 origins->insert(origin); |
| 262 } | 264 } |
| 263 } | 265 } |
| 264 | 266 |
| 265 int64_t PluginPrivateFileSystemBackend::GetOriginUsageOnFileTaskRunner( | 267 int64_t PluginPrivateFileSystemBackend::GetOriginUsageOnFileTaskRunner( |
| 266 FileSystemContext* context, | 268 FileSystemContext* context, |
| 267 const GURL& origin_url, | 269 const GURL& origin_url, |
| 268 FileSystemType type) { | 270 FileSystemType type) { |
| 269 // We don't track usage on this filesystem. | 271 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| 270 return 0; | 272 |
| 273 if (!CanHandleType(type)) |
| 274 return 0; |
| 275 |
| 276 int64_t total_size; |
| 277 base::Time last_modified_time; |
| 278 GetOriginDetailsOnFileTaskRunner(context, origin_url, &total_size, |
| 279 &last_modified_time); |
| 280 return total_size; |
| 281 } |
| 282 |
| 283 void PluginPrivateFileSystemBackend::GetOriginDetailsOnFileTaskRunner( |
| 284 FileSystemContext* context, |
| 285 const GURL& origin_url, |
| 286 int64_t* total_size, |
| 287 base::Time* last_modified_time) { |
| 288 DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| 289 |
| 290 *total_size = 0; |
| 291 *last_modified_time = base::Time::UnixEpoch(); |
| 292 std::string fsid = |
| 293 storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| 294 storage::kFileSystemTypePluginPrivate, "pluginprivate", |
| 295 base::FilePath()); |
| 296 DCHECK(storage::ValidateIsolatedFileSystemId(fsid)); |
| 297 |
| 298 std::string root = storage::GetIsolatedFileSystemRootURIString( |
| 299 origin_url, fsid, "pluginprivate"); |
| 300 |
| 301 std::unique_ptr<FileSystemOperationContext> operation_context( |
| 302 new FileSystemOperationContext(context)); |
| 303 |
| 304 // Determine the available plugin private filesystem directories for this |
| 305 // origin. Currently the plugin private filesystem is only used by Encrypted |
| 306 // Media Content Decryption Modules. Each CDM gets a directory based on the |
| 307 // mimetype (e.g. plugin application/x-ppapi-widevine-cdm uses directory |
| 308 // application_x-ppapi-widevine-cdm). Enumerate through the set of |
| 309 // directories so that data from any CDM used by this origin is counted. |
| 310 base::File::Error error; |
| 311 base::FilePath path = obfuscated_file_util()->GetDirectoryForOriginAndType( |
| 312 origin_url, "", false, &error); |
| 313 if (error != base::File::FILE_OK) { |
| 314 DLOG(ERROR) << "Unable to read directory for " << origin_url; |
| 315 return; |
| 316 } |
| 317 |
| 318 base::FileEnumerator directory_enumerator(path, false, |
| 319 base::FileEnumerator::DIRECTORIES); |
| 320 base::FilePath plugin_path; |
| 321 while (!(plugin_path = directory_enumerator.Next()).empty()) { |
| 322 std::string plugin_name = plugin_path.BaseName().MaybeAsASCII(); |
| 323 if (OpenFileSystemOnFileTaskRunner( |
| 324 obfuscated_file_util(), plugin_map_, origin_url, fsid, plugin_name, |
| 325 storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT) != |
| 326 base::File::FILE_OK) { |
| 327 continue; |
| 328 } |
| 329 |
| 330 std::unique_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( |
| 331 obfuscated_file_util()->CreateFileEnumerator( |
| 332 operation_context.get(), context->CrackURL(GURL(root)), true)); |
| 333 |
| 334 while (!enumerator->Next().empty()) { |
| 335 *total_size += enumerator->Size(); |
| 336 if (enumerator->LastModifiedTime() > *last_modified_time) |
| 337 *last_modified_time = enumerator->LastModifiedTime(); |
| 338 } |
| 339 } |
| 271 } | 340 } |
| 272 | 341 |
| 273 scoped_refptr<QuotaReservation> | 342 scoped_refptr<QuotaReservation> |
| 274 PluginPrivateFileSystemBackend::CreateQuotaReservationOnFileTaskRunner( | 343 PluginPrivateFileSystemBackend::CreateQuotaReservationOnFileTaskRunner( |
| 275 const GURL& origin_url, | 344 const GURL& origin_url, |
| 276 FileSystemType type) { | 345 FileSystemType type) { |
| 277 // We don't track usage on this filesystem. | 346 // We don't track usage on this filesystem. |
| 278 NOTREACHED(); | 347 NOTREACHED(); |
| 279 return scoped_refptr<QuotaReservation>(); | 348 return scoped_refptr<QuotaReservation>(); |
| 280 } | 349 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 293 FileSystemType type) const { | 362 FileSystemType type) const { |
| 294 return NULL; | 363 return NULL; |
| 295 } | 364 } |
| 296 | 365 |
| 297 ObfuscatedFileUtil* PluginPrivateFileSystemBackend::obfuscated_file_util() { | 366 ObfuscatedFileUtil* PluginPrivateFileSystemBackend::obfuscated_file_util() { |
| 298 return static_cast<ObfuscatedFileUtil*>( | 367 return static_cast<ObfuscatedFileUtil*>( |
| 299 static_cast<AsyncFileUtilAdapter*>(file_util_.get())->sync_file_util()); | 368 static_cast<AsyncFileUtilAdapter*>(file_util_.get())->sync_file_util()); |
| 300 } | 369 } |
| 301 | 370 |
| 302 } // namespace storage | 371 } // namespace storage |
| OLD | NEW |