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
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/sync_wifi/fake_pending_network_configuration_tracker.h"
#include "base/containers/contains.h"
#include "base/uuid.h"
#include "chromeos/ash/components/sync_wifi/pending_network_configuration_update.h"
namespace ash::sync_wifi {
FakePendingNetworkConfigurationTracker::
FakePendingNetworkConfigurationTracker() = default;
FakePendingNetworkConfigurationTracker::
~FakePendingNetworkConfigurationTracker() = default;
std::string FakePendingNetworkConfigurationTracker::TrackPendingUpdate(
const NetworkIdentifier& id,
const std::optional<sync_pb::WifiConfigurationSpecifics>& specifics) {
std::string change_id = base::Uuid::GenerateRandomV4().AsLowercaseString();
id_to_pending_update_map_.emplace(
id, PendingNetworkConfigurationUpdate(id, change_id, specifics,
/*completed_attempts=*/0));
id_to_completed_attempts_map_[id] = 0;
return change_id;
}
void FakePendingNetworkConfigurationTracker::MarkComplete(
const std::string& change_guid,
const NetworkIdentifier& id) {
if (base::Contains(id_to_pending_update_map_, id) &&
id_to_pending_update_map_.at(id).change_guid() == change_guid) {
id_to_pending_update_map_.erase(id);
}
}
void FakePendingNetworkConfigurationTracker::IncrementCompletedAttempts(
const std::string& change_guid,
const NetworkIdentifier& id) {
PendingNetworkConfigurationUpdate& existing_update =
id_to_pending_update_map_.at(id);
existing_update.SetCompletedAttemptsForTesting(
existing_update.completed_attempts() + 1);
id_to_completed_attempts_map_[id]++;
}
std::vector<PendingNetworkConfigurationUpdate>
FakePendingNetworkConfigurationTracker::GetPendingUpdates() {
std::vector<PendingNetworkConfigurationUpdate> list;
for (const auto& [id, pending_update] : id_to_pending_update_map_)
list.emplace_back(pending_update);
return list;
}
std::optional<PendingNetworkConfigurationUpdate>
FakePendingNetworkConfigurationTracker::GetPendingUpdate(
const std::string& change_guid,
const NetworkIdentifier& id) {
if (!base::Contains(id_to_pending_update_map_, id) ||
id_to_pending_update_map_.at(id).change_guid() != change_guid) {
return std::nullopt;
}
return id_to_pending_update_map_.at(id);
}
PendingNetworkConfigurationUpdate*
FakePendingNetworkConfigurationTracker::GetPendingUpdateById(
const NetworkIdentifier& id) {
if (!base::Contains(id_to_pending_update_map_, id))
return nullptr;
return &id_to_pending_update_map_.at(id);
}
int FakePendingNetworkConfigurationTracker::GetCompletedAttempts(
const NetworkIdentifier& id) {
DCHECK(id_to_completed_attempts_map_.count(id));
return id_to_completed_attempts_map_[id];
}
} // namespace ash::sync_wifi
|