Chromium Code Reviews| Index: storage/browser/fileapi/plugin_private_file_system_backend.cc |
| diff --git a/storage/browser/fileapi/plugin_private_file_system_backend.cc b/storage/browser/fileapi/plugin_private_file_system_backend.cc |
| index 06e9aefb3f1f49a0db1f66b796b502854e998cfb..e2e264b0198b9cecc6389666f9f968c71cbe57fb 100644 |
| --- a/storage/browser/fileapi/plugin_private_file_system_backend.cc |
| +++ b/storage/browser/fileapi/plugin_private_file_system_backend.cc |
| @@ -10,6 +10,8 @@ |
| #include <memory> |
| #include <utility> |
| +#include "base/files/file_enumerator.h" |
| +#include "base/files/file_path.h" |
| #include "base/stl_util.h" |
| #include "base/synchronization/lock.h" |
| #include "base/task_runner_util.h" |
| @@ -266,8 +268,76 @@ int64_t PluginPrivateFileSystemBackend::GetOriginUsageOnFileTaskRunner( |
| FileSystemContext* context, |
| const GURL& origin_url, |
| FileSystemType type) { |
| - // We don't track usage on this filesystem. |
| - return 0; |
| + DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| + |
| + if (!CanHandleType(type)) |
| + return 0; |
| + |
| + int64_t total_size; |
| + base::Time last_modified_time; |
| + GetOriginDetailsOnFileTaskRunner(context, origin_url, &total_size, |
| + &last_modified_time); |
| + return total_size; |
| +} |
| + |
| +void PluginPrivateFileSystemBackend::GetOriginDetailsOnFileTaskRunner( |
| + FileSystemContext* context, |
| + const GURL& origin_url, |
| + int64_t* total_size, |
| + base::Time* last_modified_time) { |
| + DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); |
| + |
| + *total_size = 0; |
| + *last_modified_time = base::Time::UnixEpoch(); |
| + std::string fsid = |
| + storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( |
| + storage::kFileSystemTypePluginPrivate, "pluginprivate", |
| + base::FilePath()); |
| + DCHECK(storage::ValidateIsolatedFileSystemId(fsid)); |
| + |
| + std::string root = storage::GetIsolatedFileSystemRootURIString( |
| + origin_url, fsid, "pluginprivate"); |
| + |
| + std::unique_ptr<FileSystemOperationContext> operation_context( |
| + new FileSystemOperationContext(context)); |
| + |
| + // Determine the available plugin private filesystem directories for this |
| + // origin. Currently the plugin private filesystem is only used by Encrypted |
| + // Media Content Decryption Modules. Each CDM gets a directory based on the |
| + // mimetype (e.g. plugin application/x-ppapi-widevine-cdm uses directory |
| + // application_x-ppapi-widevine-cdm). Enumerate through the set of |
| + // directories so that data from any CDM used by this origin is deleted. |
|
nhiroki
2016/10/04 08:42:43
The last sentence ("... is deleted") is not approp
jrummell
2016/10/04 19:46:57
Done.
|
| + base::File::Error error; |
| + base::FilePath path = obfuscated_file_util()->GetDirectoryForOriginAndType( |
| + origin_url, "", false, &error); |
| + if (error != base::File::FILE_OK) { |
| + DLOG(ERROR) << "Unable to read directory for " << origin_url; |
| + return; |
| + } |
| + |
| + base::FileEnumerator directory_enumerator(path, false, |
| + base::FileEnumerator::DIRECTORIES); |
| + base::FilePath plugin_path; |
| + while (!(plugin_path = directory_enumerator.Next()).empty()) { |
| + std::string plugin_name = plugin_path.BaseName().MaybeAsASCII(); |
| + if (OpenFileSystemOnFileTaskRunner( |
| + obfuscated_file_util(), plugin_map_, origin_url, fsid, plugin_name, |
| + storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT) != |
| + base::File::FILE_OK) { |
| + continue; |
| + } |
| + |
| + std::unique_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( |
| + obfuscated_file_util()->CreateFileEnumerator( |
| + operation_context.get(), context->CrackURL(GURL(root)), true)); |
| + |
| + base::FilePath current; |
| + while (!(current = enumerator->Next()).empty()) { |
|
nhiroki
2016/10/04 08:53:53
|current| is not used.
jrummell
2016/10/04 19:46:57
Removed. I was using it to log the file name while
|
| + *total_size += enumerator->Size(); |
| + if (enumerator->LastModifiedTime() > *last_modified_time) |
| + *last_modified_time = enumerator->LastModifiedTime(); |
| + } |
| + } |
| } |
| scoped_refptr<QuotaReservation> |