mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Remove unused code.
PiperOrigin-RevId: 784818952
This commit is contained in:
committed by
Copybara-Service
parent
771904b707
commit
bc908eb9cf
@@ -66,18 +66,6 @@ FakeNearbyShareLocalDeviceDataManager::UploadContactsCall::UploadContactsCall(
|
||||
FakeNearbyShareLocalDeviceDataManager::UploadContactsCall::
|
||||
~UploadContactsCall() = default;
|
||||
|
||||
FakeNearbyShareLocalDeviceDataManager::UploadCertificatesCall::
|
||||
UploadCertificatesCall(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback)
|
||||
: certificates(std::move(certificates)), callback(std::move(callback)) {}
|
||||
|
||||
FakeNearbyShareLocalDeviceDataManager::UploadCertificatesCall::
|
||||
UploadCertificatesCall(UploadCertificatesCall&&) = default;
|
||||
|
||||
FakeNearbyShareLocalDeviceDataManager::UploadCertificatesCall::
|
||||
~UploadCertificatesCall() = default;
|
||||
|
||||
FakeNearbyShareLocalDeviceDataManager::FakeNearbyShareLocalDeviceDataManager(
|
||||
absl::string_view default_device_name)
|
||||
: id_(kDefaultId), device_name_(default_device_name) {}
|
||||
@@ -122,15 +110,6 @@ void FakeNearbyShareLocalDeviceDataManager::UploadContacts(
|
||||
}
|
||||
}
|
||||
|
||||
void FakeNearbyShareLocalDeviceDataManager::UploadCertificates(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback) {
|
||||
upload_certificates_calls_.emplace_back(std::move(certificates), callback);
|
||||
if (is_sync_mode_) {
|
||||
callback(upload_certificate_result_);
|
||||
}
|
||||
}
|
||||
|
||||
void FakeNearbyShareLocalDeviceDataManager::PublishDevice(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
bool force_update_contacts, PublishDeviceCallback callback) {
|
||||
|
||||
@@ -79,17 +79,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
UploadCompleteCallback callback;
|
||||
};
|
||||
|
||||
struct UploadCertificatesCall {
|
||||
UploadCertificatesCall(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback);
|
||||
UploadCertificatesCall(UploadCertificatesCall&&);
|
||||
~UploadCertificatesCall();
|
||||
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates;
|
||||
UploadCompleteCallback callback;
|
||||
};
|
||||
|
||||
struct PublishDeviceCall {
|
||||
PublishDeviceCall(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
@@ -117,9 +106,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
DeviceNameValidationResult SetDeviceName(absl::string_view name) override;
|
||||
void UploadContacts(std::vector<nearby::sharing::proto::Contact> contacts,
|
||||
UploadCompleteCallback callback) override;
|
||||
void UploadCertificates(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback) override;
|
||||
|
||||
void PublishDevice(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
@@ -135,10 +121,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
return upload_contacts_calls_;
|
||||
}
|
||||
|
||||
std::vector<UploadCertificatesCall>& upload_certificates_calls() {
|
||||
return upload_certificates_calls_;
|
||||
}
|
||||
|
||||
std::vector<PublishDeviceCall>& publish_device_calls() {
|
||||
return publish_device_calls_;
|
||||
}
|
||||
@@ -154,10 +136,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
upload_contact_result_ = upload_contact_result;
|
||||
}
|
||||
|
||||
void SetUploadCertificatesResult(bool upload_certificate_result) {
|
||||
upload_certificate_result_ = upload_certificate_result;
|
||||
}
|
||||
|
||||
void SetPublishDeviceResult(bool publish_device_result) {
|
||||
publish_device_result_ = publish_device_result;
|
||||
}
|
||||
@@ -172,7 +150,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
std::string id_;
|
||||
std::string device_name_;
|
||||
std::vector<UploadContactsCall> upload_contacts_calls_;
|
||||
std::vector<UploadCertificatesCall> upload_certificates_calls_;
|
||||
std::vector<PublishDeviceCall> publish_device_calls_;
|
||||
DeviceNameValidationResult next_validation_result_ =
|
||||
DeviceNameValidationResult::kValid;
|
||||
@@ -180,7 +157,6 @@ class FakeNearbyShareLocalDeviceDataManager
|
||||
// Used to indicate whether the class is running in synchronization mode.
|
||||
bool is_sync_mode_ = false;
|
||||
bool upload_contact_result_ = false;
|
||||
bool upload_certificate_result_ = false;
|
||||
bool publish_device_result_ = false;
|
||||
bool publish_device_contact_removed_ = false;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -90,14 +89,6 @@ class NearbyShareLocalDeviceDataManager {
|
||||
std::vector<nearby::sharing::proto::Contact> contacts,
|
||||
UploadCompleteCallback callback) = 0;
|
||||
|
||||
// Uses the UpdateDevice RPC to send the local device's public certificates to
|
||||
// the Nearby Share server. This should only be invoked by the certificate
|
||||
// manager, and the certificate manager should handle scheduling, failure
|
||||
// retry, etc.
|
||||
virtual void UploadCertificates(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback) = 0;
|
||||
|
||||
// Calls Identity PublishDevice RPC to upload local device's public
|
||||
// certificates.
|
||||
virtual void PublishDevice(
|
||||
|
||||
@@ -62,8 +62,6 @@ using ::nearby::sharing::proto::UpdateDeviceResponse;
|
||||
|
||||
constexpr absl::string_view kDeviceIdPrefix = "users/me/devices/";
|
||||
constexpr absl::string_view kContactsFieldMaskPath = "contacts";
|
||||
constexpr absl::string_view kCertificatesFieldMaskPath = "public_certificates";
|
||||
|
||||
constexpr absl::string_view kDefaultDeviceName = "$0\'s $1";
|
||||
|
||||
// Returns a truncated version of |name| that is |max_length| characters long.
|
||||
@@ -322,57 +320,6 @@ void NearbyShareLocalDeviceDataManagerImpl::PublishDevice(
|
||||
});
|
||||
}
|
||||
|
||||
void NearbyShareLocalDeviceDataManagerImpl::UploadCertificates(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback) {
|
||||
executor_->PostTask([&, certificates = std::move(certificates),
|
||||
callback = std::move(callback)]() {
|
||||
LOG(INFO) << __func__ << ": Upload " << certificates.size()
|
||||
<< " certificates.";
|
||||
if (!is_running()) {
|
||||
LOG(WARNING) << "UploadContacts: skip to upload certificates due "
|
||||
"to manager is stopped.";
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string device_id = GetId();
|
||||
if (!account_manager_.GetCurrentAccount().has_value() ||
|
||||
device_id.empty()) {
|
||||
LOG(WARNING) << __func__
|
||||
<< ": skip to upload certificates due "
|
||||
"to no login account.";
|
||||
callback(/*success=*/true);
|
||||
return;
|
||||
}
|
||||
UpdateDeviceRequest request;
|
||||
request.mutable_device()->set_name(
|
||||
absl::StrCat(kDeviceIdPrefix, device_id));
|
||||
request.mutable_device()->mutable_public_certificates()->Add(
|
||||
certificates.begin(), certificates.end());
|
||||
request.mutable_update_mask()->add_paths(
|
||||
std::string(kCertificatesFieldMaskPath));
|
||||
nearby_share_client_->UpdateDevice(
|
||||
request, [this, callback = std::move(callback)](
|
||||
const absl::StatusOr<UpdateDeviceResponse>& response) {
|
||||
// check whether the manager is running again
|
||||
if (!is_running()) {
|
||||
LOG(WARNING)
|
||||
<< "DownloadDeviceData: skip to upload certificates due "
|
||||
"to manager is stopped.";
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
if (!response.ok()) {
|
||||
LOG(WARNING)
|
||||
<< "UploadCertificates: Failed to get response from backend: "
|
||||
<< response.status();
|
||||
}
|
||||
callback(/*success=*/response.ok());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
std::string NearbyShareLocalDeviceDataManagerImpl::GetDefaultDeviceName()
|
||||
const {
|
||||
std::optional<AccountManager::Account> account =
|
||||
|
||||
@@ -80,9 +80,6 @@ class NearbyShareLocalDeviceDataManagerImpl
|
||||
DeviceNameValidationResult SetDeviceName(absl::string_view name) override;
|
||||
void UploadContacts(std::vector<nearby::sharing::proto::Contact> contacts,
|
||||
UploadCompleteCallback callback) override;
|
||||
void UploadCertificates(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
UploadCompleteCallback callback) override;
|
||||
|
||||
void PublishDevice(
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> certificates,
|
||||
|
||||
@@ -94,14 +94,6 @@ std::vector<Contact> GetFakeContacts() {
|
||||
return {std::move(contact1), std::move(contact2)};
|
||||
}
|
||||
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> GetFakeCertificates() {
|
||||
nearby::sharing::proto::PublicCertificate cert1;
|
||||
nearby::sharing::proto::PublicCertificate cert2;
|
||||
cert1.set_secret_id("id1");
|
||||
cert2.set_secret_id("id2");
|
||||
return {std::move(cert1), std::move(cert2)};
|
||||
}
|
||||
|
||||
class NearbyShareLocalDeviceDataManagerImplTest
|
||||
: public ::testing::Test,
|
||||
public NearbyShareLocalDeviceDataManager::Observer {
|
||||
@@ -192,33 +184,6 @@ class NearbyShareLocalDeviceDataManagerImplTest
|
||||
}
|
||||
}
|
||||
|
||||
void UploadCertificates(
|
||||
const absl::StatusOr<UpdateDeviceResponse>& response) {
|
||||
std::optional<bool> returned_success;
|
||||
EXPECT_TRUE(client()->list_contact_people_requests().empty());
|
||||
|
||||
client()->SetUpdateDeviceResponse(response);
|
||||
manager_->UploadCertificates(
|
||||
GetFakeCertificates(),
|
||||
[&returned_success](bool success) { returned_success = success; });
|
||||
|
||||
Sync();
|
||||
std::vector<nearby::sharing::proto::PublicCertificate>
|
||||
expected_fake_certificates = GetFakeCertificates();
|
||||
for (size_t i = 0; i < expected_fake_certificates.size(); ++i) {
|
||||
EXPECT_EQ(expected_fake_certificates[i].SerializeAsString(),
|
||||
client()
|
||||
->update_device_requests()
|
||||
.back()
|
||||
.device()
|
||||
.public_certificates()
|
||||
.at(i)
|
||||
.SerializeAsString());
|
||||
}
|
||||
|
||||
EXPECT_EQ(response.ok(), returned_success);
|
||||
}
|
||||
|
||||
NearbyShareLocalDeviceDataManager* manager() { return manager_.get(); }
|
||||
|
||||
FakeAccountManager& fake_account_manager() { return fake_account_manager_; }
|
||||
@@ -365,19 +330,6 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, UploadContacts_Failure) {
|
||||
UploadContacts(/*response=*/absl::InternalError(""));
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareLocalDeviceDataManagerImplTest, UploadCertificates_Success) {
|
||||
CreateManager();
|
||||
SetDeviceId(kTestDeviceId);
|
||||
UploadCertificates(
|
||||
CreateResponse(kFakeFullName, kFakeIconUrl, kFakeIconToken));
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareLocalDeviceDataManagerImplTest, UploadCertificates_Failure) {
|
||||
CreateManager();
|
||||
SetDeviceId(kTestDeviceId);
|
||||
UploadCertificates(/*response=*/absl::InternalError(""));
|
||||
}
|
||||
|
||||
std::vector<nearby::sharing::proto::PublicCertificate> GetTestCertificates() {
|
||||
nearby::sharing::proto::PublicCertificate cert1;
|
||||
cert1.set_secret_id("id1");
|
||||
|
||||
Reference in New Issue
Block a user