Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model_factory.cc

Issue 2369303002: Reading List create protobuf store (Closed)
Patch Set: feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" 5 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
11 #include "components/leveldb_proto/proto_database.h"
12 #include "components/leveldb_proto/proto_database_impl.h"
13 #include "components/pref_registry/pref_registry_syncable.h"
11 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" 14 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 15 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
16 #include "ios/chrome/browser/reading_list/proto/reading_list.pb.h"
13 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h" 17 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
14 #include "ios/chrome/browser/reading_list/reading_list_model_storage_defaults.h" 18 #include "ios/chrome/browser/reading_list/reading_list_pref_names.h"
19 #include "ios/chrome/browser/reading_list/reading_list_store.h"
20 #include "ios/web/public/web_thread.h"
15 21
16 // static 22 // static
17 ReadingListModel* ReadingListModelFactory::GetForBrowserState( 23 ReadingListModel* ReadingListModelFactory::GetForBrowserState(
18 ios::ChromeBrowserState* browser_state) { 24 ios::ChromeBrowserState* browser_state) {
19 return static_cast<ReadingListModelImpl*>( 25 return static_cast<ReadingListModelImpl*>(
20 GetInstance()->GetServiceForBrowserState(browser_state, true)); 26 GetInstance()->GetServiceForBrowserState(browser_state, true));
21 } 27 }
22 28
23 // static 29 // static
24 ReadingListModel* ReadingListModelFactory::GetForBrowserStateIfExists( 30 ReadingListModel* ReadingListModelFactory::GetForBrowserStateIfExists(
25 ios::ChromeBrowserState* browser_state) { 31 ios::ChromeBrowserState* browser_state) {
26 return static_cast<ReadingListModelImpl*>( 32 return static_cast<ReadingListModelImpl*>(
27 GetInstance()->GetServiceForBrowserState(browser_state, false)); 33 GetInstance()->GetServiceForBrowserState(browser_state, false));
28 } 34 }
29 35
30 // static 36 // static
31 ReadingListModelFactory* ReadingListModelFactory::GetInstance() { 37 ReadingListModelFactory* ReadingListModelFactory::GetInstance() {
32 return base::Singleton<ReadingListModelFactory>::get(); 38 return base::Singleton<ReadingListModelFactory>::get();
33 } 39 }
34 40
35 ReadingListModelFactory::ReadingListModelFactory() 41 ReadingListModelFactory::ReadingListModelFactory()
36 : BrowserStateKeyedServiceFactory( 42 : BrowserStateKeyedServiceFactory(
37 "ReadingListModel", 43 "ReadingListModel",
38 BrowserStateDependencyManager::GetInstance()) {} 44 BrowserStateDependencyManager::GetInstance()) {}
39 45
40 ReadingListModelFactory::~ReadingListModelFactory() {} 46 ReadingListModelFactory::~ReadingListModelFactory() {}
41 47
48 void ReadingListModelFactory::RegisterProfilePrefs(
49 user_prefs::PrefRegistrySyncable* registry) {
50 // Register a not syncable pref.
sdefresne 2016/10/07 09:44:30 nit: this comment has no value in my opinion (if y
51 registry->RegisterBooleanPref(
52 reading_list::prefs::kReadingListHasUnseenEntries, false, 0);
53 }
54
42 std::unique_ptr<KeyedService> ReadingListModelFactory::BuildServiceInstanceFor( 55 std::unique_ptr<KeyedService> ReadingListModelFactory::BuildServiceInstanceFor(
43 web::BrowserState* context) const { 56 web::BrowserState* context) const {
44 std::unique_ptr<ReadingListModelStorage> storage( 57 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
45 new ReadingListModelStorageDefaults()); 58 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner(
59 web::WebThread::GetBlockingPool()->GetSequenceToken());
60 base::FilePath database_dir(
61 context->GetStatePath().Append(FILE_PATH_LITERAL("readinglist")));
62
63 std::unique_ptr<ReadingListDB> db = base::MakeUnique<
sdefresne 2016/10/07 09:44:30 nit: auto db = base::MakeUnique<...>(...) is also
64 leveldb_proto::ProtoDatabaseImpl<reading_list::ReadingListLocal>>(
65 background_task_runner);
66
67 std::unique_ptr<ReadingListStore> store =
68 base::MakeUnique<ReadingListStore>(std::move(db), database_dir);
69
70 ios::ChromeBrowserState* chrome_browser_state =
71 ios::ChromeBrowserState::FromBrowserState(context);
46 std::unique_ptr<ReadingListModelImpl> reading_list_model( 72 std::unique_ptr<ReadingListModelImpl> reading_list_model(
47 new ReadingListModelImpl(std::move(storage))); 73 new ReadingListModelImpl(std::move(store),
sdefresne 2016/10/07 09:44:30 Use base::MakeUnique<> as the constructor is publi
74 chrome_browser_state->GetPrefs()));
48 return std::move(reading_list_model); 75 return std::move(reading_list_model);
sdefresne 2016/10/07 09:44:30 Do not use "return std::move(...)" with a std::uni
49 } 76 }
50 77
51 web::BrowserState* ReadingListModelFactory::GetBrowserStateToUse( 78 web::BrowserState* ReadingListModelFactory::GetBrowserStateToUse(
52 web::BrowserState* context) const { 79 web::BrowserState* context) const {
53 return GetBrowserStateRedirectedInIncognito(context); 80 return GetBrowserStateRedirectedInIncognito(context);
54 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698