Commit 8fbee970 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[Nearby] Add contact manager implementation skeleton and fake

Add a contact manager implementation class, where the overridden methods
are currently marked as NOTIMPLEMENTED(). We also include a fake
implementation and factory for use in unit tests.

The full implementation will happen in a follow-up CL. For now, these
classes unblock consumers of the contact manager.

Bug: b/154863722
Change-Id: I1fe9813fe0578f72aa50f13d402995ed4a46b6d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308948Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Josh Nohle <nohle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791050}
parent 53a80b56
...@@ -6,6 +6,8 @@ source_set("contacts") { ...@@ -6,6 +6,8 @@ source_set("contacts") {
sources = [ sources = [
"nearby_share_contact_manager.cc", "nearby_share_contact_manager.cc",
"nearby_share_contact_manager.h", "nearby_share_contact_manager.h",
"nearby_share_contact_manager_impl.cc",
"nearby_share_contact_manager_impl.h",
] ]
deps = [ deps = [
...@@ -13,3 +15,18 @@ source_set("contacts") { ...@@ -13,3 +15,18 @@ source_set("contacts") {
"//chrome/browser/nearby_sharing/proto", "//chrome/browser/nearby_sharing/proto",
] ]
} }
source_set("test_support") {
testonly = true
sources = [
"fake_nearby_share_contact_manager.cc",
"fake_nearby_share_contact_manager.h",
]
deps = [
":contacts",
"//base",
"//chrome/browser/nearby_sharing/proto",
]
}
// Copyright 2020 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 "chrome/browser/nearby_sharing/contacts/fake_nearby_share_contact_manager.h"
FakeNearbyShareContactManager::Factory::Factory() = default;
FakeNearbyShareContactManager::Factory::~Factory() = default;
std::unique_ptr<NearbyShareContactManager>
FakeNearbyShareContactManager::Factory::CreateInstance() {
auto instance = std::make_unique<FakeNearbyShareContactManager>();
instances_.push_back(instance.get());
return instance;
}
FakeNearbyShareContactManager::FakeNearbyShareContactManager() = default;
FakeNearbyShareContactManager::~FakeNearbyShareContactManager() = default;
void FakeNearbyShareContactManager::NotifyObservers(
bool contacts_list_changed,
bool contacts_added_to_allowlist,
bool contacts_removed_from_allowlist,
const std::set<std::string>& allowed_contact_ids,
const base::Optional<std::vector<nearbyshare::proto::ContactRecord>>&
contacts) {
NotifyContactsUpdated(contacts_list_changed, contacts_added_to_allowlist,
contacts_removed_from_allowlist, allowed_contact_ids,
contacts);
}
void FakeNearbyShareContactManager::DownloadContacts(
bool only_download_if_changed) {
download_contacts_calls_.push_back(only_download_if_changed);
}
void FakeNearbyShareContactManager::SetAllowedContacts(
const std::set<std::string>& allowed_contact_ids) {
set_allowed_contacts_calls_.push_back(allowed_contact_ids);
}
void FakeNearbyShareContactManager::OnStart() {}
void FakeNearbyShareContactManager::OnStop() {}
// Copyright 2020 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 CHROME_BROWSER_NEARBY_SHARING_CONTACTS_FAKE_NEARBY_SHARE_CONTACT_MANAGER_H_
#define CHROME_BROWSER_NEARBY_SHARING_CONTACTS_FAKE_NEARBY_SHARE_CONTACT_MANAGER_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager.h"
#include "chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager_impl.h"
#include "chrome/browser/nearby_sharing/proto/rpc_resources.pb.h"
// A fake implementation of NearbyShareContactManager, along with a fake
// factory, to be used in tests. Stores parameters input into
// NearbyShareContactManager method calls. Provides a method to notify
// observers.
class FakeNearbyShareContactManager : public NearbyShareContactManager {
public:
// Factory that creates FakeNearbyShareContactManager instances. Use in
// NearbyShareContactManagerImpl::Factor::SetFactoryForTesting() in unit
// tests.
class Factory : NearbyShareContactManagerImpl::Factory {
Factory();
~Factory() override;
// Returns all FakeNearbyShareContactManager instances created by
// CreateInstance().
std::vector<FakeNearbyShareContactManager*>& instances() {
return instances_;
}
private:
// NearbyShareContactManagerImpl::Factory:
std::unique_ptr<NearbyShareContactManager> CreateInstance() override;
std::vector<FakeNearbyShareContactManager*> instances_;
};
FakeNearbyShareContactManager();
~FakeNearbyShareContactManager() override;
void NotifyObservers(
bool contacts_list_changed,
bool contacts_added_to_allowlist,
bool contacts_removed_from_allowlist,
const std::set<std::string>& allowed_contact_ids,
const base::Optional<std::vector<nearbyshare::proto::ContactRecord>>&
contacts);
// Returns inputs of all DownloadContacts() calls.
const std::vector<bool>& download_contacts_calls() const {
return download_contacts_calls_;
}
// Returns inputs of all SetAllowedContacts() calls.
const std::vector<std::set<std::string>>& set_allowed_contacts_calls() const {
return set_allowed_contacts_calls_;
}
private:
// NearbyShareContactsManager:
void DownloadContacts(bool only_download_if_changed) override;
void SetAllowedContacts(
const std::set<std::string>& allowed_contact_ids) override;
void OnStart() override;
void OnStop() override;
std::vector<bool> download_contacts_calls_;
std::vector<std::set<std::string>> set_allowed_contacts_calls_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_CONTACTS_FAKE_NEARBY_SHARE_CONTACT_MANAGER_H_
...@@ -45,9 +45,6 @@ class NearbyShareContactManager { ...@@ -45,9 +45,6 @@ class NearbyShareContactManager {
void Stop(); void Stop();
bool is_running() { return is_running_; } bool is_running() { return is_running_; }
// Clears all contact-related data.
virtual void ClearAllData() = 0;
// Makes RPC calls to check if the user's contact list has changed since the // Makes RPC calls to check if the user's contact list has changed since the
// last call to the server. If it changed or if |only_download_if_changed| is // last call to the server. If it changed or if |only_download_if_changed| is
// false, the contact list is downloaded from the server. The list of allowed // false, the contact list is downloaded from the server. The list of allowed
......
// Copyright 2020 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 "chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager_impl.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
// static
NearbyShareContactManagerImpl::Factory*
NearbyShareContactManagerImpl::Factory::test_factory_ = nullptr;
// static
std::unique_ptr<NearbyShareContactManager>
NearbyShareContactManagerImpl::Factory::Create() {
if (test_factory_) {
return test_factory_->CreateInstance();
}
return base::WrapUnique(new NearbyShareContactManagerImpl());
}
// static
void NearbyShareContactManagerImpl::Factory::SetFactoryForTesting(
Factory* test_factory) {
test_factory_ = test_factory;
}
NearbyShareContactManagerImpl::Factory::~Factory() = default;
NearbyShareContactManagerImpl::NearbyShareContactManagerImpl() = default;
NearbyShareContactManagerImpl::~NearbyShareContactManagerImpl() = default;
void NearbyShareContactManagerImpl::DownloadContacts(
bool only_download_if_changed) {
NOTIMPLEMENTED();
}
void NearbyShareContactManagerImpl::SetAllowedContacts(
const std::set<std::string>& allowed_contact_ids) {
NOTIMPLEMENTED();
}
void NearbyShareContactManagerImpl::OnStart() {
NOTIMPLEMENTED();
}
void NearbyShareContactManagerImpl::OnStop() {
NOTIMPLEMENTED();
}
// Copyright 2020 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 CHROME_BROWSER_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACT_MANAGER_IMPL_H_
#define CHROME_BROWSER_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACT_MANAGER_IMPL_H_
#include <memory>
#include <set>
#include <string>
#include "chrome/browser/nearby_sharing/contacts/nearby_share_contact_manager.h"
// TODO(nohle): Add description after class is fully implemented.
class NearbyShareContactManagerImpl : public NearbyShareContactManager {
public:
class Factory {
public:
static std::unique_ptr<NearbyShareContactManager> Create();
static void SetFactoryForTesting(Factory* test_factory);
protected:
virtual ~Factory();
virtual std::unique_ptr<NearbyShareContactManager> CreateInstance() = 0;
private:
static Factory* test_factory_;
};
~NearbyShareContactManagerImpl() override;
private:
NearbyShareContactManagerImpl();
// NearbyShareContactsManager:
void DownloadContacts(bool only_download_if_changed) override;
void SetAllowedContacts(
const std::set<std::string>& allowed_contact_ids) override;
void OnStart() override;
void OnStop() override;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACT_MANAGER_IMPL_H_
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