| 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/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/path_service.h" |
| 11 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 12 #include "base/task_scheduler/post_task.h" | 13 #include "base/task_scheduler/post_task.h" |
| 13 #include "chrome/browser/profiles/incognito_helpers.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 #include "components/offline_pages/core/archive_manager.h" |
| 17 #include "components/offline_pages/core/offline_page_client_policy.h" |
| 17 #include "components/offline_pages/core/offline_page_metadata_store_sql.h" | 18 #include "components/offline_pages/core/offline_page_metadata_store_sql.h" |
| 18 #include "components/offline_pages/core/offline_page_model_impl.h" | 19 #include "components/offline_pages/core/offline_page_model_impl.h" |
| 20 #include "content/public/browser/browser_context.h" |
| 19 | 21 |
| 20 namespace offline_pages { | 22 namespace offline_pages { |
| 21 | 23 |
| 24 using LifetimeType = LifetimePolicy::LifetimeType; |
| 25 |
| 22 OfflinePageModelFactory::OfflinePageModelFactory() | 26 OfflinePageModelFactory::OfflinePageModelFactory() |
| 23 : BrowserContextKeyedServiceFactory( | 27 : BrowserContextKeyedServiceFactory( |
| 24 "OfflinePageModel", | 28 "OfflinePageModel", |
| 25 BrowserContextDependencyManager::GetInstance()) { | 29 BrowserContextDependencyManager::GetInstance()) { |
| 26 } | 30 } |
| 27 | 31 |
| 28 // static | 32 // static |
| 29 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { | 33 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { |
| 30 return base::Singleton<OfflinePageModelFactory>::get(); | 34 return base::Singleton<OfflinePageModelFactory>::get(); |
| 31 } | 35 } |
| 32 | 36 |
| 33 // static | 37 // static |
| 34 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( | 38 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( |
| 35 content::BrowserContext* context) { | 39 content::BrowserContext* context) { |
| 36 return static_cast<OfflinePageModelImpl*>( | 40 return static_cast<OfflinePageModelImpl*>( |
| 37 GetInstance()->GetServiceForBrowserContext(context, true)); | 41 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 38 } | 42 } |
| 39 | 43 |
| 40 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( | 44 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( |
| 41 content::BrowserContext* context) const { | 45 content::BrowserContext* context) const { |
| 42 Profile* profile = Profile::FromBrowserContext(context); | |
| 43 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 46 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 44 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}); | 47 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}); |
| 45 | 48 |
| 46 base::FilePath store_path = | 49 base::FilePath store_path = |
| 47 profile->GetPath().Append(chrome::kOfflinePageMetadataDirname); | 50 context->GetPath().Append(chrome::kOfflinePageMetadataDirname); |
| 48 std::unique_ptr<OfflinePageMetadataStore> metadata_store( | 51 std::unique_ptr<OfflinePageMetadataStore> metadata_store( |
| 49 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); | 52 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); |
| 50 | 53 |
| 51 base::FilePath archives_dir = | 54 base::FilePath persistent_archives_dir = |
| 52 profile->GetPath().Append(chrome::kOfflinePageArchivesDirname); | 55 context->GetPath().Append(chrome::kOfflinePageArchivesDirname); |
| 56 base::FilePath temporary_archives_dir; |
| 57 if (!PathService::Get(base::DIR_CACHE, &temporary_archives_dir)) |
| 58 NOTREACHED(); |
| 59 temporary_archives_dir = |
| 60 temporary_archives_dir.Append(chrome::kOfflinePageArchivesDirname); |
| 61 ArchiveDirectories archive_directories; |
| 62 archive_directories[LifetimeType::TEMPORARY] = temporary_archives_dir; |
| 63 archive_directories[LifetimeType::PERSISTENT] = persistent_archives_dir; |
| 53 | 64 |
| 54 return new OfflinePageModelImpl(std::move(metadata_store), archives_dir, | 65 return new OfflinePageModelImpl(std::move(metadata_store), |
| 55 background_task_runner); | 66 archive_directories, background_task_runner); |
| 56 } | 67 } |
| 57 | 68 |
| 58 } // namespace offline_pages | 69 } // namespace offline_pages |
| OLD | NEW |