OLD | NEW |
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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "components/browser_sync/profile_sync_service.h" |
12 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 13 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
13 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
14 #include "components/reading_list/core/reading_list_switches.h" | 15 #include "components/reading_list/core/reading_list_switches.h" |
15 #include "components/reading_list/ios/reading_list_model_impl.h" | 16 #include "components/reading_list/ios/reading_list_model_impl.h" |
16 #include "components/reading_list/ios/reading_list_pref_names.h" | 17 #include "components/reading_list/ios/reading_list_pref_names.h" |
17 #include "components/reading_list/ios/reading_list_store.h" | 18 #include "components/reading_list/ios/reading_list_store.h" |
18 #include "components/sync/base/report_unrecoverable_error.h" | 19 #include "components/sync/base/report_unrecoverable_error.h" |
19 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" | 20 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" |
20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 21 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
21 #include "ios/chrome/browser/experimental_flags.h" | 22 #include "ios/chrome/browser/experimental_flags.h" |
| 23 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
22 #include "ios/chrome/common/channel_info.h" | 24 #include "ios/chrome/common/channel_info.h" |
23 #include "ios/web/public/web_thread.h" | 25 #include "ios/web/public/web_thread.h" |
24 | 26 |
25 // static | 27 // static |
26 bool ReadingListModelFactory::IsReadingListEnabled() { | 28 bool ReadingListModelFactory::IsReadingListEnabled() { |
27 return reading_list::switches::IsReadingListEnabled(); | 29 return reading_list::switches::IsReadingListEnabled(); |
28 } | 30 } |
29 | 31 |
30 // static | 32 // static |
31 ReadingListModel* ReadingListModelFactory::GetForBrowserState( | 33 ReadingListModel* ReadingListModelFactory::GetForBrowserState( |
(...skipping 23 matching lines...) Expand all Loading... |
55 | 57 |
56 void ReadingListModelFactory::RegisterBrowserStatePrefs( | 58 void ReadingListModelFactory::RegisterBrowserStatePrefs( |
57 user_prefs::PrefRegistrySyncable* registry) { | 59 user_prefs::PrefRegistrySyncable* registry) { |
58 registry->RegisterBooleanPref( | 60 registry->RegisterBooleanPref( |
59 reading_list::prefs::kReadingListHasUnseenEntries, false, | 61 reading_list::prefs::kReadingListHasUnseenEntries, false, |
60 PrefRegistry::NO_REGISTRATION_FLAGS); | 62 PrefRegistry::NO_REGISTRATION_FLAGS); |
61 } | 63 } |
62 | 64 |
63 std::unique_ptr<KeyedService> ReadingListModelFactory::BuildServiceInstanceFor( | 65 std::unique_ptr<KeyedService> ReadingListModelFactory::BuildServiceInstanceFor( |
64 web::BrowserState* context) const { | 66 web::BrowserState* context) const { |
65 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 67 ios::ChromeBrowserState* chrome_browser_state = |
66 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( | 68 ios::ChromeBrowserState::FromBrowserState(context); |
67 web::WebThread::GetBlockingPool()->GetSequenceToken()); | 69 browser_sync::ProfileSyncService* profile_sync_service = |
| 70 IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
| 71 chrome_browser_state); |
68 | 72 |
69 base::FilePath database_dir( | |
70 context->GetStatePath().Append(FILE_PATH_LITERAL("readinglist"))); | |
71 | |
72 // TODO(crbug.com/664920): use a shared location for the store. | |
73 std::unique_ptr<ReadingListStore> store = base::MakeUnique<ReadingListStore>( | 73 std::unique_ptr<ReadingListStore> store = base::MakeUnique<ReadingListStore>( |
74 base::Bind(&syncer::ModelTypeStore::CreateStore, syncer::READING_LIST, | 74 profile_sync_service->GetModelTypeStoreFactory(syncer::READING_LIST), |
75 database_dir.AsUTF8Unsafe(), background_task_runner), | |
76 base::Bind(&syncer::ModelTypeChangeProcessor::Create, | 75 base::Bind(&syncer::ModelTypeChangeProcessor::Create, |
77 base::BindRepeating(&syncer::ReportUnrecoverableError, | 76 base::BindRepeating(&syncer::ReportUnrecoverableError, |
78 GetChannel()))); | 77 GetChannel()))); |
79 | 78 |
80 ios::ChromeBrowserState* chrome_browser_state = | |
81 ios::ChromeBrowserState::FromBrowserState(context); | |
82 std::unique_ptr<KeyedService> reading_list_model = | 79 std::unique_ptr<KeyedService> reading_list_model = |
83 base::MakeUnique<ReadingListModelImpl>(std::move(store), | 80 base::MakeUnique<ReadingListModelImpl>(std::move(store), |
84 chrome_browser_state->GetPrefs()); | 81 chrome_browser_state->GetPrefs()); |
85 return reading_list_model; | 82 return reading_list_model; |
86 } | 83 } |
87 | 84 |
88 web::BrowserState* ReadingListModelFactory::GetBrowserStateToUse( | 85 web::BrowserState* ReadingListModelFactory::GetBrowserStateToUse( |
89 web::BrowserState* context) const { | 86 web::BrowserState* context) const { |
90 return GetBrowserStateRedirectedInIncognito(context); | 87 return GetBrowserStateRedirectedInIncognito(context); |
91 } | 88 } |
OLD | NEW |