Commit 01bbf565 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Tether] Rename MasterHostScanCache to TopLevelHostScanCache

Removes oppressive language from //chromeos/components/tether.

Bug: 1123072
Change-Id: I570c8e252828e6688cbb854ffedf28a7434521e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387340
Auto-Submit: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarRegan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803598}
parent 0bc66ade
......@@ -60,8 +60,6 @@ static_library("tether") {
"keep_alive_operation.h",
"keep_alive_scheduler.cc",
"keep_alive_scheduler.h",
"master_host_scan_cache.cc",
"master_host_scan_cache.h",
"message_transfer_operation.cc",
"message_transfer_operation.h",
"message_wrapper.cc",
......@@ -107,6 +105,8 @@ static_library("tether") {
"tether_session_completion_logger.h",
"timer_factory.cc",
"timer_factory.h",
"top_level_host_scan_cache.cc",
"top_level_host_scan_cache.h",
"wifi_hotspot_connector.cc",
"wifi_hotspot_connector.h",
"wifi_hotspot_disconnector.h",
......@@ -238,7 +238,6 @@ source_set("unit_tests") {
"hotspot_usage_duration_tracker_unittest.cc",
"keep_alive_operation_unittest.cc",
"keep_alive_scheduler_unittest.cc",
"master_host_scan_cache_unittest.cc",
"message_transfer_operation_unittest.cc",
"message_wrapper_unittest.cc",
"network_configuration_remover_unittest.cc",
......@@ -254,6 +253,7 @@ source_set("unit_tests") {
"tether_host_response_recorder_unittest.cc",
"tether_network_disconnection_handler_unittest.cc",
"tether_session_completion_logger_unittest.cc",
"top_level_host_scan_cache_unittest.cc",
"wifi_hotspot_connector_unittest.cc",
"wifi_hotspot_disconnector_impl_unittest.cc",
]
......
......@@ -14,8 +14,8 @@
#include "chromeos/components/tether/device_status_util.h"
#include "chromeos/components/tether/gms_core_notifications_state_tracker_impl.h"
#include "chromeos/components/tether/host_scan_cache.h"
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/tether_host_fetcher.h"
#include "chromeos/components/tether/top_level_host_scan_cache.h"
#include "chromeos/network/network_state.h"
#include "components/session_manager/core/session_manager.h"
......
......@@ -23,9 +23,9 @@
#include "chromeos/components/tether/gms_core_notifications_state_tracker_impl.h"
#include "chromeos/components/tether/host_scan_device_prioritizer.h"
#include "chromeos/components/tether/host_scanner.h"
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/mock_tether_host_response_recorder.h"
#include "chromeos/components/tether/proto_test_util.h"
#include "chromeos/components/tether/top_level_host_scan_cache.h"
#include "chromeos/network/network_state_test_helper.h"
#include "chromeos/services/device_sync/public/cpp/fake_device_sync_client.h"
#include "chromeos/services/secure_channel/public/cpp/client/fake_secure_channel_client.h"
......
......@@ -19,7 +19,6 @@
#include "chromeos/components/tether/host_scanner_impl.h"
#include "chromeos/components/tether/hotspot_usage_duration_tracker.h"
#include "chromeos/components/tether/keep_alive_scheduler.h"
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/network_connection_handler_tether_delegate.h"
#include "chromeos/components/tether/network_host_scan_cache.h"
#include "chromeos/components/tether/network_list_sorter.h"
......@@ -31,6 +30,7 @@
#include "chromeos/components/tether/tether_network_disconnection_handler.h"
#include "chromeos/components/tether/tether_session_completion_logger.h"
#include "chromeos/components/tether/timer_factory.h"
#include "chromeos/components/tether/top_level_host_scan_cache.h"
#include "chromeos/components/tether/wifi_hotspot_connector.h"
namespace chromeos {
......@@ -116,21 +116,21 @@ SynchronousShutdownObjectContainerImpl::SynchronousShutdownObjectContainerImpl(
network_state_handler_,
tether_host_response_recorder_.get(),
device_id_tether_network_guid_map_.get())),
master_host_scan_cache_(std::make_unique<MasterHostScanCache>(
top_level_host_scan_cache_(std::make_unique<TopLevelHostScanCache>(
std::make_unique<TimerFactory>(),
active_host_.get(),
network_host_scan_cache_.get(),
persistent_host_scan_cache_.get())),
notification_remover_(
std::make_unique<NotificationRemover>(network_state_handler_,
notification_remover_(std::make_unique<NotificationRemover>(
network_state_handler_,
notification_presenter,
master_host_scan_cache_.get(),
top_level_host_scan_cache_.get(),
active_host_.get())),
keep_alive_scheduler_(std::make_unique<KeepAliveScheduler>(
device_sync_client,
secure_channel_client,
active_host_.get(),
master_host_scan_cache_.get(),
top_level_host_scan_cache_.get(),
device_id_tether_network_guid_map_.get())),
hotspot_usage_duration_tracker_(
std::make_unique<HotspotUsageDurationTracker>(
......@@ -153,7 +153,7 @@ SynchronousShutdownObjectContainerImpl::SynchronousShutdownObjectContainerImpl(
gms_core_notifications_state_tracker,
notification_presenter,
device_id_tether_network_guid_map_.get(),
master_host_scan_cache_.get(),
top_level_host_scan_cache_.get(),
connection_preserver_.get(),
base::DefaultClock::GetInstance())),
host_scan_scheduler_(
......@@ -161,8 +161,7 @@ SynchronousShutdownObjectContainerImpl::SynchronousShutdownObjectContainerImpl(
host_scanner_.get(),
session_manager)),
host_connection_metrics_logger_(
std::make_unique<HostConnectionMetricsLogger>(
active_host_.get())),
std::make_unique<HostConnectionMetricsLogger>(active_host_.get())),
tether_connector_(std::make_unique<TetherConnectorImpl>(
device_sync_client,
secure_channel_client,
......@@ -172,7 +171,7 @@ SynchronousShutdownObjectContainerImpl::SynchronousShutdownObjectContainerImpl(
asychronous_container->tether_host_fetcher(),
tether_host_response_recorder_.get(),
device_id_tether_network_guid_map_.get(),
master_host_scan_cache_.get(),
top_level_host_scan_cache_.get(),
notification_presenter,
host_connection_metrics_logger_.get(),
asychronous_container->disconnect_tethering_request_sender(),
......@@ -210,7 +209,7 @@ ActiveHost* SynchronousShutdownObjectContainerImpl::active_host() {
}
HostScanCache* SynchronousShutdownObjectContainerImpl::host_scan_cache() {
return master_host_scan_cache_.get();
return top_level_host_scan_cache_.get();
}
HostScanScheduler*
......
......@@ -44,7 +44,7 @@ class HostScanDevicePrioritizerImpl;
class HotspotUsageDurationTracker;
class KeepAliveScheduler;
class HostConnectionMetricsLogger;
class MasterHostScanCache;
class TopLevelHostScanCache;
class NetworkHostScanCache;
class NetworkListSorter;
class NotificationPresenter;
......@@ -134,7 +134,7 @@ class SynchronousShutdownObjectContainerImpl
active_host_network_state_updater_;
std::unique_ptr<PersistentHostScanCache> persistent_host_scan_cache_;
std::unique_ptr<NetworkHostScanCache> network_host_scan_cache_;
std::unique_ptr<MasterHostScanCache> master_host_scan_cache_;
std::unique_ptr<TopLevelHostScanCache> top_level_host_scan_cache_;
std::unique_ptr<NotificationRemover> notification_remover_;
std::unique_ptr<KeepAliveScheduler> keep_alive_scheduler_;
std::unique_ptr<HotspotUsageDurationTracker> hotspot_usage_duration_tracker_;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/top_level_host_scan_cache.h"
#include <algorithm>
......@@ -17,7 +17,7 @@ namespace chromeos {
namespace tether {
MasterHostScanCache::MasterHostScanCache(
TopLevelHostScanCache::TopLevelHostScanCache(
std::unique_ptr<TimerFactory> timer_factory,
ActiveHost* active_host,
HostScanCache* network_host_scan_cache,
......@@ -30,14 +30,14 @@ MasterHostScanCache::MasterHostScanCache(
InitializeFromPersistentCache();
}
MasterHostScanCache::~MasterHostScanCache() {
TopLevelHostScanCache::~TopLevelHostScanCache() {
DCHECK(ActiveHost::ActiveHostStatus::DISCONNECTED ==
active_host_->GetActiveHostStatus());
for (const auto& tether_guid : GetTetherGuidsInCache())
RemoveHostScanResult(tether_guid);
}
void MasterHostScanCache::SetHostScanResult(const HostScanCacheEntry& entry) {
void TopLevelHostScanCache::SetHostScanResult(const HostScanCacheEntry& entry) {
auto found_iter = tether_guid_to_timer_map_.find(entry.tether_network_guid);
if (found_iter == tether_guid_to_timer_map_.end()) {
// Only check whether this entry exists in the cache after intialization
......@@ -63,7 +63,7 @@ void MasterHostScanCache::SetHostScanResult(const HostScanCacheEntry& entry) {
StartTimer(entry.tether_network_guid);
}
bool MasterHostScanCache::RemoveHostScanResultImpl(
bool TopLevelHostScanCache::RemoveHostScanResultImpl(
const std::string& tether_network_guid) {
DCHECK(!tether_network_guid.empty());
......@@ -104,7 +104,7 @@ bool MasterHostScanCache::RemoveHostScanResultImpl(
removed_from_timer_map;
}
std::unordered_set<std::string> MasterHostScanCache::GetTetherGuidsInCache() {
std::unordered_set<std::string> TopLevelHostScanCache::GetTetherGuidsInCache() {
std::unordered_set<std::string> tether_guids;
for (const auto& entry : tether_guid_to_timer_map_)
tether_guids.insert(entry.first);
......@@ -113,7 +113,7 @@ std::unordered_set<std::string> MasterHostScanCache::GetTetherGuidsInCache() {
return tether_guids;
}
bool MasterHostScanCache::ExistsInCache(
bool TopLevelHostScanCache::ExistsInCache(
const std::string& tether_network_guid) {
bool exists_in_network_cache =
network_host_scan_cache_->ExistsInCache(tether_network_guid);
......@@ -134,7 +134,7 @@ bool MasterHostScanCache::ExistsInCache(
exists_in_timer_map;
}
bool MasterHostScanCache::DoesHostRequireSetup(
bool TopLevelHostScanCache::DoesHostRequireSetup(
const std::string& tether_network_guid) {
// |network_host_scan_cache_| does not keep track of this value since the
// networking stack does not store it internally. Instead, query
......@@ -142,7 +142,7 @@ bool MasterHostScanCache::DoesHostRequireSetup(
return persistent_host_scan_cache_->DoesHostRequireSetup(tether_network_guid);
}
void MasterHostScanCache::InitializeFromPersistentCache() {
void TopLevelHostScanCache::InitializeFromPersistentCache() {
is_initializing_ = true;
// If a crash occurs, Tether networks which were previously present will no
......@@ -159,7 +159,7 @@ void MasterHostScanCache::InitializeFromPersistentCache() {
is_initializing_ = false;
}
void MasterHostScanCache::StartTimer(const std::string& tether_network_guid) {
void TopLevelHostScanCache::StartTimer(const std::string& tether_network_guid) {
auto found_iter = tether_guid_to_timer_map_.find(tether_network_guid);
DCHECK(found_iter != tether_guid_to_timer_map_.end());
DCHECK(!found_iter->second->IsRunning());
......@@ -172,11 +172,12 @@ void MasterHostScanCache::StartTimer(const std::string& tether_network_guid) {
found_iter->second->Start(
FROM_HERE,
base::TimeDelta::FromMinutes(kNumMinutesBeforeCacheEntryExpires),
base::BindOnce(&MasterHostScanCache::OnTimerFired,
base::BindOnce(&TopLevelHostScanCache::OnTimerFired,
weak_ptr_factory_.GetWeakPtr(), tether_network_guid));
}
void MasterHostScanCache::OnTimerFired(const std::string& tether_network_guid) {
void TopLevelHostScanCache::OnTimerFired(
const std::string& tether_network_guid) {
if (active_host_->GetTetherNetworkGuid() == tether_network_guid) {
// Log as a warning. This situation should be uncommon in practice since
// KeepAliveScheduler should schedule a new keep-alive status update every
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_TETHER_MASTER_HOST_SCAN_CACHE_H_
#define CHROMEOS_COMPONENTS_TETHER_MASTER_HOST_SCAN_CACHE_H_
#ifndef CHROMEOS_COMPONENTS_TETHER_TOP_LEVEL_HOST_SCAN_CACHE_H_
#define CHROMEOS_COMPONENTS_TETHER_TOP_LEVEL_HOST_SCAN_CACHE_H_
#include <memory>
#include <string>
......@@ -27,9 +27,9 @@ class TimerFactory;
// HostScanCache implementation which interfaces with the network stack as well
// as storing scanned device properties persistently and recovering stored
// properties after a browser crash. When SetHostScanResult() is called,
// MasterHostScanCache starts a timer which automatically removes scan results
// TopLevelHostScanCache starts a timer which automatically removes scan results
// after |kNumMinutesBeforeCacheEntryExpires| minutes.
class MasterHostScanCache : public HostScanCache {
class TopLevelHostScanCache : public HostScanCache {
public:
// The number of minutes that a cache entry is considered to be valid before
// it is removed from the cache. Very old host scan results are removed from
......@@ -42,11 +42,11 @@ class MasterHostScanCache : public HostScanCache {
// cache which are not discovered during the scan are removed.
static constexpr int kNumMinutesBeforeCacheEntryExpires = 120;
MasterHostScanCache(std::unique_ptr<TimerFactory> timer_factory,
TopLevelHostScanCache(std::unique_ptr<TimerFactory> timer_factory,
ActiveHost* active_host,
HostScanCache* network_host_scan_cache,
PersistentHostScanCache* persistent_host_scan_cache);
~MasterHostScanCache() override;
~TopLevelHostScanCache() override;
// HostScanCache:
void SetHostScanResult(const HostScanCacheEntry& entry) override;
......@@ -59,7 +59,7 @@ class MasterHostScanCache : public HostScanCache {
const std::string& tether_network_guid) override;
private:
friend class MasterHostScanCacheTest;
friend class TopLevelHostScanCacheTest;
void InitializeFromPersistentCache();
void StartTimer(const std::string& tether_network_guid);
......@@ -78,13 +78,13 @@ class MasterHostScanCache : public HostScanCache {
// host).
std::unordered_map<std::string, std::unique_ptr<base::OneShotTimer>>
tether_guid_to_timer_map_;
base::WeakPtrFactory<MasterHostScanCache> weak_ptr_factory_{this};
base::WeakPtrFactory<TopLevelHostScanCache> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(MasterHostScanCache);
DISALLOW_COPY_AND_ASSIGN(TopLevelHostScanCache);
};
} // namespace tether
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_TETHER_MASTER_HOST_SCAN_CACHE_H_
#endif // CHROMEOS_COMPONENTS_TETHER_TOP_LEVEL_HOST_SCAN_CACHE_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/tether/master_host_scan_cache.h"
#include "chromeos/components/tether/top_level_host_scan_cache.h"
#include <memory>
#include <unordered_map>
......@@ -102,11 +102,11 @@ class TestTimerFactory : public TimerFactory {
// TODO(khorimoto): The test uses a FakeHostScanCache to keep an in-memory
// cache of expected values. This has the potential to be confusing, since this
// is the test for MasterHostScanCache. Clean this up to avoid using
// is the test for TopLevelHostScanCache. Clean this up to avoid using
// FakeHostScanCache if possible.
class MasterHostScanCacheTest : public testing::Test {
class TopLevelHostScanCacheTest : public testing::Test {
protected:
MasterHostScanCacheTest()
TopLevelHostScanCacheTest()
: test_entries_(host_scan_test_util::CreateTestEntries()) {}
void SetUp() override {
......@@ -116,7 +116,7 @@ class MasterHostScanCacheTest : public testing::Test {
fake_persistent_host_scan_cache_ =
base::WrapUnique(new FakePersistentHostScanCache());
host_scan_cache_ = std::make_unique<MasterHostScanCache>(
host_scan_cache_ = std::make_unique<TopLevelHostScanCache>(
base::WrapUnique(test_timer_factory_), fake_active_host_.get(),
fake_network_host_scan_cache_.get(),
fake_persistent_host_scan_cache_.get());
......@@ -226,13 +226,13 @@ class MasterHostScanCacheTest : public testing::Test {
std::unique_ptr<DeviceIdTetherNetworkGuidMap>
device_id_tether_network_guid_map_;
std::unique_ptr<MasterHostScanCache> host_scan_cache_;
std::unique_ptr<TopLevelHostScanCache> host_scan_cache_;
private:
DISALLOW_COPY_AND_ASSIGN(MasterHostScanCacheTest);
DISALLOW_COPY_AND_ASSIGN(TopLevelHostScanCacheTest);
};
TEST_F(MasterHostScanCacheTest, TestSetScanResultsAndLetThemExpire) {
TEST_F(TopLevelHostScanCacheTest, TestSetScanResultsAndLetThemExpire) {
SetHostScanResult(test_entries_.at(host_scan_test_util::kTetherGuid0));
VerifyCacheContainsExpectedContents(1u /* expected_size */);
......@@ -258,7 +258,7 @@ TEST_F(MasterHostScanCacheTest, TestSetScanResultsAndLetThemExpire) {
VerifyCacheContainsExpectedContents(0 /* expected_size */);
}
TEST_F(MasterHostScanCacheTest, TestSetScanResultThenUpdateAndRemove) {
TEST_F(TopLevelHostScanCacheTest, TestSetScanResultThenUpdateAndRemove) {
SetHostScanResult(test_entries_.at(host_scan_test_util::kTetherGuid0));
VerifyCacheContainsExpectedContents(1u /* expected_size */);
......@@ -280,7 +280,7 @@ TEST_F(MasterHostScanCacheTest, TestSetScanResultThenUpdateAndRemove) {
VerifyCacheContainsExpectedContents(0 /* expected_size */);
}
TEST_F(MasterHostScanCacheTest, TestSetScanResult_SetActiveHost) {
TEST_F(TopLevelHostScanCacheTest, TestSetScanResult_SetActiveHost) {
SetHostScanResult(test_entries_.at(host_scan_test_util::kTetherGuid0));
VerifyCacheContainsExpectedContents(1u /* expected_size */);
......@@ -306,7 +306,7 @@ TEST_F(MasterHostScanCacheTest, TestSetScanResult_SetActiveHost) {
VerifyCacheContainsExpectedContents(0 /* expected_size */);
}
TEST_F(MasterHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
TEST_F(TopLevelHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
// Delete the cache that was initialized in SetUp(). This test requires extra
// setup before initialization.
host_scan_cache_.reset();
......@@ -317,7 +317,8 @@ TEST_F(MasterHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
fake_persistent_host_scan_cache_->SetHostScanResult(
test_entries_.at(host_scan_test_util::kTetherGuid1));
// These results are expected to be in the master cache after it is created.
// These results are expected to be in the top-level cache after it is
// created.
expected_cache_->SetHostScanResult(
test_entries_.at(host_scan_test_util::kTetherGuid0));
expected_cache_->SetHostScanResult(
......@@ -325,7 +326,7 @@ TEST_F(MasterHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
// Alert the timer factory that these GUIDs will be added. To ensure that the
// timer GUID is set in the correct order, iterate through the stored cache
// entries to mimic the iteration order performed in MasterHostScanCache.
// entries to mimic the iteration order performed in TopLevelHostScanCache.
// See crbug.com/750342.
test_timer_factory_ = new TestTimerFactory();
std::unordered_map<std::string, HostScanCacheEntry> persisted_entries =
......@@ -333,9 +334,9 @@ TEST_F(MasterHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
for (const auto& it : persisted_entries)
test_timer_factory_->set_tether_network_guid_for_next_timer(it.first);
// Create the master cache. It should have automatically picked up the
// Create the top-level cache. It should have automatically picked up the
// persisted scan results, even though they were not explicitly added.
host_scan_cache_ = std::make_unique<MasterHostScanCache>(
host_scan_cache_ = std::make_unique<TopLevelHostScanCache>(
base::WrapUnique(test_timer_factory_), fake_active_host_.get(),
fake_network_host_scan_cache_.get(),
fake_persistent_host_scan_cache_.get());
......@@ -350,7 +351,7 @@ TEST_F(MasterHostScanCacheTest, TestRecoversFromCrashAndCleansUpWhenDeleted) {
EXPECT_TRUE(
host_scan_cache_->ExistsInCache(host_scan_test_util::kTetherGuid1));
// Now, delete the master cache. It should result in the sub-caches being
// Now, delete the top-level cache. It should result in the sub-caches being
// cleared. This verifies that the persistent cache is cleared when logging
// out (i.e., when the Tether component is shut down without a crash).
host_scan_cache_.reset();
......
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