Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: content/browser/storage_partition_impl.cc

Issue 1979733002: Add ability to clear content licenses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/storage_partition_impl.cc
diff --git a/content/browser/storage_partition_impl.cc b/content/browser/storage_partition_impl.cc
index 65bf56140be1ff27696d83e7f5f483486b15345b..e26a224c3803a0bd8948e4fb700d826daccfe39a 100644
--- a/content/browser/storage_partition_impl.cc
+++ b/content/browser/storage_partition_impl.cc
@@ -34,12 +34,19 @@
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "storage/browser/database/database_tracker.h"
+#include "storage/browser/fileapi/async_file_util.h"
+#include "storage/browser/fileapi/isolated_context.h"
#include "storage/browser/quota/quota_manager.h"
+#include "storage/common/fileapi/file_system_util.h"
namespace content {
namespace {
+const char kPluginPrivateRootName[] = "pluginprivate";
xhwang 2016/05/16 17:35:23 Is this documented anywhere? Where is this magic s
jrummell 2016/05/19 00:45:57 It comes from the pepper code, that converts the p
+const char kWidevineCdmPluginId[] = "application_x-ppapi-widevine-cdm";
+const char kClearKeyCdmPluginId[] = "application_x-ppapi-clearkey-cdm";
xhwang 2016/05/16 17:35:23 In other places the pepper type is application/x-p
jrummell 2016/05/19 00:45:56 The conversion is done in GeneratePluginId [1] whi
+
bool DoesCookieMatchHost(const std::string& host,
const net::CanonicalCookie& cookie) {
return cookie.IsHostCookie() && cookie.IsDomainMatch(host);
@@ -215,6 +222,325 @@ void ClearSessionStorageOnUIThread(
callback));
}
+// Helper for deleting content licenses for a specified origin and plugin.
+// If any file matches the time range specified, then all files for this
+// origin and plugin are deleted.
+// All of the operations in this class are done on the FILE thread.
+class PluginPrivateContentLicensesDeletionHelper {
xhwang 2016/05/16 17:35:23 About naming: The UI is TBD and is subject to chan
jrummell 2016/05/19 00:45:56 Done.
+ public:
+ PluginPrivateContentLicensesDeletionHelper(
+ const scoped_refptr<storage::FileSystemContext>& filesystem_context,
+ const GURL& origin,
+ const std::string& plugin_name,
+ const base::Time begin,
+ const base::Time end,
+ const base::Closure& callback)
+ : filesystem_context_(std::move(filesystem_context)),
+ origin_(origin),
+ plugin_name_(plugin_name),
+ begin_(begin),
+ end_(end),
+ callback_(callback) {
+ // Create the filesystem ID.
+ fsid_ = storage::IsolatedContext::GetInstance()
+ ->RegisterFileSystemForVirtualPath(
+ storage::kFileSystemTypePluginPrivate,
+ kPluginPrivateRootName, base::FilePath());
+ }
+ ~PluginPrivateContentLicensesDeletionHelper() {}
+
+ // Checks the files contained in the plugin private filesystem for |origin_|
+ // and |plugin_name_| and deletes any files whose last modified time is
+ // greater or equal to |begin_|. |callback_| is called when all actions
+ // are complete.
+ void Start();
+
+ private:
+ void OnFileSystemOpened(base::File::Error result);
+ void OnDirectoryRead(const std::string& root,
+ base::File::Error result,
+ const storage::AsyncFileUtil::EntryList& file_list,
+ bool has_more);
+ void OnFileInfo(const std::string& file_name,
+ const storage::FileSystemURL& file_url,
+ base::File::Error result,
+ const base::File::Info& file_info);
+
+ // Keeps track of the pending work. When |task_count_| goes to 0 then
+ // |callback_| is called and this helper object is destroyed.
+ void IncrementTaskCount();
+ void DecrementTaskCount();
+
+ scoped_refptr<storage::FileSystemContext> filesystem_context_;
+ GURL origin_;
+ std::string plugin_name_;
+ base::Time begin_;
+ base::Time end_;
+ base::Closure callback_;
+ std::string fsid_;
+ int task_count_ = 0;
+ bool delete_this_data_ = false;
+};
+
+void PluginPrivateContentLicensesDeletionHelper::Start() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(storage::ValidateIsolatedFileSystemId(fsid_));
+
+ IncrementTaskCount();
+ filesystem_context_->OpenPluginPrivateFileSystem(
+ origin_, storage::kFileSystemTypePluginPrivate, fsid_, plugin_name_,
+ storage::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
+ base::Bind(
+ &PluginPrivateContentLicensesDeletionHelper::OnFileSystemOpened,
+ base::Unretained(this)));
+}
+
+void PluginPrivateContentLicensesDeletionHelper::OnFileSystemOpened(
+ base::File::Error result) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DVLOG(3) << "Opened filesystem for " << origin_ << ":" << plugin_name_
+ << ", result: " << result;
+
+ // If we can't open the directory, we can't delete files so simply return.
+ if (result != base::File::FILE_OK) {
+ DecrementTaskCount();
+ return;
+ }
+
+ storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil(
+ storage::kFileSystemTypePluginPrivate);
+ std::string root = storage::GetIsolatedFileSystemRootURIString(
+ origin_, fsid_, kPluginPrivateRootName);
+ std::unique_ptr<storage::FileSystemOperationContext> operation_context =
+ base::WrapUnique(
+ new storage::FileSystemOperationContext(filesystem_context_.get()));
+ file_util->ReadDirectory(
+ std::move(operation_context), filesystem_context_->CrackURL(GURL(root)),
+ base::Bind(&PluginPrivateContentLicensesDeletionHelper::OnDirectoryRead,
+ base::Unretained(this), root));
+}
+
+void PluginPrivateContentLicensesDeletionHelper::OnDirectoryRead(
+ const std::string& root,
+ base::File::Error result,
+ const storage::AsyncFileUtil::EntryList& file_list,
+ bool has_more) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DVLOG(3) << __FUNCTION__ << " result: " << result
+ << ", #files: " << file_list.size();
+
+ // Quit if there is an error.
+ if (result != base::File::FILE_OK) {
+ DLOG(ERROR) << "Unable to read directory for " << origin_ << ":"
+ << plugin_name_;
+ DecrementTaskCount();
+ return;
+ }
+
+ // No error, process the files returned.
+ storage::AsyncFileUtil* file_util = filesystem_context_->GetAsyncFileUtil(
+ storage::kFileSystemTypePluginPrivate);
+ for (const auto& file : file_list) {
+ DVLOG(3) << __FUNCTION__ << " file: " << file.name;
+ DCHECK(!file.is_directory); // Nested directories not implemented.
+
+ std::unique_ptr<storage::FileSystemOperationContext> operation_context =
+ base::WrapUnique(
+ new storage::FileSystemOperationContext(filesystem_context_.get()));
+ storage::FileSystemURL file_url =
+ filesystem_context_->CrackURL(GURL(root + file.name));
+ IncrementTaskCount();
+ file_util->GetFileInfo(
+ std::move(operation_context), file_url,
+ storage::FileSystemOperation::GET_METADATA_FIELD_SIZE |
+ storage::FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED,
+ base::Bind(&PluginPrivateContentLicensesDeletionHelper::OnFileInfo,
+ base::Unretained(this), file.name, file_url));
+ }
+
+ // If there are more files in this directory, wait for the next call.
+ if (has_more)
+ return;
+
+ DecrementTaskCount();
+}
+
+void PluginPrivateContentLicensesDeletionHelper::OnFileInfo(
+ const std::string& file_name,
+ const storage::FileSystemURL& file_url,
+ base::File::Error result,
+ const base::File::Info& file_info) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+
+ if (result == base::File::FILE_OK) {
+ DVLOG(3) << __FUNCTION__ << " name: " << file_name
+ << ", size: " << file_info.size
+ << ", modified: " << file_info.last_modified;
+ if (file_info.last_modified >= begin_ && file_info.last_modified <= end_)
+ delete_this_data_ = true;
+ }
+
+ DecrementTaskCount();
+}
+
+void PluginPrivateContentLicensesDeletionHelper::IncrementTaskCount() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ ++task_count_;
+}
+
+void PluginPrivateContentLicensesDeletionHelper::DecrementTaskCount() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK_GT(task_count_, 0);
+ --task_count_;
+ if (task_count_)
+ return;
+
+ // If there are no more tasks in progress, then delete the files for this
+ // origin if necessary.
+ if (delete_this_data_) {
+ DVLOG(3) << "Deleting content licenses for " << origin_ << ":"
+ << plugin_name_;
+ storage::FileSystemBackend* backend =
+ filesystem_context_->GetFileSystemBackend(
+ storage::kFileSystemTypePluginPrivate);
+ storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil();
+ base::File::Error result = quota_util->DeleteOriginDataOnFileTaskRunner(
+ filesystem_context_.get(), nullptr, origin_,
+ storage::kFileSystemTypePluginPrivate);
+ DLOG_IF(ERROR, result != base::File::FILE_OK)
+ << "Unable to delete the content licenses for " << origin_ << ":"
+ << plugin_name_;
+ }
+
+ // Run |callback_| and then this helper can be deleted.
+ callback_.Run();
+ delete this;
+}
+
+// Helper for deleting content licenses.
+// All of the operations in this class are done on the FILE thread.
+class ContentLicensesDeletionHelper {
+ public:
+ ContentLicensesDeletionHelper(
+ const scoped_refptr<storage::FileSystemContext>& filesystem_context,
+ const base::Time begin,
+ const base::Time end,
+ const base::Closure& callback)
+ : filesystem_context_(std::move(filesystem_context)),
+ begin_(begin),
+ end_(end),
+ callback_(callback) {}
+ ~ContentLicensesDeletionHelper() {}
+
+ void CheckOrigins(const std::set<GURL>& origins);
+
+ private:
+ // Keeps track of the pending work. When |task_count_| goes to 0 then
+ // |callback_| is called and this helper object is destroyed.
+ void IncrementTaskCount();
+ void DecrementTaskCount();
+
+ scoped_refptr<storage::FileSystemContext> filesystem_context_;
+ base::Time begin_;
+ base::Time end_;
+ base::Closure callback_;
+ int task_count_ = 0;
+};
+
+void ContentLicensesDeletionHelper::CheckOrigins(
+ const std::set<GURL>& origins) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ IncrementTaskCount();
+
+ std::vector<std::string> supported_plugins = {
+ kWidevineCdmPluginId, kClearKeyCdmPluginId,
+ };
+ // TODO(jrummell): Is there any way to determine the set of plugin IDs
+ // directly from the filesystem?
xhwang 2016/05/16 17:35:23 We should ask storage owners about this.
jrummell 2016/05/19 00:45:57 Done.
+ base::Closure decrement_callback =
+ base::Bind(&ContentLicensesDeletionHelper::DecrementTaskCount,
+ base::Unretained(this));
+ for (const auto& origin : origins) {
+ for (const auto& plugin : supported_plugins) {
+ IncrementTaskCount();
+ PluginPrivateContentLicensesDeletionHelper* helper =
+ new PluginPrivateContentLicensesDeletionHelper(
+ filesystem_context_, origin.GetOrigin(), plugin, begin_, end_,
+ decrement_callback);
+ helper->Start();
+ }
+ }
+
+ // Cancels out the call to IncrementTaskCount() at the start of this method.
+ // If there are no origins specified then this will cause this helper to
+ // be destroyed.
+ DecrementTaskCount();
+}
+
+void ContentLicensesDeletionHelper::IncrementTaskCount() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ ++task_count_;
+}
+
+void ContentLicensesDeletionHelper::DecrementTaskCount() {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK_GT(task_count_, 0);
+ --task_count_;
+ if (task_count_)
+ return;
+
+ // If there are no more tasks in progress, run |callback_| and then
+ // this helper can be deleted.
+ callback_.Run();
+ delete this;
+}
+
+void ClearContentLicensesOnFileThread(
xhwang 2016/05/16 17:35:23 Can we document about thread safety? For example,
+ const scoped_refptr<storage::FileSystemContext>& filesystem_context,
+ const GURL& storage_origin,
+ const base::Time begin,
+ const base::Time end,
+ const base::Closure& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DVLOG(3) << "Clearing content licenses for origin: " << storage_origin;
+
+ storage::FileSystemBackend* backend =
+ filesystem_context->GetFileSystemBackend(
+ storage::kFileSystemTypePluginPrivate);
+ storage::FileSystemQuotaUtil* quota_util = backend->GetQuotaUtil();
+
+ // Determine the set of origins used.
+ std::set<GURL> origins;
+ quota_util->GetOriginsForTypeOnFileTaskRunner(
+ storage::kFileSystemTypePluginPrivate, &origins);
+
+ if (origins.empty()) {
+ // No origins, so nothing to do.
+ callback.Run();
+ return;
+ }
+
+ // If a specific origin is provided, then check that it is in the list
+ // returned and remove all the other origins.
+ if (!storage_origin.is_empty()) {
+ auto it = origins.find(storage_origin);
+ if (it == origins.end()) {
+ // Nothing matches, so nothing to do.
+ callback.Run();
+ return;
+ }
+
+ // List should only contain the one value that matches.
+ origins.clear();
+ origins.insert(storage_origin);
+ }
+
+ ContentLicensesDeletionHelper* helper = new ContentLicensesDeletionHelper(
+ std::move(filesystem_context), begin, end, callback);
+ helper->CheckOrigins(origins);
+ // |helper| will delete itself when all origins have been checked.
+}
+
} // namespace
// Static.
@@ -316,6 +642,7 @@ struct StoragePartitionImpl::DataDeletionHelper {
storage::QuotaManager* quota_manager,
storage::SpecialStoragePolicy* special_storage_policy,
WebRTCIdentityStore* webrtc_identity_store,
+ storage::FileSystemContext* filesystem_context,
const base::Time begin,
const base::Time end);
@@ -635,7 +962,8 @@ void StoragePartitionImpl::ClearDataImpl(
helper->ClearDataOnUIThread(
storage_origin, origin_matcher, cookie_matcher, GetPath(), rq_context,
dom_storage_context_.get(), quota_manager_.get(),
- special_storage_policy_.get(), webrtc_identity_store_.get(), begin, end);
+ special_storage_policy_.get(), webrtc_identity_store_.get(),
+ filesystem_context_.get(), begin, end);
}
void StoragePartitionImpl::
@@ -775,6 +1103,7 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
storage::QuotaManager* quota_manager,
storage::SpecialStoragePolicy* special_storage_policy,
WebRTCIdentityStore* webrtc_identity_store,
+ storage::FileSystemContext* filesystem_context,
const base::Time begin,
const base::Time end) {
DCHECK_NE(remove_mask, 0u);
@@ -855,6 +1184,15 @@ void StoragePartitionImpl::DataDeletionHelper::ClearDataOnUIThread(
decrement_callback));
}
+ if (remove_mask & REMOVE_DATA_MASK_CONTENT_LICENSES) {
+ IncrementTaskCountOnUI();
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&ClearContentLicensesOnFileThread,
+ make_scoped_refptr(filesystem_context), storage_origin,
+ begin, end, decrement_callback));
+ }
+
DecrementTaskCountOnUI();
}
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698