mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
add flag call_nearby_identity_api and make api::SharingRpcClient base class of NearbyIdentityGrpcClient.
PiperOrigin-RevId: 698945381
This commit is contained in:
committed by
Copybara-Service
parent
f5e526317b
commit
266a773cf8
@@ -12,14 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/************* DO NOT EDIT *******************
|
||||
* After updating nearby_sharing_feature.gcl, regenerate this file by running:
|
||||
* blaze build
|
||||
* //third_party/nearby/sharing/flags:nearby_sharing_feature_flags_cpp_consts
|
||||
* Copy the generated file here:
|
||||
* blaze-genfiles/third_party/nearby/sharing/flags/nearby_sharing_feature_flags.h
|
||||
**********************************************/
|
||||
|
||||
// Mendel flags, auto-generated. DO NOT EDIT.
|
||||
#ifndef THIRD_PARTY_NEARBY_SHARING_FLAGS_NEARBY_SHARING_FEATURE_FLAGS_H_
|
||||
#define THIRD_PARTY_NEARBY_SHARING_FLAGS_NEARBY_SHARING_FEATURE_FLAGS_H_
|
||||
|
||||
@@ -83,6 +76,9 @@ constexpr auto kUseGrpcClient =
|
||||
// When true, dedup discovered endpoints.
|
||||
constexpr auto kApplyEndpointsDedup =
|
||||
flags::Flag<bool>(kConfigPackage, "45656298", false);
|
||||
// When true, call the 3P Nearby Identity API instead of the 1P private API
|
||||
constexpr auto kCallNearbyIdentityApi =
|
||||
flags::Flag<bool>(kConfigPackage, "45667328", false);
|
||||
// When true, dedup in UnregisterShareTarget.
|
||||
constexpr auto kDedupInUnregisterShareTarget =
|
||||
flags::Flag<bool>(kConfigPackage, "45664277", false);
|
||||
@@ -130,6 +126,7 @@ inline absl::btree_map<int, const flags::Flag<bool>&> GetBoolFlags() {
|
||||
{45409033, kShowAutoUpdateSetting},
|
||||
{45630055, kUseGrpcClient},
|
||||
{45656298, kApplyEndpointsDedup},
|
||||
{45667328, kCallNearbyIdentityApi},
|
||||
{45664277, kDedupInUnregisterShareTarget},
|
||||
{45657036, kDeleteUnexpectedReceivedFileFix},
|
||||
{45665616, kHonor3PClientIdAndSecret},
|
||||
|
||||
@@ -40,6 +40,7 @@ cc_library(
|
||||
deps = [
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:account_manager",
|
||||
"//proto/identity/v1:rpcs_cc_proto",
|
||||
"//sharing/analytics",
|
||||
"//sharing/proto:share_cc_proto",
|
||||
"@com_google_absl//absl/functional:any_invocable",
|
||||
|
||||
@@ -69,11 +69,38 @@ void FakeNearbyShareClient::ListPublicCertificates(
|
||||
std::move(callback)(response);
|
||||
}
|
||||
|
||||
void FakeNearbyIdentityClient::QuerySharedCredentials(
|
||||
const google::nearby::identity::v1::QuerySharedCredentialsRequest& request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
|
||||
response) &&>
|
||||
callback) {
|
||||
query_shared_credentials_requests_.emplace_back(request);
|
||||
std::move(callback)(query_shared_credentials_response_);
|
||||
}
|
||||
|
||||
void FakeNearbyIdentityClient::PublishDevice(
|
||||
const google::nearby::identity::v1::PublishDeviceRequest& request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::PublishDeviceResponse>& response) &&>
|
||||
callback) {
|
||||
publish_device_requests_.emplace_back(request);
|
||||
std::move(callback)(publish_device_response_);
|
||||
}
|
||||
|
||||
std::unique_ptr<nearby::sharing::api::SharingRpcClient>
|
||||
FakeNearbyShareClientFactory::CreateInstance() {
|
||||
auto instance = std::make_unique<FakeNearbyShareClient>();
|
||||
instances_.push_back(instance.get());
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
|
||||
FakeNearbyShareClientFactory::CreateIdentityInstance() {
|
||||
auto instance = std::make_unique<FakeNearbyIdentityClient>();
|
||||
identity_instances_.push_back(instance.get());
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
|
||||
list_public_certificates_responses_ = responses;
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateDevice(
|
||||
const proto::UpdateDeviceRequest& request,
|
||||
absl::AnyInvocable<
|
||||
@@ -103,6 +102,59 @@ class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
|
||||
list_public_certificates_responses_;
|
||||
};
|
||||
|
||||
// A fake implementation of the Nearby Identity RPC client that stores all
|
||||
// request data. Only use in unit tests.
|
||||
class FakeNearbyIdentityClient
|
||||
: public nearby::sharing::api::IdentityRpcClient {
|
||||
public:
|
||||
FakeNearbyIdentityClient() = default;
|
||||
~FakeNearbyIdentityClient() override = default;
|
||||
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>&
|
||||
publish_device_requests() {
|
||||
return publish_device_requests_;
|
||||
}
|
||||
|
||||
void PublishDevice(
|
||||
const google::nearby::identity::v1::PublishDeviceRequest& request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
PublishDeviceResponse>& response) &&>
|
||||
callback) override;
|
||||
|
||||
void SetPublishDeviceResponse(
|
||||
absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>
|
||||
response) {
|
||||
publish_device_response_ = response;
|
||||
}
|
||||
|
||||
void QuerySharedCredentials(
|
||||
const google::nearby::identity::v1::QuerySharedCredentialsRequest&
|
||||
request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
|
||||
response) &&>
|
||||
callback) override;
|
||||
|
||||
void SetQuerySharedCredentialsResponse(
|
||||
absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>
|
||||
response) {
|
||||
query_shared_credentials_response_ = response;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>
|
||||
publish_device_requests_;
|
||||
absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>
|
||||
publish_device_response_;
|
||||
|
||||
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>
|
||||
query_shared_credentials_requests_;
|
||||
absl::StatusOr<google::nearby::identity::v1::QuerySharedCredentialsResponse>
|
||||
query_shared_credentials_response_;
|
||||
};
|
||||
|
||||
class FakeNearbyShareClientFactory
|
||||
: public nearby::sharing::api::SharingRpcClientFactory {
|
||||
public:
|
||||
@@ -112,6 +164,9 @@ class FakeNearbyShareClientFactory
|
||||
public:
|
||||
// Returns all FakeNearbyShareClient instances created by CreateInstance().
|
||||
std::vector<FakeNearbyShareClient*>& instances() { return instances_; }
|
||||
std::vector<FakeNearbyIdentityClient*>& identity_instances() {
|
||||
return identity_instances_;
|
||||
}
|
||||
nearby::sharing::api::SharingRpcNotifier* GetRpcNotifier() const override {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -121,7 +176,11 @@ class FakeNearbyShareClientFactory
|
||||
std::unique_ptr<nearby::sharing::api::SharingRpcClient> CreateInstance()
|
||||
override;
|
||||
|
||||
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
|
||||
CreateIdentityInstance() override;
|
||||
|
||||
std::vector<FakeNearbyShareClient*> instances_;
|
||||
std::vector<FakeNearbyIdentityClient*> identity_instances_;
|
||||
};
|
||||
|
||||
} // namespace sharing
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "proto/identity/v1/rpcs.pb.h"
|
||||
#include "sharing/internal/api/sharing_rpc_notifier.h"
|
||||
#include "sharing/proto/certificate_rpc.pb.h"
|
||||
#include "sharing/proto/contact_rpc.pb.h"
|
||||
@@ -26,6 +27,29 @@
|
||||
|
||||
namespace nearby::sharing::api {
|
||||
|
||||
// IdentityRpcClient is used to access Nearby Identity backend APIs.
|
||||
class IdentityRpcClient {
|
||||
public:
|
||||
IdentityRpcClient() = default;
|
||||
virtual ~IdentityRpcClient() = default;
|
||||
|
||||
virtual void QuerySharedCredentials(
|
||||
const google::nearby::identity::v1::QuerySharedCredentialsRequest&
|
||||
request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
|
||||
response) &&>
|
||||
callback) = 0;
|
||||
|
||||
virtual void PublishDevice(
|
||||
const google::nearby::identity::v1::PublishDeviceRequest& request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
PublishDeviceResponse>& response) &&>
|
||||
callback) = 0;
|
||||
};
|
||||
|
||||
// SharingRpcClient is used to access Nearby Share backend APIs.
|
||||
class SharingRpcClient {
|
||||
public:
|
||||
@@ -64,6 +88,7 @@ class SharingRpcClientFactory {
|
||||
virtual ~SharingRpcClientFactory() = default;
|
||||
|
||||
virtual std::unique_ptr<SharingRpcClient> CreateInstance() = 0;
|
||||
virtual std::unique_ptr<IdentityRpcClient> CreateIdentityInstance() = 0;
|
||||
virtual api::SharingRpcNotifier* GetRpcNotifier() const = 0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user