Commit 5ab64ef2 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Remove all data when stopping sync

//ios/web_view does not support any data migration between accounts

Change-Id: Ic357556ba9c6d7f71611c3a839b3675f6b169d5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869018Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709041}
parent 9842197d
......@@ -215,10 +215,6 @@ class WebViewPasswordStoreConsumer
_passwordStore->RemoveLogin(*[password internalPasswordForm]);
}
- (void)clearAllLocalData {
_personalDataManager->ClearAllLocalData();
}
#pragma mark - Private Methods
- (void)handlePasswordStoreResults:(NSArray<CWVPassword*>*)passwords {
......
......@@ -263,33 +263,4 @@ TEST_F(CWVAutofillDataManagerTest, DeletePassword) {
EXPECT_EQ(0ul, passwords.count);
}
// Tests CWVAutofillDataManager properly deletes all local data.
TEST_F(CWVAutofillDataManagerTest, ClearAllLocalData) {
personal_data_manager_->AddCreditCard(autofill::test::GetCreditCard());
personal_data_manager_->AddCreditCard(autofill::test::GetCreditCard2());
personal_data_manager_->AddServerCreditCard(
autofill::test::GetMaskedServerCard());
personal_data_manager_->AddProfile(autofill::test::GetFullProfile());
personal_data_manager_->AddProfile(autofill::test::GetFullProfile2());
EXPECT_TRUE(FetchCreditCards(^(NSArray<CWVCreditCard*>* credit_cards) {
EXPECT_EQ(3ul, credit_cards.count);
}));
EXPECT_TRUE(FetchProfiles(^(NSArray<CWVAutofillProfile*>* profiles) {
EXPECT_EQ(2ul, profiles.count);
}));
[autofill_data_manager_ clearAllLocalData];
EXPECT_TRUE(FetchCreditCards(^(NSArray<CWVCreditCard*>* credit_cards) {
EXPECT_EQ(1ul, credit_cards.count);
EXPECT_TRUE(credit_cards.firstObject.fromGooglePay);
}));
EXPECT_TRUE(FetchProfiles(^(NSArray<CWVAutofillProfile*>* profiles) {
EXPECT_EQ(0ul, profiles.count);
}));
}
} // namespace ios_web_view
......@@ -163,12 +163,16 @@ CWVWebViewConfiguration* gIncognitoConfiguration = nil;
autofill::PersonalDataManager* personalDataManager =
ios_web_view::WebViewPersonalDataManagerFactory::GetForBrowserState(
self.browserState);
scoped_refptr<password_manager::PasswordStore> passwordStore =
ios_web_view::WebViewPasswordStoreFactory::GetForBrowserState(
self.browserState, ServiceAccessType::EXPLICIT_ACCESS);
_syncController =
[[CWVSyncController alloc] initWithSyncService:syncService
identityManager:identityManager
signinErrorController:signinErrorController
personalDataManager:personalDataManager];
personalDataManager:personalDataManager
passwordStore:passwordStore.get()];
}
return _syncController;
}
......
......@@ -7,8 +7,11 @@
#import <UIKit/UIKit.h>
#include <memory>
#include "base/bind.h"
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/password_manager/core/browser/password_store_default.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/device_accounts_synchronizer.h"
......@@ -115,6 +118,7 @@ class WebViewSyncControllerObserverBridge
SigninErrorController* _signinErrorController;
std::unique_ptr<ios_web_view::WebViewSyncControllerObserverBridge> _observer;
autofill::PersonalDataManager* _personalDataManager;
password_manager::PasswordStore* _passwordStore;
}
@synthesize currentIdentity = _currentIdentity;
......@@ -137,13 +141,15 @@ __weak id<CWVSyncControllerDataSource> gSyncDataSource;
initWithSyncService:(syncer::SyncService*)syncService
identityManager:(signin::IdentityManager*)identityManager
signinErrorController:(SigninErrorController*)signinErrorController
personalDataManager:(autofill::PersonalDataManager*)personalDataManager {
personalDataManager:(autofill::PersonalDataManager*)personalDataManager
passwordStore:(password_manager::PasswordStore*)passwordStore {
self = [super init];
if (self) {
_syncService = syncService;
_identityManager = identityManager;
_signinErrorController = signinErrorController;
_personalDataManager = personalDataManager;
_passwordStore = passwordStore;
_observer =
std::make_unique<ios_web_view::WebViewSyncControllerObserverBridge>(
self);
......@@ -213,8 +219,16 @@ __weak id<CWVSyncControllerDataSource> gSyncDataSource;
signin_metrics::ProfileSignout::USER_CLICKED_SIGNOUT_SETTINGS,
signin_metrics::SignoutDelete::IGNORE_METRIC);
// Clear all local data because we do not support data migration.
// Clear all data because we do not support data migration.
// It is important that this happens post logging out so that the deletions
// are only local to the device.
_personalDataManager->ClearAllLocalData();
// Clearing server data would usually result in data being deleted from the
// user's data on sync servers, but because this is called after the user has
// been logged out, this merely clears the left over, local copies.
_personalDataManager->ClearAllServerData();
_passwordStore->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max(),
base::Closure());
_currentIdentity = nil;
}
......
......@@ -19,7 +19,11 @@ class SyncService;
namespace signin {
class IdentityManager;
}
} // namespace signin
namespace password_manager {
class PasswordStore;
} // password_manager
class SigninErrorController;
......@@ -31,6 +35,7 @@ class SigninErrorController;
identityManager:(signin::IdentityManager*)identityManager
signinErrorController:(SigninErrorController*)signinErrorController
personalDataManager:(autofill::PersonalDataManager*)personalDataManager
passwordStore:(password_manager::PasswordStore*)passwordStore
NS_DESIGNATED_INITIALIZER;
@end
......
......@@ -12,6 +12,7 @@
#include "base/files/file_path.h"
#include "base/test/bind_test_util.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/password_manager/core/browser/test_password_store.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/base/signin_pref_names.h"
......@@ -87,14 +88,20 @@ class CWVSyncControllerTest : public TestWithLocaleAndResources {
personal_data_manager_ =
std::make_unique<autofill::TestPersonalDataManager>();
password_store_ = new password_manager::TestPasswordStore();
password_store_->Init(base::RepeatingCallback<void(syncer::ModelType)>(),
nullptr);
sync_controller_ = [[CWVSyncController alloc]
initWithSyncService:mock_sync_service()
identityManager:identity_manager()
signinErrorController:signin_error_controller()
personalDataManager:personal_data_manager_.get()];
personalDataManager:personal_data_manager_.get()
passwordStore:password_store_.get()];
}
~CWVSyncControllerTest() override {
password_store_->ShutdownOnUIThread();
EXPECT_CALL(*mock_sync_service(), RemoveObserver(_));
EXPECT_CALL(*mock_sync_service(), Shutdown());
}
......@@ -120,6 +127,7 @@ class CWVSyncControllerTest : public TestWithLocaleAndResources {
web::WebTaskEnvironment task_environment_;
web::ScopedTestingWebClient web_client_;
ios_web_view::WebViewBrowserState browser_state_;
scoped_refptr<password_manager::TestPasswordStore> password_store_;
std::unique_ptr<autofill::TestPersonalDataManager> personal_data_manager_;
CWVSyncController* sync_controller_ = nil;
syncer::SyncServiceObserver* sync_service_observer_ = nullptr;
......
......@@ -55,9 +55,6 @@ CWV_EXPORT
// Deletes the password.
- (void)deletePassword:(CWVPassword*)password;
// Deletes all locally saved data.
- (void)clearAllLocalData;
@end
NS_ASSUME_NONNULL_END
......
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