mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Cleanup certificate manager path management.
PiperOrigin-RevId: 768146823
This commit is contained in:
committed by
Copybara-Service
parent
56d7ca1c2e
commit
2d8b71703e
@@ -28,6 +28,7 @@ cc_library(
|
||||
"leveldb_data_set.h",
|
||||
],
|
||||
deps = [
|
||||
"//internal/base:file_path",
|
||||
"//internal/platform:types",
|
||||
"//third_party/leveldb:db",
|
||||
"//third_party/leveldb:table",
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "third_party/leveldb/include/options.h"
|
||||
#include "third_party/leveldb/include/slice.h"
|
||||
#include "third_party/leveldb/include/status.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/data/data_set.h"
|
||||
#if defined(_WIN32)
|
||||
#include "location/nearby/apps/better_together/windows/common/leveldb_env_windows.h"
|
||||
@@ -46,7 +47,13 @@ class LeveldbDataSet : public DataSet<T> {
|
||||
public:
|
||||
using KeyEntryVector = std::vector<std::pair<std::string, T>>;
|
||||
|
||||
explicit LeveldbDataSet(absl::string_view path) : path_(path) {}
|
||||
explicit LeveldbDataSet(const FilePath& db_dir) : path_(db_dir.ToString()) {
|
||||
#if defined(_WIN32)
|
||||
// In Windows use the Unicode compatible environment.
|
||||
db_options_.env = nearby::windows::WindowsEnv::Default();
|
||||
#endif // defined(_WIN32)
|
||||
db_options_.create_if_missing = true;
|
||||
}
|
||||
~LeveldbDataSet() override = default;
|
||||
|
||||
void Initialize(absl::AnyInvocable<void(InitStatus) &&> callback) override;
|
||||
@@ -72,6 +79,7 @@ class LeveldbDataSet : public DataSet<T> {
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
leveldb::Options db_options_;
|
||||
std::unique_ptr<leveldb::DB> db_ = nullptr;
|
||||
InitStatus status_ = InitStatus::kNotInitialized;
|
||||
};
|
||||
@@ -81,13 +89,8 @@ template <typename T,
|
||||
isMessageLite>
|
||||
void LeveldbDataSet<T, isMessageLite>::Initialize(
|
||||
absl::AnyInvocable<void(InitStatus) &&> callback) {
|
||||
leveldb::Options options;
|
||||
options.create_if_missing = true;
|
||||
#if defined(_WIN32)
|
||||
options.env = nearby::windows::WindowsEnv::Default();
|
||||
#endif // defined(_WIN32)
|
||||
leveldb::DB* db;
|
||||
leveldb::Status status = leveldb::DB::Open(options, path_, &db);
|
||||
leveldb::Status status = leveldb::DB::Open(db_options_, path_, &db);
|
||||
db_ = std::unique_ptr<leveldb::DB>(db);
|
||||
|
||||
if (status.ok()) {
|
||||
@@ -226,11 +229,7 @@ void LeveldbDataSet<T, isMessageLite>::Destroy(
|
||||
absl::AnyInvocable<void(bool) &&> callback) {
|
||||
LOG(INFO) << "Destroy is called.";
|
||||
db_.reset();
|
||||
leveldb::Options options;
|
||||
#if defined(_WIN32)
|
||||
options.env = nearby::windows::WindowsEnv::Default();
|
||||
#endif // defined(_WIN32)
|
||||
leveldb::DestroyDB(path_, options);
|
||||
leveldb::DestroyDB(path_, db_options_);
|
||||
std::move(callback)(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ FilePath GenerateLeveldbPath() {
|
||||
template <typename T>
|
||||
std::unique_ptr<LeveldbDataSet<T>> CreateDataSet(
|
||||
const FilePath& path) {
|
||||
return std::make_unique<LeveldbDataSet<T>>(path.ToString());
|
||||
return std::make_unique<LeveldbDataSet<T>>(path);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -40,6 +40,7 @@ cc_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//internal/base",
|
||||
"//internal/base:file_path",
|
||||
"//internal/crypto_cros",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/platform:types",
|
||||
@@ -92,6 +93,7 @@ cc_library(
|
||||
deps = [
|
||||
":certificates",
|
||||
"//internal/base:bluetooth_address",
|
||||
"//internal/base:file_path",
|
||||
"//internal/crypto_cros",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/contacts",
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
|
||||
#include "sharing/certificates/nearby_share_private_certificate.h"
|
||||
@@ -50,7 +50,7 @@ std::unique_ptr<NearbyShareCertificateManager>
|
||||
FakeNearbyShareCertificateManager::Factory::CreateInstance(
|
||||
nearby::Context* context,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
NearbyShareContactManager* contact_manager, absl::string_view profile_path,
|
||||
NearbyShareContactManager* contact_manager, const FilePath& profile_path,
|
||||
nearby::sharing::api::SharingRpcClientFactory* client_factory) {
|
||||
auto instance = std::make_unique<FakeNearbyShareCertificateManager>();
|
||||
instances_.push_back(instance.get());
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager_impl.h"
|
||||
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
|
||||
@@ -62,7 +62,7 @@ class FakeNearbyShareCertificateManager : public NearbyShareCertificateManager {
|
||||
Context* context,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
NearbyShareContactManager* contact_manager,
|
||||
absl::string_view profile_path,
|
||||
const FilePath& profile_path,
|
||||
nearby::sharing::api::SharingRpcClientFactory* client_factory) override;
|
||||
|
||||
std::vector<FakeNearbyShareCertificateManager*> instances_;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
#include "proto/identity/v1/resources.pb.h"
|
||||
#include "proto/identity/v1/rpcs.pb.h"
|
||||
@@ -186,7 +187,7 @@ std::unique_ptr<NearbyShareCertificateManager>
|
||||
NearbyShareCertificateManagerImpl::Factory::Create(
|
||||
Context* context, SharingPlatform& sharing_platform,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
NearbyShareContactManager* contact_manager, absl::string_view profile_path,
|
||||
NearbyShareContactManager* contact_manager, const FilePath& profile_path,
|
||||
nearby::sharing::api::SharingRpcClientFactory* client_factory) {
|
||||
DCHECK(context);
|
||||
|
||||
@@ -196,11 +197,12 @@ NearbyShareCertificateManagerImpl::Factory::Create(
|
||||
client_factory);
|
||||
}
|
||||
|
||||
FilePath database_path = profile_path;
|
||||
database_path.append(FilePath(kPublicCertificateDatabaseName));
|
||||
return absl::WrapUnique(new NearbyShareCertificateManagerImpl(
|
||||
context, sharing_platform.GetPreferenceManager(),
|
||||
sharing_platform.GetAccountManager(),
|
||||
sharing_platform.CreatePublicCertificateDatabase(
|
||||
absl::StrCat(profile_path, "/", kPublicCertificateDatabaseName)),
|
||||
sharing_platform.CreatePublicCertificateDatabase(database_path),
|
||||
local_device_data_manager, contact_manager, client_factory));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/file_path.h"
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_manager.h"
|
||||
@@ -68,7 +68,7 @@ class NearbyShareCertificateManagerImpl
|
||||
nearby::sharing::api::SharingPlatform& sharing_platform,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
NearbyShareContactManager* contact_manager,
|
||||
absl::string_view profile_path,
|
||||
const FilePath& profile_path,
|
||||
nearby::sharing::api::SharingRpcClientFactory* client_factory);
|
||||
static void SetFactoryForTesting(Factory* test_factory);
|
||||
|
||||
@@ -78,7 +78,7 @@ class NearbyShareCertificateManagerImpl
|
||||
Context* context,
|
||||
NearbyShareLocalDeviceDataManager* local_device_data_manager,
|
||||
NearbyShareContactManager* contact_manager,
|
||||
absl::string_view profile_path,
|
||||
const FilePath& profile_path,
|
||||
nearby::sharing::api::SharingRpcClientFactory* client_factory) = 0;
|
||||
|
||||
private:
|
||||
|
||||
@@ -147,8 +147,8 @@ class NearbyShareCertificateManagerImplTest
|
||||
local_device_data_manager_->SetUsingIdentityRpc(use_identity_rpc);
|
||||
cert_manager_ = NearbyShareCertificateManagerImpl::Factory::Create(
|
||||
&fake_context_, mock_sharing_platform_,
|
||||
local_device_data_manager_.get(), contact_manager_.get(), std::string(),
|
||||
&client_factory_);
|
||||
local_device_data_manager_.get(), contact_manager_.get(),
|
||||
/*profile_path=*/{}, &client_factory_);
|
||||
cert_manager_->AddObserver(this);
|
||||
|
||||
cert_store_ = cert_store_factory_.instances().back();
|
||||
|
||||
@@ -87,8 +87,8 @@ class MockSharingPlatform : public SharingPlatform {
|
||||
MOCK_METHOD(TaskRunner&, GetDefaultTaskRunner, (), (override));
|
||||
MOCK_METHOD(nearby::DeviceInfo&, GetDeviceInfo, (), (override));
|
||||
MOCK_METHOD(std::unique_ptr<PublicCertificateDatabase>,
|
||||
CreatePublicCertificateDatabase,
|
||||
(absl::string_view database_path), (override));
|
||||
CreatePublicCertificateDatabase, (const FilePath& database_path),
|
||||
(override));
|
||||
MOCK_METHOD(
|
||||
std::unique_ptr<SharingRpcClientFactory>, CreateSharingRpcClientFactory,
|
||||
(Clock * clock,
|
||||
|
||||
@@ -82,7 +82,7 @@ class SharingPlatform {
|
||||
virtual TaskRunner& GetDefaultTaskRunner() = 0;
|
||||
virtual nearby::DeviceInfo& GetDeviceInfo() = 0;
|
||||
virtual std::unique_ptr<PublicCertificateDatabase>
|
||||
CreatePublicCertificateDatabase(absl::string_view database_path) = 0;
|
||||
CreatePublicCertificateDatabase(const FilePath& database_path) = 0;
|
||||
|
||||
virtual std::unique_ptr<SharingRpcClientFactory>
|
||||
CreateSharingRpcClientFactory(
|
||||
|
||||
@@ -246,13 +246,12 @@ NearbySharingServiceImpl::NearbySharingServiceImpl(
|
||||
CHECK(analytics_recorder);
|
||||
|
||||
is_shutting_down_ = std::make_unique<bool>(false);
|
||||
FilePath full_database_path =
|
||||
FilePath profile_path =
|
||||
device_info_.GetAppDataPath().append(FilePath(kProfileRelativePath));
|
||||
|
||||
certificate_manager_ = NearbyShareCertificateManagerImpl::Factory::Create(
|
||||
context_, sharing_platform, local_device_data_manager_.get(),
|
||||
contact_manager_.get(), full_database_path.ToString(),
|
||||
nearby_share_client_factory_.get()),
|
||||
contact_manager_.get(), profile_path, nearby_share_client_factory_.get()),
|
||||
|
||||
certificate_manager_->AddObserver(this);
|
||||
context_->GetConnectivityManager()->RegisterConnectionListener(
|
||||
|
||||
Reference in New Issue
Block a user