Commit 7713fa45 authored by Zhaoxin's avatar Zhaoxin Committed by Commit Bot

[CastWebService] Add storage cleaning logic into CastWebService.

Move storage cleaning logic from CastDemoService and ManagedModeService
to CastWebService in the upstream. Therefore those two classes no longer
need to depend on content/browser/browser_context and a few other
things.

Merge-With: eureka-internal/342450

Bug: b/144316586
Test: CQ
Change-Id: Id5908d78207003c22f306e739d5272cee774aa7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1956105Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Commit-Queue: Zhaoxin Liang <zxliang@google.com>
Cr-Commit-Position: refs/heads/master@{#723576}
parent 25684bbe
...@@ -214,6 +214,7 @@ cast_source_set("browser") { ...@@ -214,6 +214,7 @@ cast_source_set("browser") {
"//media/mojo/services:media_manifest", "//media/mojo/services:media_manifest",
"//net", "//net",
"//services/media_session/public/mojom", "//services/media_session/public/mojom",
"//services/network/public/mojom",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//ui/base", "//ui/base",
"//ui/compositor", "//ui/compositor",
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
...@@ -17,12 +18,26 @@ ...@@ -17,12 +18,26 @@
#include "chromecast/browser/cast_web_view_default.h" #include "chromecast/browser/cast_web_view_default.h"
#include "chromecast/browser/cast_web_view_factory.h" #include "chromecast/browser/cast_web_view_factory.h"
#include "chromecast/chromecast_buildflags.h" #include "chromecast/chromecast_buildflags.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/media_session.h" #include "content/public/browser/media_session.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
namespace chromecast { namespace chromecast {
namespace {
uint32_t mask = content::StoragePartition::REMOVE_DATA_MASK_APPCACHE |
content::StoragePartition::REMOVE_DATA_MASK_COOKIES |
content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB |
content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE |
content::StoragePartition::REMOVE_DATA_MASK_WEBSQL;
} // namespace
CastWebService::CastWebService(content::BrowserContext* browser_context, CastWebService::CastWebService(content::BrowserContext* browser_context,
CastWebViewFactory* web_view_factory, CastWebViewFactory* web_view_factory,
CastWindowManager* window_manager) CastWindowManager* window_manager)
...@@ -68,6 +83,33 @@ CastWebView::Scoped CastWebService::CreateWebView( ...@@ -68,6 +83,33 @@ CastWebView::Scoped CastWebService::CreateWebView(
return scoped; return scoped;
} }
void CastWebService::FlushDomLocalStorage() {
content::BrowserContext::ForEachStoragePartition(
browser_context_,
base::BindRepeating([](content::StoragePartition* storage_partition) {
DVLOG(1) << "Starting DOM localStorage flush.";
storage_partition->Flush();
}));
}
void CastWebService::ClearLocalStorage(base::OnceClosure callback) {
content::BrowserContext::ForEachStoragePartition(
browser_context_,
base::BindRepeating(
[](base::OnceClosure cb, content::StoragePartition* partition) {
auto cookie_delete_filter =
network::mojom::CookieDeletionFilter::New();
cookie_delete_filter->session_control =
network::mojom::CookieDeletionSessionControl::IGNORE_CONTROL;
partition->ClearData(
mask, content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
content::StoragePartition::OriginMatcherFunction(),
std::move(cookie_delete_filter), true /*perform_cleanup*/,
base::Time::Min(), base::Time::Max(), std::move(cb));
},
base::Passed(std::move(callback))));
}
void CastWebService::OwnerDestroyed(CastWebView* web_view) { void CastWebService::OwnerDestroyed(CastWebView* web_view) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
content::WebContents* web_contents = web_view->web_contents(); content::WebContents* web_contents = web_view->web_contents();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "base/callback.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -20,6 +21,7 @@ class SequencedTaskRunner; ...@@ -20,6 +21,7 @@ class SequencedTaskRunner;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class StoragePartition;
} // namespace content } // namespace content
namespace chromecast { namespace chromecast {
...@@ -50,6 +52,12 @@ class CastWebService { ...@@ -50,6 +52,12 @@ class CastWebService {
std::unique_ptr<CastContentWindow> CreateWindow( std::unique_ptr<CastContentWindow> CreateWindow(
const CastContentWindow::CreateParams& params); const CastContentWindow::CreateParams& params);
void FlushDomLocalStorage();
// |callback| is called when data deletion is done or at least the deletion
// is scheduled.
void ClearLocalStorage(base::OnceClosure callback);
private: private:
void OwnerDestroyed(CastWebView* web_view); void OwnerDestroyed(CastWebView* web_view);
void DeleteWebView(CastWebView* web_view); void DeleteWebView(CastWebView* web_view);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment