| Index: ios/chrome/browser/reading_list/reading_list_model_factory.cc
|
| diff --git a/ios/chrome/browser/reading_list/reading_list_model_factory.cc b/ios/chrome/browser/reading_list/reading_list_model_factory.cc
|
| index 5b892cf3ae6647c46bda42394556496facefa054..d132c9109d23391777bcd1e38f3ff35cf340156c 100644
|
| --- a/ios/chrome/browser/reading_list/reading_list_model_factory.cc
|
| +++ b/ios/chrome/browser/reading_list/reading_list_model_factory.cc
|
| @@ -8,14 +8,24 @@
|
|
|
| #include "base/memory/singleton.h"
|
| #include "components/keyed_service/ios/browser_state_dependency_manager.h"
|
| +#include "components/leveldb_proto/proto_database.h"
|
| +#include "components/leveldb_proto/proto_database_impl.h"
|
| +#include "components/pref_registry/pref_registry_syncable.h"
|
| #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
|
| #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
|
| +#include "ios/chrome/browser/experimental_flags.h"
|
| +#include "ios/chrome/browser/reading_list/proto/reading_list.pb.h"
|
| #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
|
| -#include "ios/chrome/browser/reading_list/reading_list_model_storage_defaults.h"
|
| +#include "ios/chrome/browser/reading_list/reading_list_pref_names.h"
|
| +#include "ios/chrome/browser/reading_list/reading_list_store.h"
|
| +#include "ios/web/public/web_thread.h"
|
|
|
| // static
|
| ReadingListModel* ReadingListModelFactory::GetForBrowserState(
|
| ios::ChromeBrowserState* browser_state) {
|
| + if (!experimental_flags::IsReadingListEnabled()) {
|
| + return nullptr;
|
| + }
|
| return static_cast<ReadingListModelImpl*>(
|
| GetInstance()->GetServiceForBrowserState(browser_state, true));
|
| }
|
| @@ -23,6 +33,9 @@ ReadingListModel* ReadingListModelFactory::GetForBrowserState(
|
| // static
|
| ReadingListModel* ReadingListModelFactory::GetForBrowserStateIfExists(
|
| ios::ChromeBrowserState* browser_state) {
|
| + if (!experimental_flags::IsReadingListEnabled()) {
|
| + return nullptr;
|
| + }
|
| return static_cast<ReadingListModelImpl*>(
|
| GetInstance()->GetServiceForBrowserState(browser_state, false));
|
| }
|
| @@ -39,12 +52,35 @@ ReadingListModelFactory::ReadingListModelFactory()
|
|
|
| ReadingListModelFactory::~ReadingListModelFactory() {}
|
|
|
| +void ReadingListModelFactory::RegisterProfilePrefs(
|
| + user_prefs::PrefRegistrySyncable* registry) {
|
| + // Register a not syncable pref.
|
| + registry->RegisterBooleanPref(
|
| + reading_list::prefs::kReadingListHasUnseenEntries, false, 0);
|
| +}
|
| +
|
| std::unique_ptr<KeyedService> ReadingListModelFactory::BuildServiceInstanceFor(
|
| web::BrowserState* context) const {
|
| - std::unique_ptr<ReadingListModelStorage> storage(
|
| - new ReadingListModelStorageDefaults());
|
| + scoped_refptr<base::SequencedTaskRunner> background_task_runner =
|
| + web::WebThread::GetBlockingPool()->GetSequencedTaskRunner(
|
| + web::WebThread::GetBlockingPool()->GetSequenceToken());
|
| + base::FilePath database_dir(
|
| + context->GetStatePath().Append(FILE_PATH_LITERAL("readinglist")));
|
| +
|
| + std::unique_ptr<ReadingListDB> db = base::MakeUnique<
|
| + leveldb_proto::ProtoDatabaseImpl<reading_list::ReadingListLocal>>(
|
| + background_task_runner);
|
| +
|
| + std::unique_ptr<ReadingListStore> store = base::MakeUnique<ReadingListStore>(
|
| + std::move(db), database_dir,
|
| + base::Bind(&syncer::ModelTypeStore::CreateStore, syncer::READING_LIST,
|
| + database_dir.AsUTF8Unsafe(), background_task_runner));
|
| +
|
| + ios::ChromeBrowserState* chrome_browser_state =
|
| + ios::ChromeBrowserState::FromBrowserState(context);
|
| std::unique_ptr<ReadingListModelImpl> reading_list_model(
|
| - new ReadingListModelImpl(std::move(storage)));
|
| + new ReadingListModelImpl(std::move(store),
|
| + chrome_browser_state->GetPrefs()));
|
| return std::move(reading_list_model);
|
| }
|
|
|
|
|