Commit 8d297d6d authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Delete bookmarks on profile deletion

When a profile is deleted, all browsing_data is removed and the folder
is marked for deletion on shutdown. Bookmarks are currently not deleted
until the folder is deleted. As bookmarks can contains sensitive data
they should also be removed immediately.
This also changes SigninManagerAndroidTest to use
ChromeBrowsingDataRemoverDelegate.

Bug: 803643, 748484
Change-Id: Icebfcec44d61d8b38939a8cee8dc4a92b6f9e258
Reviewed-on: https://chromium-review.googlesource.com/957040
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543358}
parent 75c50929
...@@ -106,10 +106,6 @@ class ProfileDataRemover : public content::BrowsingDataRemover::Observer { ...@@ -106,10 +106,6 @@ class ProfileDataRemover : public content::BrowsingDataRemover::Observer {
remover_->RemoveObserver(this); remover_->RemoveObserver(this);
if (all_data_) { if (all_data_) {
BookmarkModel* model =
BookmarkModelFactory::GetForBrowserContext(profile_);
model->RemoveAllUserBookmarks();
// All the Profile data has been wiped. Clear the last signed in username // All the Profile data has been wiped. Clear the last signed in username
// as well, so that the next signin doesn't trigger the account // as well, so that the next signin doesn't trigger the account
// change dialog. // change dialog.
......
...@@ -13,17 +13,40 @@ ...@@ -13,17 +13,40 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h" #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h" #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_core_service_impl.h"
#include "chrome/browser/offline_pages/offline_page_model_factory.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/bookmark_test_helpers.h" #include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/offline_pages/core/stub_offline_page_model.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_remover.h" #include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace {
class MockOfflinePageModel : public offline_pages::StubOfflinePageModel {
public:
void DeleteCachedPagesByURLPredicate(
const offline_pages::UrlPredicate& predicate,
const offline_pages::DeletePageCallback& callback) override {
callback.Run(DeletePageResult::SUCCESS);
}
};
std::unique_ptr<KeyedService> BuildOfflinePageModel(
content::BrowserContext* context) {
return std::make_unique<MockOfflinePageModel>();
}
} // namespace
class SigninManagerAndroidTest : public ::testing::Test { class SigninManagerAndroidTest : public ::testing::Test {
public: public:
SigninManagerAndroidTest() SigninManagerAndroidTest()
...@@ -33,18 +56,22 @@ class SigninManagerAndroidTest : public ::testing::Test { ...@@ -33,18 +56,22 @@ class SigninManagerAndroidTest : public ::testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(profile_manager_.SetUp()); ASSERT_TRUE(profile_manager_.SetUp());
profile_ = profile_manager_.CreateTestingProfile("Testing Profile"); profile_ = profile_manager_.CreateTestingProfile("Testing Profile");
// TODO(crbug.com/748484): Remove requirement for this delegate in
// unit_tests.
DownloadCoreServiceFactory::GetForBrowserContext(profile_)
->SetDownloadManagerDelegateForTesting(
std::make_unique<ChromeDownloadManagerDelegate>(profile_));
} }
TestingProfile* profile() { return profile_; } TestingProfile* profile() { return profile_; }
static std::unique_ptr<KeyedService> GetEmptyBrowsingDataRemoverDelegate(
content::BrowserContext* context) {
return nullptr;
}
// Adds two testing bookmarks to |profile_|. // Adds two testing bookmarks to |profile_|.
bookmarks::BookmarkModel* AddTestBookmarks() { bookmarks::BookmarkModel* AddTestBookmarks() {
profile_->CreateBookmarkModel(true); profile_->CreateBookmarkModel(true);
// Creating a BookmarkModel also a creates a StubOfflinePageModel.
// We need to replace this with a mock that responds to deletions.
offline_pages::OfflinePageModelFactory::GetInstance()->SetTestingFactory(
profile_, BuildOfflinePageModel);
bookmarks::BookmarkModel* bookmark_model = bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile_); BookmarkModelFactory::GetForBrowserContext(profile_);
bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
...@@ -61,17 +88,6 @@ class SigninManagerAndroidTest : public ::testing::Test { ...@@ -61,17 +88,6 @@ class SigninManagerAndroidTest : public ::testing::Test {
// Calls SigninManager::WipeData(|all_data|) and waits for its completion. // Calls SigninManager::WipeData(|all_data|) and waits for its completion.
void WipeData(bool all_data) { void WipeData(bool all_data) {
// ChromeBrowsingDataRemoverDelegate deletes a lot of data storage backends
// that will not work correctly in a unittest. Remove it. Note that
// bookmarks deletion is currently not performed in the delegate, so this
// test remains valid.
// TODO(crbug.com/748484): Make ChromeBrowsingDataRemoverDelegate usable
// in unittests.
ChromeBrowsingDataRemoverDelegateFactory::GetInstance()
->SetTestingFactoryAndUse(
profile(),
SigninManagerAndroidTest::GetEmptyBrowsingDataRemoverDelegate);
std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop()); std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop());
SigninManagerAndroid::WipeData(profile(), all_data, SigninManagerAndroid::WipeData(profile(), all_data,
run_loop->QuitClosure()); run_loop->QuitClosure());
......
...@@ -777,6 +777,23 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData( ...@@ -777,6 +777,23 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
#endif #endif
} }
//////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_BOOKMARKS
if (remove_mask & DATA_TYPE_BOOKMARKS) {
auto* bookmark_model = BookmarkModelFactory::GetForBrowserContext(profile_);
if (bookmark_model) {
if (delete_begin_.is_null() &&
(delete_end_.is_null() || delete_end_.is_max())) {
bookmark_model->RemoveAllUserBookmarks();
} else {
// Bookmark deletion is only implemented to remove all data after a
// profile deletion. A full implementation would need to traverse the
// whole tree and check timestamps against delete_begin and delete_end.
NOTIMPLEMENTED();
}
}
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_DURABLE_PERMISSION // DATA_TYPE_DURABLE_PERMISSION
if (remove_mask & DATA_TYPE_DURABLE_PERMISSION) { if (remove_mask & DATA_TYPE_DURABLE_PERMISSION) {
......
...@@ -75,6 +75,7 @@ class ChromeBrowsingDataRemoverDelegate ...@@ -75,6 +75,7 @@ class ChromeBrowsingDataRemoverDelegate
DATA_TYPE_EXTERNAL_PROTOCOL_DATA = DATA_TYPE_EMBEDDER_BEGIN << 7, DATA_TYPE_EXTERNAL_PROTOCOL_DATA = DATA_TYPE_EMBEDDER_BEGIN << 7,
DATA_TYPE_HOSTED_APP_DATA_TEST_ONLY = DATA_TYPE_EMBEDDER_BEGIN << 8, DATA_TYPE_HOSTED_APP_DATA_TEST_ONLY = DATA_TYPE_EMBEDDER_BEGIN << 8,
DATA_TYPE_CONTENT_SETTINGS = DATA_TYPE_EMBEDDER_BEGIN << 9, DATA_TYPE_CONTENT_SETTINGS = DATA_TYPE_EMBEDDER_BEGIN << 9,
DATA_TYPE_BOOKMARKS = DATA_TYPE_EMBEDDER_BEGIN << 10,
// Group datatypes. // Group datatypes.
...@@ -97,10 +98,9 @@ class ChromeBrowsingDataRemoverDelegate ...@@ -97,10 +98,9 @@ class ChromeBrowsingDataRemoverDelegate
// Datatypes that can be deleted partially per URL / origin / domain, // Datatypes that can be deleted partially per URL / origin / domain,
// whichever makes sense. // whichever makes sense.
FILTERABLE_DATA_TYPES = FILTERABLE_DATA_TYPES = DATA_TYPE_SITE_DATA |
DATA_TYPE_SITE_DATA | content::BrowsingDataRemover::DATA_TYPE_CACHE |
content::BrowsingDataRemover::DATA_TYPE_CACHE | content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
// Includes all the available remove options. Meant to be used by clients // Includes all the available remove options. Meant to be used by clients
// that wish to wipe as much data as possible from a Profile, to make it // that wish to wipe as much data as possible from a Profile, to make it
...@@ -112,7 +112,8 @@ class ChromeBrowsingDataRemoverDelegate ...@@ -112,7 +112,8 @@ class ChromeBrowsingDataRemoverDelegate
DATA_TYPE_HISTORY | // DATA_TYPE_HISTORY | //
DATA_TYPE_PASSWORDS | DATA_TYPE_PASSWORDS |
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES | content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES |
DATA_TYPE_CONTENT_SETTINGS, DATA_TYPE_CONTENT_SETTINGS | //
DATA_TYPE_BOOKMARKS,
// Includes all available remove options. Meant to be used when the Profile // Includes all available remove options. Meant to be used when the Profile
// is scheduled to be deleted, and all possible data should be wiped from // is scheduled to be deleted, and all possible data should be wiped from
......
...@@ -1521,6 +1521,23 @@ TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) { ...@@ -1521,6 +1521,23 @@ TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) {
EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page)); EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
} }
TEST_F(ChromeBrowsingDataRemoverDelegateTest, DeleteBookmarks) {
GURL bookmarked_page("http://a");
TestingProfile* profile = GetProfile();
profile->CreateBookmarkModel(true);
bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile);
bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
base::ASCIIToUTF16("a"), bookmarked_page);
EXPECT_EQ(1, bookmark_model->bookmark_bar_node()->child_count());
BlockUntilBrowsingDataRemoved(
base::Time(), base::Time::Max(),
ChromeBrowsingDataRemoverDelegate::DATA_TYPE_BOOKMARKS, false);
EXPECT_EQ(0, bookmark_model->bookmark_bar_node()->child_count());
}
// TODO(crbug.com/589586): Disabled, since history is not yet marked as // TODO(crbug.com/589586): Disabled, since history is not yet marked as
// a filterable datatype. // a filterable datatype.
TEST_F(ChromeBrowsingDataRemoverDelegateTest, TEST_F(ChromeBrowsingDataRemoverDelegateTest,
......
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