Commit cde6b8b3 authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

[Sync:USS] Add NigoriStorage::ClearData()

We need to remove all stored sync metadata when user disabled sync.
Nigori is not user type, so we have to remove everything related in
this case. NigoriStorage::ClearData() just removes the corresponding
file.

Bug: 922900
Change-Id: Icfbb27f4a693122b3d048bdba857764d5dd83a97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1782848
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693149}
parent a847b0d9
...@@ -24,6 +24,9 @@ class NigoriStorage { ...@@ -24,6 +24,9 @@ class NigoriStorage {
// was stored, returns base::nullopt. // was stored, returns base::nullopt.
virtual base::Optional<sync_pb::NigoriLocalData> RestoreData() = 0; virtual base::Optional<sync_pb::NigoriLocalData> RestoreData() = 0;
// Removes all previously stored data.
virtual void ClearData() = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(NigoriStorage); DISALLOW_COPY_AND_ASSIGN(NigoriStorage);
}; };
......
...@@ -68,4 +68,8 @@ base::Optional<sync_pb::NigoriLocalData> NigoriStorageImpl::RestoreData() { ...@@ -68,4 +68,8 @@ base::Optional<sync_pb::NigoriLocalData> NigoriStorageImpl::RestoreData() {
return data; return data;
} }
void NigoriStorageImpl::ClearData() {
base::DeleteFile(path_, /*recursive=*/false);
}
} // namespace syncer } // namespace syncer
...@@ -23,6 +23,7 @@ class NigoriStorageImpl : public NigoriStorage { ...@@ -23,6 +23,7 @@ class NigoriStorageImpl : public NigoriStorage {
// Encrypts |data| and atomically stores it in binary file. // Encrypts |data| and atomically stores it in binary file.
void StoreData(const sync_pb::NigoriLocalData& data) override; void StoreData(const sync_pb::NigoriLocalData& data) override;
base::Optional<sync_pb::NigoriLocalData> RestoreData() override; base::Optional<sync_pb::NigoriLocalData> RestoreData() override;
void ClearData() override;
private: private:
base::FilePath path_; base::FilePath path_;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/sync/nigori/nigori_storage_impl.h" #include "components/sync/nigori/nigori_storage_impl.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "components/sync/base/fake_encryptor.h" #include "components/sync/base/fake_encryptor.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -58,6 +59,15 @@ TEST_F(NigoriStorageImplTest, ShouldReturnNulloptWhenFileNotExists) { ...@@ -58,6 +59,15 @@ TEST_F(NigoriStorageImplTest, ShouldReturnNulloptWhenFileNotExists) {
EXPECT_EQ(storage.RestoreData(), base::nullopt); EXPECT_EQ(storage.RestoreData(), base::nullopt);
} }
TEST_F(NigoriStorageImplTest, ShouldRemoveFile) {
NigoriStorageImpl storage(GetFilePath(), encryptor());
sync_pb::NigoriLocalData data = MakeSomeNigoriLocalData();
storage.StoreData(data);
ASSERT_TRUE(base::PathExists(GetFilePath()));
storage.ClearData();
EXPECT_FALSE(base::PathExists(GetFilePath()));
}
} // namespace } // namespace
} // namespace syncer } // namespace syncer
...@@ -272,6 +272,7 @@ class MockNigoriStorage : public NigoriStorage { ...@@ -272,6 +272,7 @@ class MockNigoriStorage : public NigoriStorage {
MOCK_METHOD1(StoreData, void(const sync_pb::NigoriLocalData&)); MOCK_METHOD1(StoreData, void(const sync_pb::NigoriLocalData&));
MOCK_METHOD0(RestoreData, base::Optional<sync_pb::NigoriLocalData>()); MOCK_METHOD0(RestoreData, base::Optional<sync_pb::NigoriLocalData>());
MOCK_METHOD0(ClearData, void());
}; };
class NigoriSyncBridgeImplTest : public testing::Test { class NigoriSyncBridgeImplTest : public testing::Test {
......
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