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

Unified Diff: chrome/browser/android/preferences/website_preference_bridge.cc

Issue 863503002: Delete cookies for site when deleting locally stored data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove parentheses Created 5 years, 11 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
Index: chrome/browser/android/preferences/website_preference_bridge.cc
diff --git a/chrome/browser/android/preferences/website_preference_bridge.cc b/chrome/browser/android/preferences/website_preference_bridge.cc
index 4ea9e47f788bd958f75a31abebbf9c097eb9fa10..515b43e82181dc7b69c24f220af265b478dbc159 100644
--- a/chrome/browser/android/preferences/website_preference_bridge.cc
+++ b/chrome/browser/android/preferences/website_preference_bridge.cc
@@ -12,6 +12,8 @@
#include "base/files/file_path.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
+#include "chrome/browser/browsing_data/cookies_tree_model.h"
+#include "chrome/browser/browsing_data/local_data_container.h"
#include "chrome/browser/content_settings/cookie_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
@@ -285,6 +287,104 @@ static void SetCookieSettingForOrigin(JNIEnv* env, jclass clazz,
namespace {
+class SiteDataDeleteHelper :
+ public base::RefCountedThreadSafe<SiteDataDeleteHelper>,
+ public CookiesTreeModel::Observer {
+ public:
+ SiteDataDeleteHelper(Profile* profile, const GURL& domain)
+ : profile_(profile), domain_(domain), ending_batch_processing_(false) {
+ }
+
+ void Run() {
+ AddRef(); // Balanced in TreeModelEndBatch.
+
+ content::StoragePartition* storage_partition =
+ content::BrowserContext::GetDefaultStoragePartition(profile_);
+ content::IndexedDBContext* indexed_db_context =
+ storage_partition->GetIndexedDBContext();
+ content::ServiceWorkerContext* service_worker_context =
+ storage_partition->GetServiceWorkerContext();
+ storage::FileSystemContext* file_system_context =
+ storage_partition->GetFileSystemContext();
+ LocalDataContainer* container = new LocalDataContainer(
+ new BrowsingDataCookieHelper(profile_->GetRequestContext()),
+ new BrowsingDataDatabaseHelper(profile_),
+ new BrowsingDataLocalStorageHelper(profile_),
+ NULL,
+ new BrowsingDataAppCacheHelper(profile_),
+ new BrowsingDataIndexedDBHelper(indexed_db_context),
+ BrowsingDataFileSystemHelper::Create(file_system_context),
+ BrowsingDataQuotaHelper::Create(profile_),
+ BrowsingDataChannelIDHelper::Create(profile_->GetRequestContext()),
+ new BrowsingDataServiceWorkerHelper(service_worker_context),
+ NULL);
+
+ cookies_tree_model_.reset(new CookiesTreeModel(
+ container, profile_->GetExtensionSpecialStoragePolicy(), false));
+ cookies_tree_model_->AddCookiesTreeObserver(this);
+ }
+
+ // TreeModelObserver:
+ void TreeNodesAdded(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) override {}
+ void TreeNodesRemoved(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) override {}
+
+ // CookiesTreeModel::Observer:
+ void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) override {
+ }
+
+ void TreeModelBeginBatch(CookiesTreeModel* model) override {
+ DCHECK(!ending_batch_processing_); // Extra batch-start sent.
+ }
+
+ void TreeModelEndBatch(CookiesTreeModel* model) override {
newt (away) 2015/01/23 02:23:14 It's not clear to me that TreeModelEndBatch is gua
Finnur 2015/01/26 10:47:22 Incidentally, I've become intimately familiar with
+ DCHECK(!ending_batch_processing_); // Already in end-stage.
+ ending_batch_processing_ = true;
+
+ RecursivelyFindSiteAndDelete(cookies_tree_model_->GetRoot());
+
+ // This will result in this class getting deleted.
+ Release();
+ }
+
+ void RecursivelyFindSiteAndDelete(CookieTreeNode* node) {
+ CookieTreeNode::DetailedInfo info = node->GetDetailedInfo();
+ bool delete_this_node = false;
+ if (info.node_type == CookieTreeNode::DetailedInfo::TYPE_COOKIE &&
+ info.cookie &&
+ domain_.DomainIs(info.cookie->Domain().c_str()))
+ delete_this_node = true;
+
+ for (int i = node->child_count(); i > 0; --i)
newt (away) 2015/01/23 02:23:14 Why can't you move this for loop up to before the
Finnur 2015/01/26 10:47:22 At one point I needed to delete last, but then man
+ RecursivelyFindSiteAndDelete(node->GetChild(i - 1));
newt (away) 2015/01/23 02:23:14 Can COOKIE nodes contain other COOKIE nodes?
Finnur 2015/01/26 10:47:22 I don't believe so. What I see is a tree that look
+
+ if (delete_this_node)
+ cookies_tree_model_->DeleteCookieNode(node);
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<SiteDataDeleteHelper>;
+
+ virtual ~SiteDataDeleteHelper() {}
+
+ Profile* profile_;
+
+ // The domain we want to delete data for.
+ GURL domain_;
+
+ // Keeps track of when we're ready to close batch processing.
+ bool ending_batch_processing_;
+
+ scoped_ptr<CookiesTreeModel> cookies_tree_model_;
+
+ DISALLOW_COPY_AND_ASSIGN(SiteDataDeleteHelper);
+};
+
class StorageInfoFetcher :
public base::RefCountedThreadSafe<StorageInfoFetcher> {
public:
@@ -500,6 +600,14 @@ static void ClearStorageData(JNIEnv* env,
storage_data_deleter->Run();
}
+static void ClearCookieData(JNIEnv* env, jclass clazz, jstring jorigin) {
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ GURL url(ConvertJavaStringToUTF8(env, jorigin));
+ scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
+ new SiteDataDeleteHelper(profile, url));
+ site_data_deleter->Run();
+}
+
// Register native methods
bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
return RegisterNativesImpl(env);
« no previous file with comments | « chrome/android/java/strings/android_chrome_strings.grd ('k') | chrome/browser/browsing_data/cookies_tree_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698