Remove unused code.

PiperOrigin-RevId: 785603603
This commit is contained in:
Francis Tsui
2025-07-21 15:49:05 -07:00
committed by Copybara-Service
parent 01013cb824
commit 9d42718e68
10 changed files with 5 additions and 660 deletions
@@ -79,8 +79,6 @@ using ::nearby::sharing::api::PublicCertificateDatabase;
using ::nearby::sharing::api::SharingPlatform;
using ::nearby::sharing::proto::DeviceVisibility;
using ::nearby::sharing::proto::EncryptedMetadata;
using ::nearby::sharing::proto::ListPublicCertificatesRequest;
using ::nearby::sharing::proto::ListPublicCertificatesResponse;
using ::nearby::sharing::proto::PublicCertificate;
constexpr char kDeviceIdPrefix[] = "users/me/devices/";
@@ -225,7 +223,6 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
account_manager_(account_manager),
local_device_data_manager_(local_device_data_manager),
contact_manager_(contact_manager),
nearby_client_(client_factory->CreateInstance()),
nearby_identity_client_(client_factory->CreateIdentityInstance()),
certificate_storage_(NearbyShareCertificateStorageImpl::Factory::Create(
preference_manager, std::move(public_certificate_database))),
@@ -299,39 +296,6 @@ NearbyShareCertificateManagerImpl::~NearbyShareCertificateManagerImpl() {
local_device_data_manager_->RemoveObserver(this);
}
void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
FetchNextPage() {
LOG(INFO) << "Downloading certificate page=" << page_number_++;
ListPublicCertificatesRequest request;
request.set_parent(device_id_);
if (next_page_token_.has_value()) {
request.set_page_token(*next_page_token_);
}
nearby_share_client_->ListPublicCertificates(
request, [this](const absl::StatusOr<ListPublicCertificatesResponse>&
response) mutable {
if (!response.ok()) {
LOG(WARNING) << "Failed to download certificates: "
<< response.status();
std::move(download_failure_callback_)();
return;
}
certificates_.insert(certificates_.end(),
response->public_certificates().begin(),
response->public_certificates().end());
if (response->next_page_token().empty()) {
LOG(INFO) << "Finished downloading " << certificates_.size()
<< " certificates from backend";
std::move(download_success_callback_)(certificates_);
return;
}
next_page_token_ = response->next_page_token();
FetchNextPage();
});
}
void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
QuerySharedCredentialsFetchNextPage() {
page_number_++;
@@ -435,10 +399,9 @@ bool NearbyShareCertificateManagerImpl::DownloadPublicCertificatesInExecutor() {
bool download_succeeded = false;
// Currently certificates download is synchronous. It completes after
// FetchNextPage() returns.
// QuerySharedCredentialsFetchNextPage() returns.
auto context = std::make_unique<CertificateDownloadContext>(
nearby_client_.get(), nearby_identity_client_.get(),
kDeviceIdPrefix + device_id,
nearby_identity_client_.get(), kDeviceIdPrefix + device_id,
[&download_succeeded]() { download_succeeded = false; },
[this, &download_succeeded](
const std::vector<PublicCertificate>& certificates) {
@@ -95,7 +95,6 @@ class NearbyShareCertificateManagerImpl
class CertificateDownloadContext {
public:
CertificateDownloadContext(
nearby::sharing::api::SharingRpcClient* nearby_share_client,
nearby::sharing::api::IdentityRpcClient* nearby_identity_client,
std::string device_id,
absl::AnyInvocable<void() &&> download_failure_callback,
@@ -103,24 +102,19 @@ class NearbyShareCertificateManagerImpl
void(const std::vector<nearby::sharing::proto::PublicCertificate>&
certificates) &&>
download_success_callback)
: nearby_share_client_(nearby_share_client),
nearby_identity_client_(nearby_identity_client),
: nearby_identity_client_(nearby_identity_client),
device_id_(std::move(device_id)),
download_failure_callback_(std::move(download_failure_callback)),
download_success_callback_(std::move(download_success_callback)) {}
// Fetches the next page of certificates.
// Fetches the next page of certificates by calling Identity API
// QuerySharedCredentials.
// If |next_page_token_| is empty, it fetches the first page.
// On successful download, if page token in the response is empty, the
// |download_success_callback_| is invoked with all downloaded certificates.
void FetchNextPage();
// Fetches the next page of certificates by calling Identity API
// QuerySharedCredentials.
void QuerySharedCredentialsFetchNextPage();
private:
nearby::sharing::api::SharingRpcClient* const nearby_share_client_;
nearby::sharing::api::IdentityRpcClient* const nearby_identity_client_;
std::string device_id_;
std::optional<std::string> next_page_token_;
@@ -78,7 +78,6 @@ using ::testing::UnorderedElementsAreArray;
const absl::Time t0 = absl::UnixEpoch() + absl::Hours(365 * 50 * 24);
constexpr char kPageTokenPrefix[] = "page_token_";
constexpr char kSecretIdPrefix[] = "secret_id_";
constexpr char kDeviceId[] = "123456789A";
constexpr char kDefaultDeviceName[] = "Josh's Chromebook";
@@ -329,53 +328,6 @@ class NearbyShareCertificateManagerImplTest
publish_device_success);
}
// Test downloading public certificates with or without errors. The RPC is
// paginated, and |num_pages| will be simulated. Any failures, as indicated by
// |result|, will be simulated on the last page.
void DownloadPublicCertificatesFlow(size_t num_pages,
DownloadPublicCertificatesResult result) {
size_t prev_num_results = download_scheduler_->handled_results().size();
cert_store_->SetPublicCertificateIds(kPublicCertificateIds);
size_t initial_num_notifications =
num_public_certs_downloaded_notifications_;
size_t initial_num_public_cert_exp_reschedules =
public_cert_exp_scheduler_->num_reschedule_calls();
// Build RPC responses.
std::vector<absl::StatusOr<proto::ListPublicCertificatesResponse>>
responses;
std::string page_token;
for (size_t page_number = 0; page_number < num_pages; ++page_number) {
bool last_page = page_number == num_pages - 1;
if (last_page && result == DownloadPublicCertificatesResult::kHttpError) {
responses.push_back(absl::InternalError(""));
break;
}
page_token = last_page ? std::string()
: absl::StrCat(kPageTokenPrefix, page_number);
responses.push_back(BuildRpcResponse(page_number, page_token));
}
client_factory_.instances().back()->SetListPublicCertificatesResponses(
responses);
cert_store_->SetAddPublicCertificatesResult(
result != DownloadPublicCertificatesResult::kStorageError);
download_scheduler_->InvokeRequestCallback();
Sync();
CheckRpcRequest(num_pages);
ASSERT_EQ(download_scheduler_->handled_results().size(),
prev_num_results + 1);
bool success = result == DownloadPublicCertificatesResult::kSuccess;
EXPECT_EQ(download_scheduler_->handled_results().back(), success);
EXPECT_EQ(num_public_certs_downloaded_notifications_,
initial_num_notifications + (success ? 1u : 0u));
EXPECT_EQ(public_cert_exp_scheduler_->num_reschedule_calls(),
initial_num_public_cert_exp_reschedules + (success ? 1u : 0u));
}
void QuerySharedCredentialsFlow(size_t num_pages,
DownloadPublicCertificatesResult result) {
size_t prev_num_results = download_scheduler_->handled_results().size();
@@ -425,25 +377,6 @@ class NearbyShareCertificateManagerImplTest
initial_num_public_cert_exp_reschedules + (success ? 1u : 0u));
}
void CheckRpcRequest(int num_pages) {
std::vector<proto::ListPublicCertificatesRequest> requests =
client_factory_.instances().back()->list_public_certificates_requests();
EXPECT_EQ(requests.size(), num_pages);
}
nearby::sharing::proto::ListPublicCertificatesResponse BuildRpcResponse(
size_t page_number, absl::string_view page_token) {
nearby::sharing::proto::ListPublicCertificatesResponse response;
for (size_t i = 0; i < public_certificates_.size(); ++i) {
public_certificates_[i].set_secret_id(
absl::StrCat(kSecretIdPrefix, page_number, "_", i));
response.add_public_certificates();
*response.mutable_public_certificates(i) = public_certificates_[i];
}
response.set_next_page_token(page_token);
return response;
}
QuerySharedCredentialsResponse BuildQuerySharedCredentialsResponse(
size_t page_number, absl::string_view page_token) {
QuerySharedCredentialsResponse response;
-3
View File
@@ -19,12 +19,10 @@ cc_library(
srcs = [
"nearby_share_contact_manager.cc",
"nearby_share_contact_manager_impl.cc",
"nearby_share_contacts_sorter.cc",
],
hdrs = [
"nearby_share_contact_manager.h",
"nearby_share_contact_manager_impl.h",
"nearby_share_contacts_sorter.h",
],
visibility = ["//visibility:public"],
deps = [
@@ -76,7 +74,6 @@ cc_test(
name = "contacts_test",
srcs = [
"nearby_share_contact_manager_impl_test.cc",
"nearby_share_contacts_sorter_test.cc",
],
deps = [
":contacts",
@@ -1,161 +0,0 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sharing/contacts/nearby_share_contacts_sorter.h"
#include <algorithm>
#include <locale>
#include <optional>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "sharing/proto/rpc_resources.pb.h"
namespace nearby {
namespace sharing {
namespace {
struct ContactSortingFields {
// Primary sorting key: person name if not empty; otherwise, email.
std::optional<std::string> person_name_or_email;
// Secondary sorting key. Note: It is okay if email is also used as the
// primary sorting key.
std::optional<std::string> email;
// Tertiary sorting key.
std::optional<std::string> phone_number;
// Last resort sorting key. The contact ID should be unique for each
// contact record, guaranteeing uniquely defined ordering.
std::string id;
};
ContactSortingFields GetContactSortingFields(
const nearby::sharing::proto::ContactRecord& contact) {
ContactSortingFields fields;
fields.id = contact.id();
for (const proto::Contact_Identifier& identifier : contact.identifiers()) {
switch (identifier.identifier_case()) {
case nearby::sharing::proto::Contact_Identifier::IdentifierCase::
kAccountName:
if (!fields.email) {
fields.email = identifier.account_name();
}
break;
case nearby::sharing::proto::Contact_Identifier::IdentifierCase::
kPhoneNumber:
if (!fields.phone_number) {
fields.phone_number = identifier.phone_number();
}
break;
case nearby::sharing::proto::Contact_Identifier::IdentifierCase::
kObfuscatedGaia:
break;
case nearby::sharing::proto::Contact_Identifier::IdentifierCase::
IDENTIFIER_NOT_SET:
break;
}
}
fields.person_name_or_email =
contact.person_name().empty()
? fields.email
: std::make_optional<std::string>(contact.person_name());
return fields;
}
class ContactRecordComparator {
public:
explicit ContactRecordComparator(std::locale locale) : locale_(locale) {}
bool operator()(const nearby::sharing::proto::ContactRecord& c1,
const nearby::sharing::proto::ContactRecord& c2) const {
ContactSortingFields f1 = GetContactSortingFields(c1);
ContactSortingFields f2 = GetContactSortingFields(c2);
switch (CollatorCompare(f1.person_name_or_email, f2.person_name_or_email)) {
case 0:
// Do nothing. Compare with the next field.
break;
case -1:
return true;
case 1:
return false;
}
switch (CollatorCompare(f1.email, f2.email)) {
case 0:
// Do nothing. Compare with the next field.
break;
case -1:
return true;
case 1:
return false;
}
if (f1.phone_number != f2.phone_number) {
if (!f1.phone_number) return false;
if (!f2.phone_number) return true;
return *f1.phone_number < *f2.phone_number;
}
return f1.id < f2.id;
}
private:
int CollatorCompare(const std::optional<std::string>& a,
const std::optional<std::string>& b) const {
// Sort populated strings before absl::nullopt.
if (!a && !b) return 0;
if (!b) return -1;
if (!a) return 1;
// Sort using a locale-based collator if available.
if (std::has_facet<std::ctype<char>>(locale_)) {
auto& facet = std::use_facet<std::collate<char>>(locale_);
std::string s1 = *a;
std::string s2 = *b;
return facet.compare(&s1[0], &s1[0] + s1.size(), &s2[0],
&s2[0] + s2.size());
}
// Fall back on standard string comparison, though we hope and expect
// that locale-based sorting will succeed.
if (*a == *b) {
return 0;
}
return *a < *b ? -1 : 1;
}
std::locale locale_;
};
} // namespace
void SortNearbyShareContactRecords(
std::vector<nearby::sharing::proto::ContactRecord>* contacts,
absl::string_view locale_string) {
// initialized to default program environment locale.
std::locale loc = std::locale("");
if (!locale_string.empty()) {
loc = std::locale(locale_string.data());
}
ContactRecordComparator comparator(loc);
std::sort(contacts->begin(), contacts->end(), comparator);
}
} // namespace sharing
} // namespace nearby
@@ -1,45 +0,0 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACTS_SORTER_H_
#define THIRD_PARTY_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACTS_SORTER_H_
#include <vector>
#include "absl/strings/string_view.h"
#include "sharing/proto/rpc_resources.pb.h"
namespace nearby {
namespace sharing {
// Sort |contacts| by the following fields:
// - person name or email address if name is empty (primary),
// - email, even if this is also used as the primary (secondary),
// - phone number (tertiary),
// - contact record id (last resort; should always be unique).
//
// This sorted order is unique for a given |locale|, presuming every element of
// |contacts| has a unique ContactRecord::id(). The ordering between fields is
// locale-dependent. For example, 'Å' will be sorted with these 'A's for
// US-based sorting, whereas 'Å' will be sorted after 'Z' for Sweden-based
// sorting, because 'Å' comes after 'Z' in the Swedish alphabet. By default,
// |locale| is inferred from system settings.
void SortNearbyShareContactRecords(
std::vector<nearby::sharing::proto::ContactRecord>* contacts,
absl::string_view locale_string = "");
} // namespace sharing
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACTS_SORTER_H_
@@ -1,251 +0,0 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sharing/contacts/nearby_share_contacts_sorter.h"
#include <stddef.h>
#include <algorithm>
#include <locale>
#include <random>
#include <vector>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "sharing/proto/rpc_resources.pb.h"
namespace nearby {
namespace sharing {
namespace {
using ::nearby::sharing::proto::ContactRecord;
using ::protobuf_matchers::EqualsProto;
using ::testing::Pointwise;
const std::vector<ContactRecord>& contacts() {
static const std::vector<ContactRecord>* contacts =
new std::vector<ContactRecord>([] {
ContactRecord contact0;
contact0.set_person_name("Claire");
contact0.set_is_reachable(true);
ContactRecord contact1;
contact1.set_person_name("Alice");
contact1.add_identifiers()->set_account_name("y@gmail.com");
contact1.set_is_reachable(true);
ContactRecord contact2;
contact2.set_person_name("Alice");
contact2.add_identifiers()->set_account_name("x@gmail.com");
contact2.set_is_reachable(true);
ContactRecord contact3;
contact3.add_identifiers()->set_account_name("bob@gmail.com");
contact3.set_is_reachable(true);
ContactRecord contact4;
contact4.add_identifiers()->set_phone_number("222-222-2222");
contact4.set_is_reachable(true);
ContactRecord contact5;
contact5.add_identifiers()->set_phone_number("111-111-1111");
contact5.set_is_reachable(true);
ContactRecord contact6;
contact6.set_person_name("David");
contact6.add_identifiers()->set_account_name("z@gmail.com");
contact6.add_identifiers()->set_phone_number("222-222-2222");
contact6.set_is_reachable(true);
ContactRecord contact7;
contact7.set_person_name("David");
contact7.add_identifiers()->set_account_name("z@gmail.com");
contact7.add_identifiers()->set_phone_number("111-111-1111");
contact7.set_id("2");
contact7.set_is_reachable(true);
ContactRecord contact8;
contact8.set_person_name("David");
contact8.add_identifiers()->set_account_name("z@gmail.com");
contact8.add_identifiers()->set_phone_number("111-111-1111");
contact8.set_id("1");
contact8.set_is_reachable(true);
ContactRecord contact9;
contact9.set_person_name("中村光");
contact9.set_is_reachable(true);
auto a = contact9.person_name();
ContactRecord contact10;
contact10.set_person_name("王皓");
contact10.set_is_reachable(true);
ContactRecord contact11;
contact11.set_person_name("中村俊輔");
contact11.set_is_reachable(true);
ContactRecord contact12;
contact12.set_person_name("丁立人");
contact12.set_is_reachable(true);
ContactRecord contact13;
contact13.set_person_name("Á");
contact13.set_is_reachable(true);
ContactRecord contact14;
contact14.set_person_name("Ñ");
contact14.set_is_reachable(true);
ContactRecord contact15;
contact15.set_person_name("å");
contact15.set_id("5");
contact15.set_is_reachable(true);
ContactRecord contact16;
contact16.set_person_name("Å");
contact16.set_id("3");
contact16.set_is_reachable(true);
ContactRecord contact17;
contact17.set_person_name("åz");
contact17.set_id("4");
contact17.set_is_reachable(true);
ContactRecord contact18;
contact18.set_person_name("Opus");
contact18.set_is_reachable(true);
return std::vector<ContactRecord>{
contact0, contact1, contact2, contact3, contact4,
contact5, contact6, contact7, contact8, contact9,
contact10, contact11, contact12, contact13, contact14,
contact15, contact16, contact17, contact18};
}());
return *contacts;
}
void VerifySort(const std::vector<ContactRecord>& expected_contacts,
const std::vector<ContactRecord>& unsorted_contacts,
absl::string_view locale_string) {
// Try a few different permutations of |unsorted_contacts|, which should all
// be sorted to |expected_contacts|.
std::default_random_engine rng;
for (size_t i = 0; i < 10u; ++i) {
std::vector<ContactRecord> sorted_contacts = contacts();
std::shuffle(sorted_contacts.begin(), sorted_contacts.end(), rng);
SortNearbyShareContactRecords(&sorted_contacts, locale_string);
ASSERT_EQ(expected_contacts.size(), sorted_contacts.size());
EXPECT_THAT(sorted_contacts, Pointwise(EqualsProto(), sorted_contacts));
}
}
TEST(NearbyShareContactsSorter, US) {
// Expected ordering:
// Á | | |
// å | | | ID: 5
// Å | | | ID: 3
// Alice | x@gmail.com | |
// Alice | y@gmail.com | |
// åz | | | ID: 4
// | bob@gmail.com | |
// Claire | | |
// David | z@gmail.com | 111-111-1111 | ID: 1
// David | z@gmail.com | 111-111-1111 | ID: 2
// David | z@gmail.com | 222-222-2222 |
// Ñ | | |
// Opus | | |
// 丁立人 | | |
// 中村俊輔 | | |
// 中村光 | | |
// 王皓 | | |
// | | 111-111-1111 |
// | | 222-222-2222 |
std::vector<ContactRecord> expected_contacts{
contacts()[13], contacts()[15], contacts()[16], contacts()[2],
contacts()[1], contacts()[17], contacts()[3], contacts()[0],
contacts()[8], contacts()[7], contacts()[6], contacts()[14],
contacts()[18], contacts()[12], contacts()[11], contacts()[9],
contacts()[10], contacts()[5], contacts()[4]};
ASSERT_NO_FATAL_FAILURE(
VerifySort(expected_contacts, contacts(), "en_US.UTF-8"));
}
TEST(NearbyShareContactsSorter, DISABLED_Sweden) {
// Expected ordering:
// Á | | |
// Alice | x@gmail.com | |
// Alice | y@gmail.com | |
// | bob@gmail.com | |
// Claire | | |
// David | z@gmail.com | 111-111-1111 | ID: 1
// David | z@gmail.com | 111-111-1111 | ID: 2
// David | z@gmail.com | 222-222-2222 |
// Ñ | | |
// Opus | | |
// å | | | ID: 5
// Å | | | ID: 3
// åz | | | ID: 4
// 丁立人 | | |
// 中村俊輔 | | |
// 中村光 | | |
// 王皓 | | |
// | | 111-111-1111 |
// | | 222-222-2222 |
std::vector<ContactRecord> expected_contacts{
contacts()[13], contacts()[2], contacts()[1], contacts()[3],
contacts()[0], contacts()[8], contacts()[7], contacts()[6],
contacts()[14], contacts()[18], contacts()[15], contacts()[16],
contacts()[17], contacts()[12], contacts()[11], contacts()[9],
contacts()[10], contacts()[5], contacts()[4]};
ASSERT_NO_FATAL_FAILURE(
VerifySort(expected_contacts, contacts(), "sv-SE.UTF-8"));
}
TEST(NearbyShareContactsSorter, DISABLED_China) {
// Expected ordering:
// Á | | |
// å | | | ID: 5
// Å | | | ID: 3
// Alice | x@gmail.com | |
// Alice | y@gmail.com | |
// åz | | | ID: 4
// | bob@gmail.com | |
// Claire | | |
// David | z@gmail.com | 111-111-1111 | ID: 1
// David | z@gmail.com | 111-111-1111 | ID: 2
// David | z@gmail.com | 222-222-2222 |
// Ñ | | |
// Opus | | |
// 丁立人 | | |
// 王皓 | | |
// 中村光 | | |
// 中村俊輔 | | |
// | | 111-111-1111 |
// | | 222-222-2222 |
std::vector<ContactRecord> expected_contacts{
contacts()[13], contacts()[15], contacts()[16], contacts()[2],
contacts()[1], contacts()[17], contacts()[3], contacts()[0],
contacts()[8], contacts()[7], contacts()[6], contacts()[14],
contacts()[18], contacts()[12], contacts()[10], contacts()[9],
contacts()[11], contacts()[5], contacts()[4]};
ASSERT_NO_FATAL_FAILURE(
VerifySort(expected_contacts, contacts(), "zh_CN.UTF-8"));
}
} // namespace
} // namespace sharing
} // namespace nearby
@@ -28,15 +28,6 @@
namespace nearby {
namespace sharing {
void FakeNearbyShareClient::UpdateDevice(
const proto::UpdateDeviceRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::UpdateDeviceResponse>& response) &&>
callback) {
update_device_requests_.emplace_back(request);
std::move(callback)(update_device_response_);
}
void FakeNearbyShareClient::ListContactPeople(
const proto::ListContactPeopleRequest& request,
absl::AnyInvocable<void(const absl::StatusOr<
@@ -52,23 +43,6 @@ void FakeNearbyShareClient::ListContactPeople(
std::move(callback)(response);
}
void FakeNearbyShareClient::ListPublicCertificates(
const proto::ListPublicCertificatesRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::ListPublicCertificatesResponse>&
response) &&>
callback) {
list_public_certificates_requests_.emplace_back(request);
if (list_public_certificates_responses_.empty()) {
std::move(callback)(absl::NotFoundError(""));
return;
}
auto response = list_public_certificates_responses_[0];
list_public_certificates_responses_.erase(
list_public_certificates_responses_.begin());
std::move(callback)(response);
}
void FakeNearbyIdentityClient::QuerySharedCredentials(
const google::nearby::identity::v1::QuerySharedCredentialsRequest& request,
absl::AnyInvocable<
@@ -35,70 +35,26 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
FakeNearbyShareClient() = default;
~FakeNearbyShareClient() override = default;
std::vector<nearby::sharing::proto::UpdateDeviceRequest>&
update_device_requests() {
return update_device_requests_;
}
std::vector<nearby::sharing::proto::ListContactPeopleRequest>&
list_contact_people_requests() {
return list_contact_people_requests_;
}
std::vector<nearby::sharing::proto::ListPublicCertificatesRequest>&
list_public_certificates_requests() {
return list_public_certificates_requests_;
}
absl::StatusOr<proto::UpdateDeviceResponse>& update_device_response() {
return update_device_response_;
}
void SetUpdateDeviceResponse(
absl::StatusOr<proto::UpdateDeviceResponse> response) {
update_device_response_ = response;
}
void SetListContactPeopleResponses(
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>> responses) {
list_contact_people_responses_ = responses;
}
void SetListPublicCertificatesResponses(
std::vector<absl::StatusOr<proto::ListPublicCertificatesResponse>>
responses) {
list_public_certificates_responses_ = responses;
}
void UpdateDevice(
const proto::UpdateDeviceRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::UpdateDeviceResponse>& response) &&>
callback) override;
void ListContactPeople(
const proto::ListContactPeopleRequest& request,
absl::AnyInvocable<void(const absl::StatusOr<
proto::ListContactPeopleResponse>& response) &&>
callback) override;
void ListPublicCertificates(
const proto::ListPublicCertificatesRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::ListPublicCertificatesResponse>&
response) &&>
callback) override;
std::vector<nearby::sharing::proto::UpdateDeviceRequest>
update_device_requests_;
std::vector<nearby::sharing::proto::ListContactPeopleRequest>
list_contact_people_requests_;
std::vector<nearby::sharing::proto::ListPublicCertificatesRequest>
list_public_certificates_requests_;
absl::StatusOr<proto::UpdateDeviceResponse> update_device_response_;
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>>
list_contact_people_responses_;
std::vector<absl::StatusOr<proto::ListPublicCertificatesResponse>>
list_public_certificates_responses_;
};
// A fake implementation of the Nearby Identity RPC client that stores all
-15
View File
@@ -63,27 +63,12 @@ class SharingRpcClient {
SharingRpcClient() = default;
virtual ~SharingRpcClient() = default;
// Updates device data.
virtual void UpdateDevice(
const proto::UpdateDeviceRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::UpdateDeviceResponse>& response) &&>
callback) = 0;
// NearbyShareService v1: ListContactPeople
virtual void ListContactPeople(
const proto::ListContactPeopleRequest& request,
absl::AnyInvocable<void(const absl::StatusOr<
proto::ListContactPeopleResponse>& response) &&>
callback) = 0;
// NearbyShareService v1: ListPublicCertificates
virtual void ListPublicCertificates(
const proto::ListPublicCertificatesRequest& request,
absl::AnyInvocable<
void(const absl::StatusOr<proto::ListPublicCertificatesResponse>&
response) &&>
callback) = 0;
};
// Interface for creating SharingRpcClient instances. Because each