mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update to Chromium version 95.0.4638.0 (#920003)
Known issues: - Windows ARM64 builds are currently failing due to https://crbug.com/1242884#c31
This commit is contained in:
@@ -8,9 +8,11 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "extensions/browser/api/storage/backend_task_runner.h"
|
||||
#include "extensions/browser/api/storage/value_store_util.h"
|
||||
#include "extensions/browser/api/storage/weak_unlimited_settings_storage.h"
|
||||
#include "extensions/browser/value_store/value_store_factory.h"
|
||||
#include "extensions/common/api/storage.h"
|
||||
@@ -37,8 +39,8 @@ SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() {
|
||||
} // namespace
|
||||
|
||||
SyncValueStoreCache::SyncValueStoreCache(
|
||||
const scoped_refptr<ValueStoreFactory>& factory)
|
||||
: storage_factory_(factory), quota_(GetLocalQuotaLimits()) {
|
||||
scoped_refptr<value_store::ValueStoreFactory> factory)
|
||||
: storage_factory_(std::move(factory)), quota_(GetLocalQuotaLimits()) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
}
|
||||
|
||||
@@ -51,7 +53,7 @@ void SyncValueStoreCache::RunWithValueStoreForExtension(
|
||||
scoped_refptr<const Extension> extension) {
|
||||
DCHECK(IsOnBackendSequence());
|
||||
|
||||
ValueStore* storage = GetStorage(extension.get());
|
||||
value_store::ValueStore* storage = GetStorage(extension.get());
|
||||
|
||||
// A neat way to implement unlimited storage; if the extension has the
|
||||
// unlimited storage permission, force through all calls to Set().
|
||||
@@ -67,29 +69,34 @@ void SyncValueStoreCache::RunWithValueStoreForExtension(
|
||||
void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
|
||||
DCHECK(IsOnBackendSequence());
|
||||
storage_map_.erase(extension_id);
|
||||
storage_factory_->DeleteSettings(settings_namespace::SYNC,
|
||||
ValueStoreFactory::ModelType::APP,
|
||||
extension_id);
|
||||
storage_factory_->DeleteSettings(settings_namespace::SYNC,
|
||||
ValueStoreFactory::ModelType::EXTENSION,
|
||||
extension_id);
|
||||
|
||||
value_store_util::DeleteValueStore(settings_namespace::SYNC,
|
||||
value_store_util::ModelType::APP,
|
||||
extension_id, storage_factory_);
|
||||
|
||||
value_store_util::DeleteValueStore(settings_namespace::SYNC,
|
||||
value_store_util::ModelType::EXTENSION,
|
||||
extension_id, storage_factory_);
|
||||
}
|
||||
|
||||
ValueStore* SyncValueStoreCache::GetStorage(const Extension* extension) {
|
||||
StorageMap::iterator iter = storage_map_.find(extension->id());
|
||||
value_store::ValueStore* SyncValueStoreCache::GetStorage(
|
||||
const Extension* extension) {
|
||||
auto iter = storage_map_.find(extension->id());
|
||||
if (iter != storage_map_.end())
|
||||
return iter->second.get();
|
||||
|
||||
ValueStoreFactory::ModelType model_type =
|
||||
extension->is_app() ? ValueStoreFactory::ModelType::APP
|
||||
: ValueStoreFactory::ModelType::EXTENSION;
|
||||
std::unique_ptr<ValueStore> store = storage_factory_->CreateSettingsStore(
|
||||
settings_namespace::SYNC, model_type, extension->id());
|
||||
value_store_util::ModelType model_type =
|
||||
extension->is_app() ? value_store_util::ModelType::APP
|
||||
: value_store_util::ModelType::EXTENSION;
|
||||
std::unique_ptr<value_store::ValueStore> store =
|
||||
value_store_util::CreateSettingsStore(settings_namespace::LOCAL,
|
||||
model_type, extension->id(),
|
||||
storage_factory_);
|
||||
std::unique_ptr<SettingsStorageQuotaEnforcer> storage(
|
||||
new SettingsStorageQuotaEnforcer(quota_, std::move(store)));
|
||||
DCHECK(storage.get());
|
||||
|
||||
ValueStore* storage_ptr = storage.get();
|
||||
value_store::ValueStore* storage_ptr = storage.get();
|
||||
storage_map_[extension->id()] = std::move(storage);
|
||||
return storage_ptr;
|
||||
}
|
||||
|
@@ -14,10 +14,11 @@
|
||||
#include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
|
||||
#include "extensions/browser/api/storage/value_store_cache.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
namespace value_store {
|
||||
class ValueStoreFactory;
|
||||
}
|
||||
|
||||
namespace extensions {
|
||||
namespace cef {
|
||||
|
||||
// Based on LocalValueStoreCache
|
||||
@@ -25,7 +26,8 @@ namespace cef {
|
||||
// another for extensions. Each backend takes care of persistence.
|
||||
class SyncValueStoreCache : public ValueStoreCache {
|
||||
public:
|
||||
explicit SyncValueStoreCache(const scoped_refptr<ValueStoreFactory>& factory);
|
||||
explicit SyncValueStoreCache(
|
||||
scoped_refptr<value_store::ValueStoreFactory> factory);
|
||||
~SyncValueStoreCache() override;
|
||||
|
||||
// ValueStoreCache implementation:
|
||||
@@ -35,12 +37,13 @@ class SyncValueStoreCache : public ValueStoreCache {
|
||||
void DeleteStorageSoon(const std::string& extension_id) override;
|
||||
|
||||
private:
|
||||
using StorageMap = std::map<std::string, std::unique_ptr<ValueStore>>;
|
||||
using StorageMap =
|
||||
std::map<std::string, std::unique_ptr<value_store::ValueStore>>;
|
||||
|
||||
ValueStore* GetStorage(const Extension* extension);
|
||||
value_store::ValueStore* GetStorage(const Extension* extension);
|
||||
|
||||
// The Factory to use for creating new ValueStores.
|
||||
const scoped_refptr<ValueStoreFactory> storage_factory_;
|
||||
const scoped_refptr<value_store::ValueStoreFactory> storage_factory_;
|
||||
|
||||
// Quota limits (see SettingsStorageQuotaEnforcer).
|
||||
const SettingsStorageQuotaEnforcer::Limits quota_;
|
||||
@@ -50,6 +53,7 @@ class SyncValueStoreCache : public ValueStoreCache {
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SyncValueStoreCache);
|
||||
};
|
||||
|
||||
} // namespace cef
|
||||
} // namespace extensions
|
||||
|
||||
|
@@ -78,7 +78,7 @@ TabsCreateFunction::TabsCreateFunction() : cef_details_(this) {}
|
||||
|
||||
ExtensionFunction::ResponseAction TabsCreateFunction::Run() {
|
||||
std::unique_ptr<tabs::Create::Params> params(
|
||||
tabs::Create::Params::Create(*args_));
|
||||
tabs::Create::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params.get());
|
||||
|
||||
CefExtensionFunctionDetails::OpenTabParams options;
|
||||
@@ -119,7 +119,7 @@ content::WebContents* BaseAPIFunction::GetWebContents(int tab_id) {
|
||||
|
||||
ExtensionFunction::ResponseAction TabsUpdateFunction::Run() {
|
||||
std::unique_ptr<tabs::Update::Params> params(
|
||||
tabs::Update::Params::Create(*args_));
|
||||
tabs::Update::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params.get());
|
||||
|
||||
tab_id_ = params->tab_id ? *params->tab_id : -1;
|
||||
@@ -256,11 +256,10 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
|
||||
if (init_result_)
|
||||
return init_result_.value();
|
||||
|
||||
const auto list_view = args_->GetList();
|
||||
if (list_view.size() < 2)
|
||||
if (args().size() < 2)
|
||||
return set_init_result(VALIDATION_FAILURE);
|
||||
|
||||
const auto& tab_id_value = list_view[0];
|
||||
const auto& tab_id_value = args()[0];
|
||||
// |tab_id| is optional so it's ok if it's not there.
|
||||
int tab_id = -1;
|
||||
if (tab_id_value.is_int()) {
|
||||
@@ -272,7 +271,7 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() {
|
||||
}
|
||||
|
||||
// |details| are not optional.
|
||||
const base::Value& details_value = list_view[1];
|
||||
const base::Value& details_value = args()[1];
|
||||
if (!details_value.is_dict())
|
||||
return set_init_result(VALIDATION_FAILURE);
|
||||
std::unique_ptr<InjectDetails> details(new InjectDetails());
|
||||
@@ -414,7 +413,7 @@ bool TabsRemoveCSSFunction::ShouldRemoveCSS() const {
|
||||
|
||||
ExtensionFunction::ResponseAction TabsSetZoomFunction::Run() {
|
||||
std::unique_ptr<tabs::SetZoom::Params> params(
|
||||
tabs::SetZoom::Params::Create(*args_));
|
||||
tabs::SetZoom::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
int tab_id = params->tab_id ? *params->tab_id : -1;
|
||||
@@ -444,7 +443,7 @@ ExtensionFunction::ResponseAction TabsSetZoomFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction TabsGetZoomFunction::Run() {
|
||||
std::unique_ptr<tabs::GetZoom::Params> params(
|
||||
tabs::GetZoom::Params::Create(*args_));
|
||||
tabs::GetZoom::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
int tab_id = params->tab_id ? *params->tab_id : -1;
|
||||
@@ -463,7 +462,7 @@ ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
|
||||
using api::tabs::ZoomSettings;
|
||||
|
||||
std::unique_ptr<tabs::SetZoomSettings::Params> params(
|
||||
tabs::SetZoomSettings::Params::Create(*args_));
|
||||
tabs::SetZoomSettings::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
int tab_id = params->tab_id ? *params->tab_id : -1;
|
||||
@@ -512,7 +511,7 @@ ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
|
||||
|
||||
ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() {
|
||||
std::unique_ptr<tabs::GetZoomSettings::Params> params(
|
||||
tabs::GetZoomSettings::Params::Create(*args_));
|
||||
tabs::GetZoomSettings::Params::Create(args()));
|
||||
EXTENSION_FUNCTION_VALIDATE(params);
|
||||
|
||||
int tab_id = params->tab_id ? *params->tab_id : -1;
|
||||
|
@@ -420,7 +420,8 @@ StateStore* CefExtensionSystem::rules_store() {
|
||||
return rules_store_.get();
|
||||
}
|
||||
|
||||
scoped_refptr<ValueStoreFactory> CefExtensionSystem::store_factory() {
|
||||
scoped_refptr<value_store::ValueStoreFactory>
|
||||
CefExtensionSystem::store_factory() {
|
||||
return store_factory_;
|
||||
}
|
||||
|
||||
@@ -518,18 +519,19 @@ CefExtensionSystem::ComponentExtensionInfo::ComponentExtensionInfo(
|
||||
}
|
||||
|
||||
void CefExtensionSystem::InitPrefs() {
|
||||
store_factory_ = new CefValueStoreFactory(browser_context_->GetPath());
|
||||
store_factory_ =
|
||||
new value_store::CefValueStoreFactory(browser_context_->GetPath());
|
||||
|
||||
Profile* profile = Profile::FromBrowserContext(browser_context_);
|
||||
|
||||
// Two state stores. The latter, which contains declarative rules, must be
|
||||
// loaded immediately so that the rules are ready before we issue network
|
||||
// requests.
|
||||
state_store_.reset(new StateStore(
|
||||
profile, store_factory_, ValueStoreFrontend::BackendType::STATE, true));
|
||||
state_store_ = std::make_unique<StateStore>(
|
||||
profile, store_factory_, StateStore::BackendType::STATE, true);
|
||||
|
||||
rules_store_.reset(new StateStore(
|
||||
profile, store_factory_, ValueStoreFrontend::BackendType::RULES, false));
|
||||
rules_store_ = std::make_unique<StateStore>(
|
||||
profile, store_factory_, StateStore::BackendType::RULES, false);
|
||||
}
|
||||
|
||||
// Implementation based on ComponentLoader::CreateExtension.
|
||||
|
@@ -90,7 +90,7 @@ class CefExtensionSystem : public ExtensionSystem {
|
||||
UserScriptManager* user_script_manager() override;
|
||||
StateStore* state_store() override;
|
||||
StateStore* rules_store() override;
|
||||
scoped_refptr<ValueStoreFactory> store_factory() override;
|
||||
scoped_refptr<value_store::ValueStoreFactory> store_factory() override;
|
||||
InfoMap* info_map() override;
|
||||
QuotaService* quota_service() override;
|
||||
AppSorting* app_sorting() override;
|
||||
@@ -176,7 +176,7 @@ class CefExtensionSystem : public ExtensionSystem {
|
||||
|
||||
std::unique_ptr<StateStore> state_store_;
|
||||
std::unique_ptr<StateStore> rules_store_;
|
||||
scoped_refptr<ValueStoreFactory> store_factory_;
|
||||
scoped_refptr<value_store::ValueStoreFactory> store_factory_;
|
||||
|
||||
// Signaled when the extension system has completed its startup tasks.
|
||||
base::OneShotEvent ready_;
|
||||
|
@@ -65,7 +65,7 @@ void CefExtensionsAPIClient::AttachWebContentsHelpers(
|
||||
|
||||
void CefExtensionsAPIClient::AddAdditionalValueStoreCaches(
|
||||
content::BrowserContext* context,
|
||||
const scoped_refptr<ValueStoreFactory>& factory,
|
||||
const scoped_refptr<value_store::ValueStoreFactory>& factory,
|
||||
const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>&
|
||||
observers,
|
||||
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches) {
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#define CEF_LIBCEF_BROWSER_EXTENSIONS_EXTENSIONS_API_CLIENT_H_
|
||||
|
||||
#include "extensions/browser/api/extensions_api_client.h"
|
||||
#include "extensions/browser/value_store/value_store_factory.h"
|
||||
|
||||
namespace extensions {
|
||||
|
||||
@@ -31,7 +32,7 @@ class CefExtensionsAPIClient : public ExtensionsAPIClient {
|
||||
// to |caches|. By default adds nothing.
|
||||
void AddAdditionalValueStoreCaches(
|
||||
content::BrowserContext* context,
|
||||
const scoped_refptr<ValueStoreFactory>& factory,
|
||||
const scoped_refptr<value_store::ValueStoreFactory>& factory,
|
||||
const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>&
|
||||
observers,
|
||||
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches)
|
||||
|
@@ -5,12 +5,14 @@
|
||||
|
||||
#include "libcef/browser/extensions/value_store/cef_value_store.h"
|
||||
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/notreached.h"
|
||||
|
||||
namespace value_store {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kGenericErrorMessage[] = "CefValueStore configured to error";
|
||||
@@ -23,9 +25,8 @@ ValueStore::Status CreateStatusCopy(const ValueStore::Status& status) {
|
||||
|
||||
} // namespace
|
||||
|
||||
CefValueStore::CefValueStore() : read_count_(0), write_count_(0) {}
|
||||
|
||||
CefValueStore::~CefValueStore() {}
|
||||
CefValueStore::CefValueStore() = default;
|
||||
CefValueStore::~CefValueStore() = default;
|
||||
|
||||
void CefValueStore::set_status_code(StatusCode status_code) {
|
||||
status_ = ValueStore::Status(status_code, kGenericErrorMessage);
|
||||
@@ -33,19 +34,19 @@ void CefValueStore::set_status_code(StatusCode status_code) {
|
||||
|
||||
size_t CefValueStore::GetBytesInUse(const std::string& key) {
|
||||
// Let SettingsStorageQuotaEnforcer implement this.
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "Not implemented";
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t CefValueStore::GetBytesInUse(const std::vector<std::string>& keys) {
|
||||
// Let SettingsStorageQuotaEnforcer implement this.
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "Not implemented";
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t CefValueStore::GetBytesInUse() {
|
||||
// Let SettingsStorageQuotaEnforcer implement this.
|
||||
NOTREACHED();
|
||||
NOTREACHED() << "Not implemented";
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ ValueStore::WriteResult CefValueStore::Set(WriteOptions options,
|
||||
const std::string& key,
|
||||
const base::Value& value) {
|
||||
base::DictionaryValue settings;
|
||||
settings.SetWithoutPathExpansion(key, value.CreateDeepCopy());
|
||||
settings.SetKey(key, value.Clone());
|
||||
return Set(options, settings);
|
||||
}
|
||||
|
||||
@@ -134,4 +135,6 @@ ValueStore::WriteResult CefValueStore::Clear() {
|
||||
keys.push_back(it.key());
|
||||
}
|
||||
return Remove(keys);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace value_store
|
||||
|
@@ -15,25 +15,29 @@
|
||||
#include "base/macros.h"
|
||||
#include "extensions/browser/value_store/value_store.h"
|
||||
|
||||
// Implementation Based on TestingValueStore
|
||||
// ValueStore with an in-memory storage but the ability to
|
||||
// optionally fail all operations.
|
||||
namespace value_store {
|
||||
|
||||
// Implementation Based on TestingValueStore.
|
||||
// ValueStore with an in-memory storage but the ability to optionally fail all
|
||||
// operations.
|
||||
class CefValueStore : public ValueStore {
|
||||
public:
|
||||
CefValueStore();
|
||||
~CefValueStore() override;
|
||||
CefValueStore(const CefValueStore&) = delete;
|
||||
CefValueStore& operator=(const CefValueStore&) = delete;
|
||||
|
||||
// Sets the error code for requests. If OK, errors won't be thrown.
|
||||
// Defaults to OK.
|
||||
void set_status_code(StatusCode status_code);
|
||||
|
||||
// Accessors for the number of reads/writes done by this value store. Each
|
||||
// Get* operation (except for the BytesInUse ones) counts as one read, and
|
||||
// each Set*/Remove/Clear operation counts as one write. This is useful in
|
||||
// tests seeking to assert that some number of reads/writes to their
|
||||
// underlying value store have (or have not) happened.
|
||||
int read_count() const { return read_count_; }
|
||||
int write_count() const { return write_count_; }
|
||||
|
||||
// Sets the error code for requests. If OK, errors won't be thrown.
|
||||
// Defaults to OK.
|
||||
void set_status_code(StatusCode status_code);
|
||||
int read_count() { return read_count_; }
|
||||
int write_count() { return write_count_; }
|
||||
|
||||
// ValueStore implementation.
|
||||
size_t GetBytesInUse(const std::string& key) override;
|
||||
@@ -53,11 +57,11 @@ class CefValueStore : public ValueStore {
|
||||
|
||||
private:
|
||||
base::DictionaryValue storage_;
|
||||
int read_count_;
|
||||
int write_count_;
|
||||
int read_count_ = 0;
|
||||
int write_count_ = 0;
|
||||
ValueStore::Status status_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefValueStore);
|
||||
};
|
||||
|
||||
} // namespace value_store
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_H_
|
||||
|
@@ -5,9 +5,11 @@
|
||||
|
||||
#include "libcef/browser/extensions/value_store/cef_value_store_factory.h"
|
||||
|
||||
#include "libcef/browser/extensions/value_store/cef_value_store.h"
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "extensions/browser/value_store/leveldb_value_store.h"
|
||||
#include "libcef/browser/extensions/value_store/cef_value_store.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -15,177 +17,58 @@ const char kUMAClientName[] = "Cef";
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace extensions {
|
||||
|
||||
using SettingsNamespace = settings_namespace::Namespace;
|
||||
|
||||
CefValueStoreFactory::StorageHelper::StorageHelper() = default;
|
||||
|
||||
CefValueStoreFactory::StorageHelper::~StorageHelper() = default;
|
||||
|
||||
std::set<ExtensionId> CefValueStoreFactory::StorageHelper::GetKnownExtensionIDs(
|
||||
ModelType model_type) const {
|
||||
std::set<ExtensionId> ids;
|
||||
switch (model_type) {
|
||||
case ValueStoreFactory::ModelType::APP:
|
||||
for (const auto& key : app_stores_)
|
||||
ids.insert(key.first);
|
||||
break;
|
||||
case ValueStoreFactory::ModelType::EXTENSION:
|
||||
for (const auto& key : extension_stores_)
|
||||
ids.insert(key.first);
|
||||
break;
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
void CefValueStoreFactory::StorageHelper::Reset() {
|
||||
app_stores_.clear();
|
||||
extension_stores_.clear();
|
||||
}
|
||||
|
||||
ValueStore* CefValueStoreFactory::StorageHelper::AddValueStore(
|
||||
const ExtensionId& extension_id,
|
||||
ValueStore* value_store,
|
||||
ModelType model_type) {
|
||||
if (model_type == ValueStoreFactory::ModelType::APP) {
|
||||
DCHECK(app_stores_.find(extension_id) == app_stores_.end());
|
||||
app_stores_[extension_id] = value_store;
|
||||
} else {
|
||||
DCHECK(extension_stores_.find(extension_id) == extension_stores_.end());
|
||||
extension_stores_[extension_id] = value_store;
|
||||
}
|
||||
return value_store;
|
||||
}
|
||||
|
||||
void CefValueStoreFactory::StorageHelper::DeleteSettings(
|
||||
const ExtensionId& extension_id,
|
||||
ModelType model_type) {
|
||||
switch (model_type) {
|
||||
case ValueStoreFactory::ModelType::APP:
|
||||
app_stores_.erase(extension_id);
|
||||
break;
|
||||
case ValueStoreFactory::ModelType::EXTENSION:
|
||||
extension_stores_.erase(extension_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CefValueStoreFactory::StorageHelper::HasSettings(
|
||||
const ExtensionId& extension_id,
|
||||
ModelType model_type) const {
|
||||
switch (model_type) {
|
||||
case ValueStoreFactory::ModelType::APP:
|
||||
return app_stores_.find(extension_id) != app_stores_.end();
|
||||
case ValueStoreFactory::ModelType::EXTENSION:
|
||||
return extension_stores_.find(extension_id) != extension_stores_.end();
|
||||
}
|
||||
NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
ValueStore* CefValueStoreFactory::StorageHelper::GetExisting(
|
||||
const ExtensionId& extension_id) const {
|
||||
auto it = app_stores_.find(extension_id);
|
||||
if (it != app_stores_.end())
|
||||
return it->second;
|
||||
it = extension_stores_.find(extension_id);
|
||||
if (it != extension_stores_.end())
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
namespace value_store {
|
||||
|
||||
CefValueStoreFactory::CefValueStoreFactory() = default;
|
||||
|
||||
CefValueStoreFactory::CefValueStoreFactory(const base::FilePath& db_path)
|
||||
: db_path_(db_path) {}
|
||||
|
||||
CefValueStoreFactory::~CefValueStoreFactory() {}
|
||||
CefValueStoreFactory::~CefValueStoreFactory() = default;
|
||||
|
||||
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateRulesStore() {
|
||||
if (db_path_.empty())
|
||||
last_created_store_ = new CefValueStore();
|
||||
else
|
||||
last_created_store_ = new LeveldbValueStore(kUMAClientName, db_path_);
|
||||
return base::WrapUnique(last_created_store_);
|
||||
}
|
||||
|
||||
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateStateStore() {
|
||||
return CreateRulesStore();
|
||||
}
|
||||
|
||||
CefValueStoreFactory::StorageHelper& CefValueStoreFactory::GetStorageHelper(
|
||||
SettingsNamespace settings_namespace) {
|
||||
switch (settings_namespace) {
|
||||
case settings_namespace::LOCAL:
|
||||
return local_helper_;
|
||||
case settings_namespace::SYNC:
|
||||
return sync_helper_;
|
||||
case settings_namespace::MANAGED:
|
||||
return managed_helper_;
|
||||
case settings_namespace::INVALID:
|
||||
break;
|
||||
}
|
||||
NOTREACHED();
|
||||
return local_helper_;
|
||||
}
|
||||
|
||||
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateSettingsStore(
|
||||
SettingsNamespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) {
|
||||
std::unique_ptr<ValueStore> settings_store(CreateRulesStore());
|
||||
// Note: This factory is purposely keeping the raw pointers to each ValueStore
|
||||
// created. Tests using CefValueStoreFactory must be careful to keep
|
||||
// those ValueStore's alive for the duration of their test.
|
||||
GetStorageHelper(settings_namespace)
|
||||
.AddValueStore(extension_id, settings_store.get(), model_type);
|
||||
return settings_store;
|
||||
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateValueStore(
|
||||
const base::FilePath& directory,
|
||||
const std::string& uma_client_name) {
|
||||
std::unique_ptr<ValueStore> value_store(CreateStore());
|
||||
// This factory is purposely keeping the raw pointers to each ValueStore
|
||||
// created. Cefs using CefValueStoreFactory must be careful to keep
|
||||
// those ValueStore's alive for the duration of their test.
|
||||
value_store_map_[directory] = value_store.get();
|
||||
return value_store;
|
||||
}
|
||||
|
||||
ValueStore* CefValueStoreFactory::LastCreatedStore() const {
|
||||
return last_created_store_;
|
||||
}
|
||||
|
||||
void CefValueStoreFactory::DeleteSettings(SettingsNamespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) {
|
||||
GetStorageHelper(settings_namespace).DeleteSettings(extension_id, model_type);
|
||||
void CefValueStoreFactory::DeleteValueStore(const base::FilePath& directory) {
|
||||
value_store_map_.erase(directory);
|
||||
}
|
||||
|
||||
bool CefValueStoreFactory::HasSettings(SettingsNamespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) {
|
||||
return GetStorageHelper(settings_namespace)
|
||||
.HasSettings(extension_id, model_type);
|
||||
}
|
||||
|
||||
std::set<ExtensionId> CefValueStoreFactory::GetKnownExtensionIDs(
|
||||
SettingsNamespace settings_namespace,
|
||||
ModelType model_type) const {
|
||||
return const_cast<CefValueStoreFactory*>(this)
|
||||
->GetStorageHelper(settings_namespace)
|
||||
.GetKnownExtensionIDs(model_type);
|
||||
bool CefValueStoreFactory::HasValueStore(const base::FilePath& directory) {
|
||||
return base::Contains(value_store_map_, directory);
|
||||
}
|
||||
|
||||
ValueStore* CefValueStoreFactory::GetExisting(
|
||||
const ExtensionId& extension_id) const {
|
||||
ValueStore* existing_store = local_helper_.GetExisting(extension_id);
|
||||
if (existing_store)
|
||||
return existing_store;
|
||||
existing_store = sync_helper_.GetExisting(extension_id);
|
||||
if (existing_store)
|
||||
return existing_store;
|
||||
existing_store = managed_helper_.GetExisting(extension_id);
|
||||
DCHECK(existing_store != nullptr);
|
||||
return existing_store;
|
||||
const base::FilePath& directory) const {
|
||||
auto it = value_store_map_.find(directory);
|
||||
DCHECK(it != value_store_map_.end());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void CefValueStoreFactory::Reset() {
|
||||
last_created_store_ = nullptr;
|
||||
local_helper_.Reset();
|
||||
sync_helper_.Reset();
|
||||
managed_helper_.Reset();
|
||||
value_store_map_.clear();
|
||||
}
|
||||
|
||||
} // namespace extensions
|
||||
std::unique_ptr<ValueStore> CefValueStoreFactory::CreateStore() {
|
||||
std::unique_ptr<ValueStore> store;
|
||||
if (db_path_.empty())
|
||||
store = std::make_unique<CefValueStore>();
|
||||
else
|
||||
store = std::make_unique<LeveldbValueStore>(kUMAClientName, db_path_);
|
||||
last_created_store_ = store.get();
|
||||
return store;
|
||||
}
|
||||
|
||||
} // namespace value_store
|
||||
|
@@ -8,90 +8,54 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "extensions/browser/value_store/value_store_factory.h"
|
||||
#include "extensions/common/extension_id.h"
|
||||
|
||||
namespace value_store {
|
||||
|
||||
class ValueStore;
|
||||
|
||||
namespace extensions {
|
||||
|
||||
// Will either open a database on disk (if path provided) returning a
|
||||
// |LeveldbValueStore|. Otherwise a new |CefValueStore| instance will be
|
||||
// returned.
|
||||
// Based on TestValueStoreFactory. Will either open a database on disk (if path
|
||||
// provided) returning a |LeveldbValueStore|. Otherwise a new |CefingValueStore|
|
||||
// instance will be returned.
|
||||
class CefValueStoreFactory : public ValueStoreFactory {
|
||||
public:
|
||||
CefValueStoreFactory();
|
||||
explicit CefValueStoreFactory(const base::FilePath& db_path);
|
||||
CefValueStoreFactory(const CefValueStoreFactory&) = delete;
|
||||
CefValueStoreFactory& operator=(const CefValueStoreFactory&) = delete;
|
||||
|
||||
// ValueStoreFactory
|
||||
std::unique_ptr<ValueStore> CreateRulesStore() override;
|
||||
std::unique_ptr<ValueStore> CreateStateStore() override;
|
||||
std::unique_ptr<ValueStore> CreateSettingsStore(
|
||||
settings_namespace::Namespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) override;
|
||||
void DeleteSettings(settings_namespace::Namespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) override;
|
||||
bool HasSettings(settings_namespace::Namespace settings_namespace,
|
||||
ModelType model_type,
|
||||
const ExtensionId& extension_id) override;
|
||||
std::set<ExtensionId> GetKnownExtensionIDs(
|
||||
settings_namespace::Namespace settings_namespace,
|
||||
ModelType model_type) const override;
|
||||
std::unique_ptr<ValueStore> CreateValueStore(
|
||||
const base::FilePath& directory,
|
||||
const std::string& uma_client_name) override;
|
||||
void DeleteValueStore(const base::FilePath& directory) override;
|
||||
bool HasValueStore(const base::FilePath& directory) override;
|
||||
|
||||
// Return the last created |ValueStore|. Use with caution as this may return
|
||||
// a dangling pointer since the creator now owns the ValueStore which can be
|
||||
// deleted at any time.
|
||||
ValueStore* LastCreatedStore() const;
|
||||
// Return a previously created |ValueStore| for an extension.
|
||||
ValueStore* GetExisting(const ExtensionId& extension_id) const;
|
||||
// Return the previously created |ValueStore| in the given directory.
|
||||
ValueStore* GetExisting(const base::FilePath& directory) const;
|
||||
// Reset this class (as if just created).
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
// Manages a collection of |ValueStore|'s created for an app/extension.
|
||||
// One of these exists for each setting type.
|
||||
class StorageHelper {
|
||||
public:
|
||||
StorageHelper();
|
||||
~StorageHelper();
|
||||
std::set<ExtensionId> GetKnownExtensionIDs(ModelType model_type) const;
|
||||
ValueStore* AddValueStore(const ExtensionId& extension_id,
|
||||
ValueStore* value_store,
|
||||
ModelType model_type);
|
||||
void DeleteSettings(const ExtensionId& extension_id, ModelType model_type);
|
||||
bool HasSettings(const ExtensionId& extension_id,
|
||||
ModelType model_type) const;
|
||||
void Reset();
|
||||
ValueStore* GetExisting(const ExtensionId& extension_id) const;
|
||||
|
||||
private:
|
||||
std::map<ExtensionId, ValueStore*> app_stores_;
|
||||
std::map<ExtensionId, ValueStore*> extension_stores_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(StorageHelper);
|
||||
};
|
||||
|
||||
StorageHelper& GetStorageHelper(
|
||||
settings_namespace::Namespace settings_namespace);
|
||||
|
||||
~CefValueStoreFactory() override;
|
||||
|
||||
std::unique_ptr<ValueStore> CreateStore();
|
||||
|
||||
base::FilePath db_path_;
|
||||
ValueStore* last_created_store_ = nullptr;
|
||||
|
||||
// None of these value stores are owned by this factory, so care must be
|
||||
// taken when calling GetExisting.
|
||||
StorageHelper local_helper_;
|
||||
StorageHelper sync_helper_;
|
||||
StorageHelper managed_helper_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CefValueStoreFactory);
|
||||
// A mapping from directories to their ValueStore. None of these value
|
||||
// stores are owned by this factory, so care must be taken when calling
|
||||
// GetExisting.
|
||||
std::map<base::FilePath, ValueStore*> value_store_map_;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
} // namespace value_store
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_VALUE_STORE_CEF_VALUE_STORE_FACTORY_H_
|
||||
|
Reference in New Issue
Block a user