forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For now we try to reuse as much USS code as possible. It has limitations and drawbacks (see the code). We will rethink our persistence code later when we start to design WebAppSyncBridge (an implementation for syncer::ModelTypeSyncBridge interface). Bug: 896150 Change-Id: Ia898b905f39869a6b1c3f79751358425449a617a Reviewed-on: https://chromium-review.googlesource.com/c/1295529 Reviewed-by: calamity <calamity@chromium.org> Reviewed-by: Mikel Astiz <mastiz@chromium.org> Reviewed-by: Ben Wells <benwells@chromium.org> Commit-Queue: Alexey Baskakov <loyso@chromium.org> Cr-Commit-Position: refs/heads/master@{#605974}
- Loading branch information
Alexey Baskakov
authored and
Commit Bot
committed
Nov 7, 2018
1 parent
9e150bd
commit ac8c4b0
Showing
19 changed files
with
860 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
chrome/browser/web_applications/abstract_web_app_database.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// 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_ABSTRACT_WEB_APP_DATABASE_H_ | ||
#define CHROME_BROWSER_WEB_APPLICATIONS_ABSTRACT_WEB_APP_DATABASE_H_ | ||
|
||
#include <map> | ||
#include <vector> | ||
|
||
#include "base/callback_forward.h" | ||
#include "chrome/browser/web_applications/components/web_app_helpers.h" | ||
|
||
namespace web_app { | ||
|
||
class WebApp; | ||
|
||
using Registry = std::map<AppId, std::unique_ptr<WebApp>>; | ||
|
||
// An abstract database for the registry persistence. | ||
// Exclusively used from the UI thread. | ||
class AbstractWebAppDatabase { | ||
public: | ||
virtual ~AbstractWebAppDatabase() = default; | ||
|
||
using OnceRegistryOpenedCallback = | ||
base::OnceCallback<void(Registry registry)>; | ||
// Open existing or create new DB. Read all data and return it via callback. | ||
virtual void OpenDatabase(OnceRegistryOpenedCallback callback) = 0; | ||
|
||
// |OpenDatabase| must have been called and completed before using any other | ||
// methods. Otherwise, it fails with DCHECK. | ||
virtual void WriteWebApp(const WebApp& web_app) = 0; | ||
virtual void DeleteWebApps(std::vector<AppId> app_ids) = 0; | ||
}; | ||
|
||
} // namespace web_app | ||
|
||
#endif // CHROME_BROWSER_WEB_APPLICATIONS_ABSTRACT_WEB_APP_DATABASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2018 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//third_party/protobuf/proto_library.gni") | ||
|
||
proto_library("proto") { | ||
sources = [ | ||
"web_app.proto", | ||
] | ||
deps = [ | ||
"//components/sync/protocol", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
syntax = "proto2"; | ||
|
||
option optimize_for = LITE_RUNTIME; | ||
|
||
package web_app; | ||
|
||
// WebApp class data. | ||
// TODO(loyso): Consider moving this proto to components/sync/protocol/ | ||
// crbug.com/902214. | ||
message WebAppProto { | ||
// app_id is the client tag for sync system. | ||
optional string app_id = 1; | ||
optional string name = 2; | ||
optional string description = 3; | ||
optional string launch_url = 4; | ||
} |
27 changes: 27 additions & 0 deletions
27
chrome/browser/web_applications/test/test_web_app_database.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/web_applications/test/test_web_app_database.h" | ||
|
||
#include "chrome/browser/web_applications/web_app.h" | ||
|
||
namespace web_app { | ||
|
||
TestWebAppDatabase::TestWebAppDatabase() {} | ||
|
||
TestWebAppDatabase::~TestWebAppDatabase() {} | ||
|
||
void TestWebAppDatabase::OpenDatabase(OnceRegistryOpenedCallback callback) { | ||
open_database_callback_ = std::move(callback); | ||
} | ||
|
||
void TestWebAppDatabase::WriteWebApp(const WebApp& web_app) { | ||
write_web_app_id_ = web_app.app_id(); | ||
} | ||
|
||
void TestWebAppDatabase::DeleteWebApps(std::vector<AppId> app_ids) { | ||
delete_web_app_ids_ = std::move(app_ids); | ||
} | ||
|
||
} // namespace web_app |
42 changes: 42 additions & 0 deletions
42
chrome/browser/web_applications/test/test_web_app_database.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// 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_TEST_TEST_WEB_APP_DATABASE_H_ | ||
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_WEB_APP_DATABASE_H_ | ||
|
||
#include "base/callback.h" | ||
#include "base/macros.h" | ||
#include "chrome/browser/web_applications/abstract_web_app_database.h" | ||
|
||
namespace web_app { | ||
|
||
class TestWebAppDatabase : public AbstractWebAppDatabase { | ||
public: | ||
TestWebAppDatabase(); | ||
~TestWebAppDatabase() override; | ||
|
||
// AbstractWebAppDatabase: | ||
void OpenDatabase(OnceRegistryOpenedCallback callback) override; | ||
void WriteWebApp(const WebApp& web_app) override; | ||
void DeleteWebApps(std::vector<AppId> app_ids) override; | ||
|
||
OnceRegistryOpenedCallback TakeOpenDatabaseCallback() { | ||
return std::move(open_database_callback_); | ||
} | ||
const AppId& write_web_app_id() const { return write_web_app_id_; } | ||
const std::vector<AppId>& delete_web_app_ids() const { | ||
return delete_web_app_ids_; | ||
} | ||
|
||
private: | ||
OnceRegistryOpenedCallback open_database_callback_; | ||
AppId write_web_app_id_; | ||
std::vector<AppId> delete_web_app_ids_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TestWebAppDatabase); | ||
}; | ||
|
||
} // namespace web_app | ||
|
||
#endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_WEB_APP_DATABASE_H_ |
23 changes: 23 additions & 0 deletions
23
chrome/browser/web_applications/test/test_web_app_database_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/web_applications/test/test_web_app_database_factory.h" | ||
|
||
#include "components/sync/model/model_type_store_test_util.h" | ||
|
||
namespace web_app { | ||
|
||
TestWebAppDatabaseFactory::TestWebAppDatabaseFactory() { | ||
// InMemoryStore must be created after message_loop_. | ||
store_ = syncer::ModelTypeStoreTestUtil::CreateInMemoryStoreForTest(); | ||
} | ||
|
||
TestWebAppDatabaseFactory::~TestWebAppDatabaseFactory() {} | ||
|
||
syncer::OnceModelTypeStoreFactory TestWebAppDatabaseFactory::GetStoreFactory() { | ||
return syncer::ModelTypeStoreTestUtil::FactoryForForwardingStore( | ||
store_.get()); | ||
} | ||
|
||
} // namespace web_app |
38 changes: 38 additions & 0 deletions
38
chrome/browser/web_applications/test/test_web_app_database_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// 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_TEST_TEST_WEB_APP_DATABASE_FACTORY_H_ | ||
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_WEB_APP_DATABASE_FACTORY_H_ | ||
|
||
#include "base/macros.h" | ||
#include "chrome/browser/web_applications/web_app_database_factory.h" | ||
|
||
namespace syncer { | ||
class ModelTypeStore; | ||
} // namespace syncer | ||
|
||
namespace web_app { | ||
|
||
// Requires base::MessageLoop message_loop_ in test fixture. Reason: | ||
// InMemoryStore needs a SequencedTaskRunner. | ||
// MessageLoop ctor calls MessageLoop::SetThreadTaskRunnerHandle(). | ||
class TestWebAppDatabaseFactory : public AbstractWebAppDatabaseFactory { | ||
public: | ||
TestWebAppDatabaseFactory(); | ||
~TestWebAppDatabaseFactory() override; | ||
|
||
// AbstractWebAppDatabaseFactory interface implementation. | ||
syncer::OnceModelTypeStoreFactory GetStoreFactory() override; | ||
|
||
syncer::ModelTypeStore* store() { return store_.get(); } | ||
|
||
private: | ||
std::unique_ptr<syncer::ModelTypeStore> store_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(TestWebAppDatabaseFactory); | ||
}; | ||
|
||
} // namespace web_app | ||
|
||
#endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_WEB_APP_DATABASE_FACTORY_H_ |
Oops, something went wrong.