1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/sync/engine/active_devices_invalidation_info.h"
#include <utility>
namespace syncer {
namespace {
// The maximum number of FCM registration tokens to be returned for a commit
// message.
constexpr size_t kMaxFcmRegistrationTokens = 5;
} // namespace
// static
ActiveDevicesInvalidationInfo
ActiveDevicesInvalidationInfo::CreateUninitialized() {
return ActiveDevicesInvalidationInfo(/*initialized=*/false);
}
// static
ActiveDevicesInvalidationInfo ActiveDevicesInvalidationInfo::Create(
std::vector<std::string> all_fcm_registration_tokens,
DataTypeSet all_interested_data_types,
std::map<std::string, DataTypeSet> fcm_token_and_interested_data_types,
DataTypeSet old_invalidations_interested_data_types) {
ActiveDevicesInvalidationInfo result(/*initialized=*/true);
result.all_fcm_registration_tokens_ = std::move(all_fcm_registration_tokens);
result.all_interested_data_types_ = all_interested_data_types;
result.fcm_token_and_interested_data_types_ =
std::move(fcm_token_and_interested_data_types);
result.old_invalidations_interested_data_types_ =
old_invalidations_interested_data_types;
return result;
}
ActiveDevicesInvalidationInfo::ActiveDevicesInvalidationInfo(bool initialized)
: initialized_(initialized) {}
ActiveDevicesInvalidationInfo::~ActiveDevicesInvalidationInfo() = default;
ActiveDevicesInvalidationInfo::ActiveDevicesInvalidationInfo(
const ActiveDevicesInvalidationInfo&) = default;
ActiveDevicesInvalidationInfo& ActiveDevicesInvalidationInfo::operator=(
const ActiveDevicesInvalidationInfo&) = default;
ActiveDevicesInvalidationInfo::ActiveDevicesInvalidationInfo(
ActiveDevicesInvalidationInfo&&) = default;
ActiveDevicesInvalidationInfo& ActiveDevicesInvalidationInfo::operator=(
ActiveDevicesInvalidationInfo&&) = default;
bool ActiveDevicesInvalidationInfo::IsSingleClientForTypes(
const DataTypeSet& types) const {
if (!initialized_) {
return false;
}
return Intersection(types, all_interested_data_types_).empty();
}
bool ActiveDevicesInvalidationInfo::
IsSingleClientWithStandaloneInvalidationsForTypes(
const DataTypeSet& types) const {
if (!initialized_) {
return false;
}
return Intersection(types,
GetAllInterestedDataTypesForStandaloneInvalidations())
.empty();
}
bool ActiveDevicesInvalidationInfo::IsSingleClientWithOldInvalidationsForTypes(
const DataTypeSet& types) const {
if (!initialized_) {
return false;
}
return Intersection(types, old_invalidations_interested_data_types_).empty();
}
std::vector<std::string>
ActiveDevicesInvalidationInfo::GetFcmRegistrationTokensForInterestedClients(
DataTypeSet types) const {
std::vector<std::string> fcm_tokens;
for (const auto& fcm_token_with_data_types :
fcm_token_and_interested_data_types_) {
if (Intersection(types, fcm_token_with_data_types.second).empty()) {
continue;
}
if (fcm_tokens.size() >= kMaxFcmRegistrationTokens) {
fcm_tokens.clear();
// Single client is used to determine if there are devices with standalone
// invalidations enabled.
DCHECK(!IsSingleClientWithStandaloneInvalidationsForTypes(types));
break;
}
fcm_tokens.push_back(fcm_token_with_data_types.first);
}
return fcm_tokens;
}
DataTypeSet ActiveDevicesInvalidationInfo::
GetAllInterestedDataTypesForStandaloneInvalidations() const {
DataTypeSet result;
for (const auto& fcm_token_with_data_types :
fcm_token_and_interested_data_types_) {
result.PutAll(fcm_token_with_data_types.second);
}
return result;
}
} // namespace syncer
|