Commit 74b454af authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Feed] Feed Storage Initialization

Implement feed storage initialization in C++.

Bug:828938

Change-Id: I33a5a9e2e7dd20c36ec945feab6ea9932e9d94a2
Reviewed-on: https://chromium-review.googlesource.com/1121834Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Gang Wu <gangwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574386}
parent 856e676d
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/feed/core/feed_image_manager.h" #include "components/feed/core/feed_image_manager.h"
#include "components/feed/core/feed_networking_host.h" #include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h" #include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h"
#include "components/image_fetcher/core/image_fetcher_impl.h" #include "components/image_fetcher/core/image_fetcher_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
...@@ -85,9 +86,11 @@ KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor( ...@@ -85,9 +86,11 @@ KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor(
auto scheduler_host = std::make_unique<FeedSchedulerHost>( auto scheduler_host = std::make_unique<FeedSchedulerHost>(
profile->GetPrefs(), base::DefaultClock::GetInstance()); profile->GetPrefs(), base::DefaultClock::GetInstance());
return new FeedHostService(std::move(image_manager), auto storage_database = std::make_unique<FeedStorageDatabase>(feed_dir);
std::move(networking_host),
std::move(scheduler_host)); return new FeedHostService(
std::move(image_manager), std::move(networking_host),
std::move(scheduler_host), std::move(storage_database));
} }
content::BrowserContext* FeedHostServiceFactory::GetBrowserContextToUse( content::BrowserContext* FeedHostServiceFactory::GetBrowserContextToUse(
......
...@@ -11,10 +11,12 @@ namespace feed { ...@@ -11,10 +11,12 @@ namespace feed {
FeedHostService::FeedHostService( FeedHostService::FeedHostService(
std::unique_ptr<FeedImageManager> image_manager, std::unique_ptr<FeedImageManager> image_manager,
std::unique_ptr<FeedNetworkingHost> networking_host, std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host) std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database)
: image_manager_(std::move(image_manager)), : image_manager_(std::move(image_manager)),
networking_host_(std::move(networking_host)), networking_host_(std::move(networking_host)),
scheduler_host_(std::move(scheduler_host)) {} scheduler_host_(std::move(scheduler_host)),
storage_database_(std::move(storage_database)) {}
FeedHostService::~FeedHostService() = default; FeedHostService::~FeedHostService() = default;
...@@ -30,4 +32,8 @@ FeedSchedulerHost* FeedHostService::GetSchedulerHost() { ...@@ -30,4 +32,8 @@ FeedSchedulerHost* FeedHostService::GetSchedulerHost() {
return scheduler_host_.get(); return scheduler_host_.get();
} }
FeedStorageDatabase* FeedHostService::GetStorageDatabase() {
return storage_database_.get();
}
} // namespace feed } // namespace feed
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/feed/core/feed_image_manager.h" #include "components/feed/core/feed_image_manager.h"
#include "components/feed/core/feed_networking_host.h" #include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h" #include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
namespace feed { namespace feed {
...@@ -24,17 +25,20 @@ class FeedHostService : public KeyedService { ...@@ -24,17 +25,20 @@ class FeedHostService : public KeyedService {
public: public:
FeedHostService(std::unique_ptr<FeedImageManager> image_manager, FeedHostService(std::unique_ptr<FeedImageManager> image_manager,
std::unique_ptr<FeedNetworkingHost> networking_host, std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host); std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database);
~FeedHostService() override; ~FeedHostService() override;
FeedImageManager* GetImageManager(); FeedImageManager* GetImageManager();
FeedNetworkingHost* GetNetworkingHost(); FeedNetworkingHost* GetNetworkingHost();
FeedSchedulerHost* GetSchedulerHost(); FeedSchedulerHost* GetSchedulerHost();
FeedStorageDatabase* GetStorageDatabase();
private: private:
std::unique_ptr<FeedImageManager> image_manager_; std::unique_ptr<FeedImageManager> image_manager_;
std::unique_ptr<FeedNetworkingHost> networking_host_; std::unique_ptr<FeedNetworkingHost> networking_host_;
std::unique_ptr<FeedSchedulerHost> scheduler_host_; std::unique_ptr<FeedSchedulerHost> scheduler_host_;
std::unique_ptr<FeedStorageDatabase> storage_database_;
DISALLOW_COPY_AND_ASSIGN(FeedHostService); DISALLOW_COPY_AND_ASSIGN(FeedHostService);
}; };
......
...@@ -75,13 +75,13 @@ bool DatabasePrefixFilter(const std::string& key_prefix, ...@@ -75,13 +75,13 @@ bool DatabasePrefixFilter(const std::string& key_prefix,
} // namespace } // namespace
FeedStorageDatabase::FeedStorageDatabase( FeedStorageDatabase::FeedStorageDatabase(const base::FilePath& database_folder)
const base::FilePath& database_folder,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: FeedStorageDatabase( : FeedStorageDatabase(
database_folder, database_folder,
std::make_unique<leveldb_proto::ProtoDatabaseImpl<FeedStorageProto>>( std::make_unique<leveldb_proto::ProtoDatabaseImpl<FeedStorageProto>>(
task_runner)) {} base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}))) {}
FeedStorageDatabase::FeedStorageDatabase( FeedStorageDatabase::FeedStorageDatabase(
const base::FilePath& database_folder, const base::FilePath& database_folder,
......
...@@ -49,9 +49,7 @@ class FeedStorageDatabase { ...@@ -49,9 +49,7 @@ class FeedStorageDatabase {
using ConfirmationCallback = base::OnceCallback<void(bool)>; using ConfirmationCallback = base::OnceCallback<void(bool)>;
// Initializes the database with |database_folder|. // Initializes the database with |database_folder|.
FeedStorageDatabase( explicit FeedStorageDatabase(const base::FilePath& database_folder);
const base::FilePath& database_folder,
const scoped_refptr<base::SequencedTaskRunner>& task_runner);
// Initializes the database with |database_folder|. Creates storage using the // Initializes the database with |database_folder|. Creates storage using the
// given |storage_database| for local storage. Useful for testing. // given |storage_database| for local storage. Useful for testing.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment