1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SECURITY_EVENTS_SECURITY_EVENT_SYNC_BRIDGE_IMPL_H_ 6 #define CHROME_BROWSER_SECURITY_EVENTS_SECURITY_EVENT_SYNC_BRIDGE_IMPL_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/macros.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/optional.h" 14 #include "chrome/browser/security_events/security_event_sync_bridge.h" 15 #include "components/sync/model/model_type_change_processor.h" 16 #include "components/sync/model/model_type_store.h" 17 #include "components/sync/model/model_type_sync_bridge.h" 18 #include "components/sync/protocol/sync.pb.h" 19 20 class SecurityEventSyncBridgeImpl : public SecurityEventSyncBridge, 21 public syncer::ModelTypeSyncBridge { 22 public: 23 SecurityEventSyncBridgeImpl( 24 syncer::OnceModelTypeStoreFactory store_factory, 25 std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor); 26 ~SecurityEventSyncBridgeImpl() override; 27 28 void RecordSecurityEvent(sync_pb::SecurityEventSpecifics specifics) override; 29 30 base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate() 31 override; 32 33 // ModelTypeSyncBridge implementation. 34 std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList() 35 override; 36 base::Optional<syncer::ModelError> MergeSyncData( 37 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 38 syncer::EntityChangeList entity_data) override; 39 base::Optional<syncer::ModelError> ApplySyncChanges( 40 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 41 syncer::EntityChangeList entity_changes) override; 42 void GetData(StorageKeyList storage_keys, DataCallback callback) override; 43 void GetAllDataForDebugging(DataCallback callback) override; 44 std::string GetClientTag(const syncer::EntityData& entity_data) override; 45 std::string GetStorageKey(const syncer::EntityData& entity_data) override; 46 void ApplyStopSyncChanges(std::unique_ptr<syncer::MetadataChangeList> 47 delete_metadata_change_list) override; 48 49 private: 50 void OnStoreCreated(const base::Optional<syncer::ModelError>& error, 51 std::unique_ptr<syncer::ModelTypeStore> store); 52 53 void OnReadData( 54 DataCallback callback, 55 const base::Optional<syncer::ModelError>& error, 56 std::unique_ptr<syncer::ModelTypeStore::RecordList> data_records, 57 std::unique_ptr<syncer::ModelTypeStore::IdList> missing_id_list); 58 59 void OnReadAllData( 60 DataCallback callback, 61 const base::Optional<syncer::ModelError>& error, 62 std::unique_ptr<syncer::ModelTypeStore::RecordList> data_records); 63 64 void OnReadAllMetadata(const base::Optional<syncer::ModelError>& error, 65 std::unique_ptr<syncer::MetadataBatch> metadata_batch); 66 67 void OnCommit(const base::Optional<syncer::ModelError>& error); 68 69 std::unique_ptr<syncer::ModelTypeStore> store_; 70 71 base::WeakPtrFactory<SecurityEventSyncBridgeImpl> weak_ptr_factory_{this}; 72 73 DISALLOW_COPY_AND_ASSIGN(SecurityEventSyncBridgeImpl); 74 }; 75 76 #endif // CHROME_BROWSER_SECURITY_EVENTS_SECURITY_EVENT_SYNC_BRIDGE_IMPL_H_ 77