
See linked bug for rationale. Quick follow-up to https://crrev.com/c/5756944 where the files were renamed. In this patch, the classes are renamed too, generated using the following commands: git grep -l ModelTypeStore | \ xargs sed -i 's/\([^.]\)ModelTypeStore/\1DataTypeStore/g' git grep -l ModelTypeStore | \ xargs sed -i 's/^ModelTypeStore/DataTypeStore/g' git grep -l model_type_store | \ xargs sed -i 's/model_type_store/data_type_store/g' git cl format Some DependsOn() orderings were fixed manually, as well as string occurrences in ProfileKeyedServiceBrowserTest and calls to the factories' GetInstance() functions. Note that renaming proto ModelTypeStoreSchemaDescriptor is fine because it is used locally (client-side) only and it gets serialized into bytes, where the message name isn't encoded. Change-Id: I2f3b9d1c73d3bac6339f112d54c12e638ea06d66 Bug: 356649891 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5756560 Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Rushan Suleymanov <rushans@google.com> Owners-Override: Nico Weber <thakis@chromium.org> Commit-Queue: Mikel Astiz <mastiz@chromium.org> Reviewed-by: Ryan Sultanem <rsult@google.com> Cr-Commit-Position: refs/heads/main@{#1337326}
103 lines
3.5 KiB
C++
103 lines
3.5 KiB
C++
// Copyright 2018 The Chromium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_DATABASE_H_
|
|
#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_DATABASE_H_
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
|
|
#include "base/functional/callback_forward.h"
|
|
#include "base/memory/raw_ptr.h"
|
|
#include "base/memory/weak_ptr.h"
|
|
#include "base/sequence_checker.h"
|
|
#include "chrome/browser/web_applications/proto/web_app.pb.h"
|
|
#include "chrome/browser/web_applications/web_app_constants.h"
|
|
#include "chrome/browser/web_applications/web_app_registrar.h"
|
|
#include "components/sync/model/data_type_store.h"
|
|
#include "components/sync/protocol/web_app_specifics.pb.h"
|
|
#include "components/webapps/common/web_app_id.h"
|
|
|
|
namespace syncer {
|
|
class ModelError;
|
|
class MetadataBatch;
|
|
class MetadataChangeList;
|
|
} // namespace syncer
|
|
|
|
namespace web_app {
|
|
|
|
class AbstractWebAppDatabaseFactory;
|
|
class WebApp;
|
|
class WebAppProto;
|
|
struct RegistryUpdateData;
|
|
|
|
// Exclusively used from the UI thread.
|
|
class WebAppDatabase {
|
|
public:
|
|
using ReportErrorCallback =
|
|
base::RepeatingCallback<void(const syncer::ModelError&)>;
|
|
|
|
WebAppDatabase(AbstractWebAppDatabaseFactory* database_factory,
|
|
ReportErrorCallback error_callback);
|
|
WebAppDatabase(const WebAppDatabase&) = delete;
|
|
WebAppDatabase& operator=(const WebAppDatabase&) = delete;
|
|
~WebAppDatabase();
|
|
|
|
using RegistryOpenedCallback = base::OnceCallback<void(
|
|
Registry registry,
|
|
std::unique_ptr<syncer::MetadataBatch> metadata_batch)>;
|
|
// Open existing or create new DB. Read all data and return it via callback.
|
|
void OpenDatabase(RegistryOpenedCallback callback);
|
|
|
|
using CompletionCallback = base::OnceCallback<void(bool success)>;
|
|
void Write(const RegistryUpdateData& update_data,
|
|
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
|
|
CompletionCallback callback);
|
|
|
|
// Exposed for testing.
|
|
static std::unique_ptr<WebAppProto> CreateWebAppProto(const WebApp& web_app);
|
|
// Exposed for testing.
|
|
static std::unique_ptr<WebApp> ParseWebApp(const webapps::AppId& app_id,
|
|
const std::string& value);
|
|
// Exposed for testing.
|
|
static std::unique_ptr<WebApp> CreateWebApp(const WebAppProto& local_data);
|
|
|
|
bool is_opened() const { return opened_; }
|
|
|
|
private:
|
|
void OnDatabaseOpened(RegistryOpenedCallback callback,
|
|
const std::optional<syncer::ModelError>& error,
|
|
std::unique_ptr<syncer::DataTypeStore> store);
|
|
|
|
void OnAllDataAndMetadataRead(
|
|
RegistryOpenedCallback callback,
|
|
const std::optional<syncer::ModelError>& error,
|
|
std::unique_ptr<syncer::DataTypeStore::RecordList> data_records,
|
|
std::unique_ptr<syncer::MetadataBatch> metadata_batch);
|
|
|
|
void OnDataWritten(CompletionCallback callback,
|
|
const std::optional<syncer::ModelError>& error);
|
|
|
|
std::unique_ptr<syncer::DataTypeStore> store_;
|
|
const raw_ptr<AbstractWebAppDatabaseFactory, DanglingUntriaged>
|
|
database_factory_;
|
|
ReportErrorCallback error_callback_;
|
|
|
|
// Database is opened if store is created and all data read.
|
|
bool opened_ = false;
|
|
|
|
SEQUENCE_CHECKER(sequence_checker_);
|
|
|
|
base::WeakPtrFactory<WebAppDatabase> weak_ptr_factory_{this};
|
|
|
|
};
|
|
|
|
DisplayMode ToMojomDisplayMode(WebAppProto::DisplayMode display_mode);
|
|
|
|
WebAppProto::DisplayMode ToWebAppProtoDisplayMode(DisplayMode display_mode);
|
|
|
|
} // namespace web_app
|
|
|
|
#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_DATABASE_H_
|