Commit fba4e0b6 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[CrOS Multidevice] Remove RemoteBeaconSeedFetcher.

This class is no longer used and can be deleted. BeaconSeeds are no
longer fetched on demand; they are always present in a RemoteDevice
object.

R=jhawkins@chromium.org

Bug: 824568, 752273
Change-Id: I6047f5ed9da2abd01c93e26c752e46e9562ff2a1
Reviewed-on: https://chromium-review.googlesource.com/1087875
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565081}
parent 2c3eb17e
......@@ -17,7 +17,6 @@
#include "components/cryptauth/connection.h"
#include "components/cryptauth/connection_finder.h"
#include "components/cryptauth/connection_observer.h"
#include "components/cryptauth/remote_beacon_seed_fetcher.h"
#include "components/cryptauth/remote_device_ref.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_device.h"
......
......@@ -18,7 +18,6 @@
#include "chromeos/services/secure_channel/ble_synchronizer.h"
#include "components/cryptauth/cryptauth_service.h"
#include "components/cryptauth/local_device_data_provider.h"
#include "components/cryptauth/remote_beacon_seed_fetcher.h"
namespace chromeos {
......@@ -89,9 +88,6 @@ AsynchronousShutdownObjectContainerImpl::
local_device_data_provider_(
std::make_unique<cryptauth::LocalDeviceDataProvider>(
cryptauth_service)),
remote_beacon_seed_fetcher_(
std::make_unique<cryptauth::RemoteBeaconSeedFetcher>(
cryptauth_service->GetCryptAuthDeviceManager())),
ble_service_data_helper_(
BleServiceDataHelperImpl::Factory::Get()->BuildInstance(
tether_host_fetcher_,
......
......@@ -20,7 +20,6 @@ class PrefService;
namespace cryptauth {
class CryptAuthService;
class LocalDeviceDataProvider;
class RemoteBeaconSeedFetcher;
} // namespace cryptauth
namespace device {
......@@ -139,8 +138,6 @@ class AsynchronousShutdownObjectContainerImpl
TetherHostFetcher* tether_host_fetcher_;
std::unique_ptr<cryptauth::LocalDeviceDataProvider>
local_device_data_provider_;
std::unique_ptr<cryptauth::RemoteBeaconSeedFetcher>
remote_beacon_seed_fetcher_;
std::unique_ptr<secure_channel::BleServiceDataHelper>
ble_service_data_helper_;
std::unique_ptr<BleAdvertisementDeviceQueue> ble_advertisement_device_queue_;
......
......@@ -34,7 +34,7 @@ BleServiceDataHelper::IdentifyRemoteDevice(
}
PA_LOG(ERROR) << "BleServiceDataHelper::IdentifyRemoteDevice(): Identified "
<< "device was not present in the provided DeviceIdPairSet.";
"device was not present in the provided DeviceIdPairSet.";
NOTREACHED();
return base::nullopt;
}
......
......@@ -65,8 +65,6 @@ static_library("cryptauth") {
"raw_eid_generator.h",
"raw_eid_generator_impl.cc",
"raw_eid_generator_impl.h",
"remote_beacon_seed_fetcher.cc",
"remote_beacon_seed_fetcher.h",
"remote_device.cc",
"remote_device.h",
"remote_device_cache.cc",
......@@ -164,8 +162,6 @@ static_library("test_support") {
"mock_foreground_eid_generator.h",
"mock_local_device_data_provider.cc",
"mock_local_device_data_provider.h",
"mock_remote_beacon_seed_fetcher.cc",
"mock_remote_beacon_seed_fetcher.h",
"mock_sync_scheduler.cc",
"mock_sync_scheduler.h",
"remote_device_test_util.cc",
......@@ -204,7 +200,6 @@ source_set("unit_tests") {
"foreground_eid_generator_unittest.cc",
"local_device_data_provider_unittest.cc",
"raw_eid_generator_impl_unittest.cc",
"remote_beacon_seed_fetcher_unittest.cc",
"remote_device_cache_unittest.cc",
"remote_device_loader_unittest.cc",
"remote_device_provider_impl_unittest.cc",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cryptauth/mock_remote_beacon_seed_fetcher.h"
#include "components/cryptauth/cryptauth_device_manager.h"
namespace cryptauth {
MockRemoteBeaconSeedFetcher::MockRemoteBeaconSeedFetcher()
: RemoteBeaconSeedFetcher(nullptr) {}
MockRemoteBeaconSeedFetcher::~MockRemoteBeaconSeedFetcher() {}
bool MockRemoteBeaconSeedFetcher::FetchSeedsForDeviceId(
const std::string& device_id,
std::vector<BeaconSeed>* beacon_seeds_out) const {
const auto& seeds_iter = device_id_to_beacon_seeds_map_.find(device_id);
if (seeds_iter == device_id_to_beacon_seeds_map_.end())
return false;
*beacon_seeds_out = seeds_iter->second;
return true;
}
void MockRemoteBeaconSeedFetcher::SetSeedsForDeviceId(
const std::string& device_id,
const std::vector<BeaconSeed>* beacon_seeds) {
if (!beacon_seeds) {
const auto& it = device_id_to_beacon_seeds_map_.find(device_id);
if (it != device_id_to_beacon_seeds_map_.end())
device_id_to_beacon_seeds_map_.erase(it);
return;
}
device_id_to_beacon_seeds_map_[device_id] = *beacon_seeds;
}
} // namespace cryptauth
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CRYPTAUTH_MOCK_BEACON_SEED_FETCHER_H_
#define COMPONENTS_CRYPTAUTH_MOCK_BEACON_SEED_FETCHER_H_
#include <map>
#include <vector>
#include "components/cryptauth/proto/cryptauth_api.pb.h"
#include "components/cryptauth/remote_beacon_seed_fetcher.h"
namespace cryptauth {
class MockRemoteBeaconSeedFetcher : public RemoteBeaconSeedFetcher {
public:
MockRemoteBeaconSeedFetcher();
~MockRemoteBeaconSeedFetcher() override;
// If |beacon_seeds| is null, FetchSeedsForDevice() will fail for the same
// |remote_device|.
void SetSeedsForDeviceId(const std::string& device_id,
const std::vector<BeaconSeed>* beacon_seeds);
// RemoteBeaconSeedFetcher:
bool FetchSeedsForDeviceId(
const std::string& device_id,
std::vector<BeaconSeed>* beacon_seeds_out) const override;
private:
std::map<std::string, std::vector<BeaconSeed>> device_id_to_beacon_seeds_map_;
DISALLOW_COPY_AND_ASSIGN(MockRemoteBeaconSeedFetcher);
};
} // namespace cryptauth
#endif // COMPONENTS_CRYPTAUTH_MOCK_BEACON_SEED_FETCHER_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cryptauth/remote_beacon_seed_fetcher.h"
#include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/remote_device_ref.h"
namespace cryptauth {
RemoteBeaconSeedFetcher::RemoteBeaconSeedFetcher(
const CryptAuthDeviceManager* device_manager)
: device_manager_(device_manager) {}
RemoteBeaconSeedFetcher::~RemoteBeaconSeedFetcher() {}
bool RemoteBeaconSeedFetcher::FetchSeedsForDeviceId(
const std::string& device_id,
std::vector<BeaconSeed>* beacon_seeds_out) const {
for(const auto& device_info : device_manager_->GetSyncedDevices()) {
if (RemoteDeviceRef::GenerateDeviceId(device_info.public_key()) ==
device_id) {
if (device_info.beacon_seeds_size() == 0) {
return false;
}
beacon_seeds_out->clear();
for (int i = 0; i < device_info.beacon_seeds_size(); i++) {
beacon_seeds_out->push_back(device_info.beacon_seeds(i));
}
return true;
}
}
return false;
}
} // namespace cryptauth
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_CRYPTAUTH_REMOTE_BEACON_SEED_FETCHER_H_
#define COMPONENTS_CRYPTAUTH_REMOTE_BEACON_SEED_FETCHER_H_
#include <vector>
#include "base/macros.h"
#include "components/cryptauth/proto/cryptauth_api.pb.h"
namespace cryptauth {
class CryptAuthDeviceManager;
// Fetches |BeaconSeed|s corresponding to a given |RemoteDevice|. Note that an
// alternate solution would be to embed a list of |BeaconSeed|s in each
// |RemoteDevice| object; however, because |BeaconSeed| objects take up almost
// 1kB of memory apiece, that approach adds unnecessary memory overhead.
class RemoteBeaconSeedFetcher {
public:
RemoteBeaconSeedFetcher(const CryptAuthDeviceManager* device_manager);
virtual ~RemoteBeaconSeedFetcher();
virtual bool FetchSeedsForDeviceId(
const std::string& device_id,
std::vector<BeaconSeed>* beacon_seeds_out) const;
private:
// Not owned by this instance and must outlive it.
const CryptAuthDeviceManager* device_manager_;
DISALLOW_COPY_AND_ASSIGN(RemoteBeaconSeedFetcher);
};
} // namespace cryptauth
#endif // COMPONENTS_CRYPTAUTH_REMOTE_BEACON_SEED_FETCHER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/cryptauth/remote_beacon_seed_fetcher.h"
#include <memory>
#include "base/macros.h"
#include "components/cryptauth/cryptauth_client.h"
#include "components/cryptauth/fake_cryptauth_device_manager.h"
#include "components/cryptauth/remote_device_ref.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::StrictMock;
using testing::Return;
namespace cryptauth {
namespace {
const std::string fake_beacon_seed1_data = "fakeBeaconSeed1Data";
const int64_t fake_beacon_seed1_start_ms = 1000L;
const int64_t fake_beacon_seed1_end_ms = 2000L;
const std::string fake_beacon_seed2_data = "fakeBeaconSeed2Data";
const int64_t fake_beacon_seed2_start_ms = 2000L;
const int64_t fake_beacon_seed2_end_ms = 3000L;
const std::string fake_beacon_seed3_data = "fakeBeaconSeed3Data";
const int64_t fake_beacon_seed3_start_ms = 1000L;
const int64_t fake_beacon_seed3_end_ms = 2000L;
const std::string fake_beacon_seed4_data = "fakeBeaconSeed4Data";
const int64_t fake_beacon_seed4_start_ms = 2000L;
const int64_t fake_beacon_seed4_end_ms = 3000L;
const std::string public_key1 = "publicKey1";
const std::string public_key2 = "publicKey2";
ExternalDeviceInfo CreateFakeInfo1() {
BeaconSeed seed1;
seed1.set_data(fake_beacon_seed1_data);
seed1.set_start_time_millis(fake_beacon_seed1_start_ms);
seed1.set_end_time_millis(fake_beacon_seed1_end_ms);
BeaconSeed seed2;
seed2.set_data(fake_beacon_seed2_data);
seed2.set_start_time_millis(fake_beacon_seed2_start_ms);
seed2.set_end_time_millis(fake_beacon_seed2_end_ms);
ExternalDeviceInfo info1;
info1.set_public_key(public_key1);
info1.add_beacon_seeds()->CopyFrom(seed1);
info1.add_beacon_seeds()->CopyFrom(seed2);
return info1;
}
ExternalDeviceInfo CreateFakeInfo2() {
BeaconSeed seed3;
seed3.set_data(fake_beacon_seed3_data);
seed3.set_start_time_millis(fake_beacon_seed3_start_ms);
seed3.set_end_time_millis(fake_beacon_seed3_end_ms);
BeaconSeed seed4;
seed4.set_data(fake_beacon_seed4_data);
seed4.set_start_time_millis(fake_beacon_seed4_start_ms);
seed4.set_end_time_millis(fake_beacon_seed4_end_ms);
ExternalDeviceInfo info2;
info2.set_public_key(public_key2);
info2.add_beacon_seeds()->CopyFrom(seed3);
info2.add_beacon_seeds()->CopyFrom(seed4);
return info2;
}
} // namespace
class CryptAuthRemoteBeaconSeedFetcherTest : public testing::Test {
protected:
CryptAuthRemoteBeaconSeedFetcherTest()
: fake_info1_(CreateFakeInfo1()), fake_info2_(CreateFakeInfo2()) {}
void SetUp() override {
fake_device_manager_ = std::make_unique<FakeCryptAuthDeviceManager>();
fetcher_ = std::make_unique<StrictMock<RemoteBeaconSeedFetcher>>(
fake_device_manager_.get());
}
std::unique_ptr<RemoteBeaconSeedFetcher> fetcher_;
std::unique_ptr<FakeCryptAuthDeviceManager> fake_device_manager_;
const ExternalDeviceInfo fake_info1_;
const ExternalDeviceInfo fake_info2_;
private:
DISALLOW_COPY_AND_ASSIGN(CryptAuthRemoteBeaconSeedFetcherTest);
};
TEST_F(CryptAuthRemoteBeaconSeedFetcherTest, TestRemoteDeviceWithNoPublicKey) {
std::vector<BeaconSeed> seeds;
EXPECT_FALSE(fetcher_->FetchSeedsForDeviceId(std::string(), &seeds));
}
TEST_F(CryptAuthRemoteBeaconSeedFetcherTest, TestNoSyncedDevices) {
std::vector<BeaconSeed> seeds;
EXPECT_FALSE(fetcher_->FetchSeedsForDeviceId(
RemoteDeviceRef::GenerateDeviceId(public_key1), &seeds));
}
TEST_F(CryptAuthRemoteBeaconSeedFetcherTest, TestDeviceHasDifferentPublicKey) {
fake_device_manager_->set_synced_devices(
std::vector<ExternalDeviceInfo>{fake_info1_, fake_info2_});
std::vector<BeaconSeed> seeds;
EXPECT_FALSE(fetcher_->FetchSeedsForDeviceId(
RemoteDeviceRef::GenerateDeviceId("differentPublicKey"), &seeds));
}
TEST_F(CryptAuthRemoteBeaconSeedFetcherTest, TestSuccess) {
fake_device_manager_->set_synced_devices(
std::vector<ExternalDeviceInfo>{fake_info1_, fake_info2_});
std::vector<BeaconSeed> seeds1;
ASSERT_TRUE(fetcher_->FetchSeedsForDeviceId(
RemoteDeviceRef::GenerateDeviceId(public_key1), &seeds1));
ASSERT_EQ(2u, seeds1.size());
EXPECT_EQ(fake_beacon_seed1_data, seeds1[0].data());
EXPECT_EQ(fake_beacon_seed1_start_ms, seeds1[0].start_time_millis());
EXPECT_EQ(fake_beacon_seed1_end_ms, seeds1[0].end_time_millis());
EXPECT_EQ(fake_beacon_seed2_data, seeds1[1].data());
EXPECT_EQ(fake_beacon_seed2_start_ms, seeds1[1].start_time_millis());
EXPECT_EQ(fake_beacon_seed2_end_ms, seeds1[1].end_time_millis());
std::vector<BeaconSeed> seeds2;
ASSERT_TRUE(fetcher_->FetchSeedsForDeviceId(
RemoteDeviceRef::GenerateDeviceId(public_key2), &seeds2));
ASSERT_EQ(2u, seeds2.size());
EXPECT_EQ(fake_beacon_seed3_data, seeds2[0].data());
EXPECT_EQ(fake_beacon_seed3_start_ms, seeds2[0].start_time_millis());
EXPECT_EQ(fake_beacon_seed3_end_ms, seeds2[0].end_time_millis());
EXPECT_EQ(fake_beacon_seed4_data, seeds2[1].data());
EXPECT_EQ(fake_beacon_seed4_start_ms, seeds2[1].start_time_millis());
EXPECT_EQ(fake_beacon_seed4_end_ms, seeds2[1].end_time_millis());
}
} // namespace cryptauth
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