Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_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/singleton.h" | 11 #include "base/memory/singleton.h" |
| 11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 12 #include "chrome/browser/profiles/incognito_helpers.h" | 13 #include "chrome/browser/profiles/incognito_helpers.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/offline_pages/offline_page_metadata_store_sql.h" | 17 #include "components/offline_pages/offline_page_metadata_store_sql.h" |
| 17 #include "components/offline_pages/offline_page_model_impl.h" | 18 #include "components/offline_pages/offline_page_model_impl.h" |
| 19 #include "components/offline_pages/stub_offline_page_model.h" | |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 | 21 |
| 22 namespace { | |
| 23 std::unique_ptr<KeyedService> BuildMockOfflinePageModelFactory( | |
|
fgorski
2016/09/08 17:18:57
how about moving this to testing_profile and appro
| |
| 24 content::BrowserContext* context) { | |
| 25 return base::MakeUnique<offline_pages::StubOfflinePageModel>(); | |
| 26 } | |
| 27 } | |
| 28 | |
| 20 namespace offline_pages { | 29 namespace offline_pages { |
| 21 | 30 |
| 22 OfflinePageModelFactory::OfflinePageModelFactory() | 31 OfflinePageModelFactory::OfflinePageModelFactory() |
| 23 : BrowserContextKeyedServiceFactory( | 32 : BrowserContextKeyedServiceFactory( |
| 24 "OfflinePageModel", | 33 "OfflinePageModel", |
| 25 BrowserContextDependencyManager::GetInstance()) { | 34 BrowserContextDependencyManager::GetInstance()) { |
| 26 } | 35 } |
| 27 | 36 |
| 28 // static | 37 // static |
| 29 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { | 38 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { |
| 30 return base::Singleton<OfflinePageModelFactory>::get(); | 39 return base::Singleton<OfflinePageModelFactory>::get(); |
| 31 } | 40 } |
| 32 | 41 |
| 33 // static | 42 // static |
| 34 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( | 43 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( |
| 35 content::BrowserContext* context) { | 44 content::BrowserContext* context) { |
| 36 return static_cast<OfflinePageModelImpl*>( | 45 return static_cast<OfflinePageModelImpl*>( |
| 37 GetInstance()->GetServiceForBrowserContext(context, true)); | 46 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 38 } | 47 } |
| 39 | 48 |
| 49 // static | |
| 50 BrowserContextKeyedServiceFactory::TestingFactoryFunction | |
| 51 OfflinePageModelFactory::GetMockFactory() { | |
| 52 return &BuildMockOfflinePageModelFactory; | |
| 53 } | |
| 54 | |
| 40 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( | 55 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( |
| 41 content::BrowserContext* context) const { | 56 content::BrowserContext* context) const { |
| 42 Profile* profile = Profile::FromBrowserContext(context); | 57 Profile* profile = Profile::FromBrowserContext(context); |
| 43 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 44 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 59 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 45 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 60 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 46 | 61 |
| 47 base::FilePath store_path = | 62 base::FilePath store_path = |
| 48 profile->GetPath().Append(chrome::kOfflinePageMetadataDirname); | 63 profile->GetPath().Append(chrome::kOfflinePageMetadataDirname); |
| 49 std::unique_ptr<OfflinePageMetadataStore> metadata_store( | 64 std::unique_ptr<OfflinePageMetadataStore> metadata_store( |
| 50 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); | 65 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); |
| 51 | 66 |
| 52 base::FilePath archives_dir = | 67 base::FilePath archives_dir = |
| 53 profile->GetPath().Append(chrome::kOfflinePageArchivesDirname); | 68 profile->GetPath().Append(chrome::kOfflinePageArchivesDirname); |
| 54 | 69 |
| 55 return new OfflinePageModelImpl(std::move(metadata_store), archives_dir, | 70 return new OfflinePageModelImpl(std::move(metadata_store), archives_dir, |
| 56 background_task_runner); | 71 background_task_runner); |
| 57 } | 72 } |
| 58 | 73 |
| 59 } // namespace offline_pages | 74 } // namespace offline_pages |
| OLD | NEW |