Commit 3066fd65 authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

[StandaloneSyncInvalidations] Use data types from invalidation payload.

R=rushans@google.com, treib@chromium.org

Bug: 1102322
Change-Id: Iaaf74e0260e2b2ad560938dcb7d9fbbd0f899911
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2366719
Commit-Queue: Paula Vidas <paulavidas@google.com>
Reviewed-by: default avatarRushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800159}
parent 54bb0e0d
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "components/sync/nigori/nigori_model_type_processor.h" #include "components/sync/nigori/nigori_model_type_processor.h"
#include "components/sync/nigori/nigori_storage_impl.h" #include "components/sync/nigori/nigori_storage_impl.h"
#include "components/sync/nigori/nigori_sync_bridge_impl.h" #include "components/sync/nigori/nigori_sync_bridge_impl.h"
#include "components/sync/protocol/sync_invalidations_payload.pb.h"
// Helper macros to log with the syncer thread name; useful when there // Helper macros to log with the syncer thread name; useful when there
// are multiple syncers involved. // are multiple syncers involved.
...@@ -589,12 +590,25 @@ void SyncEngineBackend::DoOnInvalidationReceived(const std::string& payload) { ...@@ -589,12 +590,25 @@ void SyncEngineBackend::DoOnInvalidationReceived(const std::string& payload) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK( DCHECK(
base::FeatureList::IsEnabled(switches::kSubscribeForSyncInvalidations)); base::FeatureList::IsEnabled(switches::kSubscribeForSyncInvalidations));
// TODO(crbug.com/1102322): use data types from active or from payload.
const ModelTypeSet active_datatypes{ModelType::BOOKMARKS}; sync_pb::SyncInvalidationsPayload payload_message;
for (const ModelType type : active_datatypes) { // TODO(crbug.com/1119804): Track parsing failures in a histogram.
if (!payload_message.ParseFromString(payload)) {
return;
}
for (const auto& data_type_invalidation :
payload_message.data_type_invalidations()) {
const int field_number = data_type_invalidation.data_type_id();
ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number);
if (!IsRealDataType(model_type)) {
DLOG(WARNING) << "Unknown field number " << field_number;
continue;
}
// TODO(crbug.com/1119798): Use only enabled data types.
std::unique_ptr<InvalidationInterface> inv_adapter = std::unique_ptr<InvalidationInterface> inv_adapter =
std::make_unique<SyncInvalidationAdapter>(payload); std::make_unique<SyncInvalidationAdapter>(payload_message.hint());
sync_manager_->OnIncomingInvalidation(type, std::move(inv_adapter)); sync_manager_->OnIncomingInvalidation(model_type, std::move(inv_adapter));
} }
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/invalidator_state.h" #include "components/invalidation/public/invalidator_state.h"
#include "components/sync/base/invalidation_helper.h" #include "components/sync/base/invalidation_helper.h"
#include "components/sync/base/model_type.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync/driver/sync_driver_switches.h" #include "components/sync/driver/sync_driver_switches.h"
#include "components/sync/engine/cycle/commit_counters.h" #include "components/sync/engine/cycle/commit_counters.h"
...@@ -45,6 +46,7 @@ ...@@ -45,6 +46,7 @@
#include "components/sync/invalidations/mock_sync_invalidations_service.h" #include "components/sync/invalidations/mock_sync_invalidations_service.h"
#include "components/sync/invalidations/switches.h" #include "components/sync/invalidations/switches.h"
#include "components/sync/invalidations/sync_invalidations_service.h" #include "components/sync/invalidations/sync_invalidations_service.h"
#include "components/sync/protocol/sync_invalidations_payload.pb.h"
#include "components/sync/test/callback_counter.h" #include "components/sync/test/callback_counter.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
...@@ -658,11 +660,20 @@ TEST_F(SyncEngineImplWithSyncInvalidationsTest, ...@@ -658,11 +660,20 @@ TEST_F(SyncEngineImplWithSyncInvalidationsTest,
ShouldInvalidateDataTypesOnIncomingInvalidation) { ShouldInvalidateDataTypesOnIncomingInvalidation) {
EXPECT_CALL(mock_instance_id_driver_, AddListener(backend_.get())); EXPECT_CALL(mock_instance_id_driver_, AddListener(backend_.get()));
InitializeBackend(/*expect_success=*/true); InitializeBackend(/*expect_success=*/true);
// TODO(crbug.com/1102322): use real payload with invalidated data types.
backend_->OnInvalidationReceived(/*payload=*/""); sync_pb::SyncInvalidationsPayload payload;
auto* bookmarks_invalidation = payload.add_data_type_invalidations();
bookmarks_invalidation->set_data_type_id(
GetSpecificsFieldNumberFromModelType(ModelType::BOOKMARKS));
auto* preferences_invalidation = payload.add_data_type_invalidations();
preferences_invalidation->set_data_type_id(
GetSpecificsFieldNumberFromModelType(ModelType::PREFERENCES));
backend_->OnInvalidationReceived(payload.SerializeAsString());
fake_manager_->WaitForSyncThread(); fake_manager_->WaitForSyncThread();
// Currently only one data type is expected to invalidate. EXPECT_EQ(1, fake_manager_->GetInvalidationCount(ModelType::BOOKMARKS));
EXPECT_EQ(1, fake_manager_->GetInvalidationCount()); EXPECT_EQ(1, fake_manager_->GetInvalidationCount(ModelType::PREFERENCES));
} }
} // namespace } // namespace
......
...@@ -31,8 +31,7 @@ FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types, ...@@ -31,8 +31,7 @@ FakeSyncManager::FakeSyncManager(ModelTypeSet initial_sync_ended_types,
initial_sync_ended_types_(initial_sync_ended_types), initial_sync_ended_types_(initial_sync_ended_types),
progress_marker_types_(progress_marker_types), progress_marker_types_(progress_marker_types),
configure_fail_types_(configure_fail_types), configure_fail_types_(configure_fail_types),
last_configure_reason_(CONFIGURE_REASON_UNKNOWN), last_configure_reason_(CONFIGURE_REASON_UNKNOWN) {}
num_invalidations_received_(0) {}
FakeSyncManager::~FakeSyncManager() {} FakeSyncManager::~FakeSyncManager() {}
...@@ -48,8 +47,13 @@ ConfigureReason FakeSyncManager::GetAndResetConfigureReason() { ...@@ -48,8 +47,13 @@ ConfigureReason FakeSyncManager::GetAndResetConfigureReason() {
return reason; return reason;
} }
int FakeSyncManager::GetInvalidationCount() const { int FakeSyncManager::GetInvalidationCount(ModelType type) const {
return num_invalidations_received_; auto it = num_invalidations_received_.find(type);
if (it == num_invalidations_received_.end()) {
return 0;
} else {
return it->second;
}
} }
void FakeSyncManager::WaitForSyncThread() { void FakeSyncManager::WaitForSyncThread() {
...@@ -180,7 +184,7 @@ void FakeSyncManager::RequestEmitDebugInfo() {} ...@@ -180,7 +184,7 @@ void FakeSyncManager::RequestEmitDebugInfo() {}
void FakeSyncManager::OnIncomingInvalidation( void FakeSyncManager::OnIncomingInvalidation(
ModelType type, ModelType type,
std::unique_ptr<InvalidationInterface> invalidation) { std::unique_ptr<InvalidationInterface> invalidation) {
num_invalidations_received_++; num_invalidations_received_[type]++;
} }
ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef COMPONENTS_SYNC_ENGINE_FAKE_SYNC_MANAGER_H_ #ifndef COMPONENTS_SYNC_ENGINE_FAKE_SYNC_MANAGER_H_
#define COMPONENTS_SYNC_ENGINE_FAKE_SYNC_MANAGER_H_ #define COMPONENTS_SYNC_ENGINE_FAKE_SYNC_MANAGER_H_
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "components/sync/base/model_type.h"
#include "components/sync/engine/fake_model_type_connector.h" #include "components/sync/engine/fake_model_type_connector.h"
#include "components/sync/engine/sync_manager.h" #include "components/sync/engine/sync_manager.h"
#include "components/sync/test/fake_sync_encryption_handler.h" #include "components/sync/test/fake_sync_encryption_handler.h"
...@@ -56,8 +58,8 @@ class FakeSyncManager : public SyncManager { ...@@ -56,8 +58,8 @@ class FakeSyncManager : public SyncManager {
// GetAndResetConfigureReason, or since startup if never called. // GetAndResetConfigureReason, or since startup if never called.
ConfigureReason GetAndResetConfigureReason(); ConfigureReason GetAndResetConfigureReason();
// Returns the number of invalidations received since startup. // Returns the number of invalidations received for type since startup.
int GetInvalidationCount() const; int GetInvalidationCount(ModelType type) const;
// Block until the sync thread has finished processing any pending messages. // Block until the sync thread has finished processing any pending messages.
void WaitForSyncThread(); void WaitForSyncThread();
...@@ -130,8 +132,8 @@ class FakeSyncManager : public SyncManager { ...@@ -130,8 +132,8 @@ class FakeSyncManager : public SyncManager {
FakeModelTypeConnector fake_model_type_connector_; FakeModelTypeConnector fake_model_type_connector_;
// Number of invalidations received since startup. // Number of invalidations received per type since startup.
int num_invalidations_received_; std::map<ModelType, int> num_invalidations_received_;
DISALLOW_COPY_AND_ASSIGN(FakeSyncManager); DISALLOW_COPY_AND_ASSIGN(FakeSyncManager);
}; };
......
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