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/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/task_scheduler/post_task.h" |
13 #include "chrome/browser/profiles/incognito_helpers.h" | 13 #include "chrome/browser/profiles/incognito_helpers.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
16 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
17 #include "components/offline_pages/core/offline_page_metadata_store_sql.h" | 17 #include "components/offline_pages/core/offline_page_metadata_store_sql.h" |
18 #include "components/offline_pages/core/offline_page_model_impl.h" | 18 #include "components/offline_pages/core/offline_page_model_impl.h" |
19 #include "content/public/browser/browser_thread.h" | |
20 | 19 |
21 namespace offline_pages { | 20 namespace offline_pages { |
22 | 21 |
23 OfflinePageModelFactory::OfflinePageModelFactory() | 22 OfflinePageModelFactory::OfflinePageModelFactory() |
24 : BrowserContextKeyedServiceFactory( | 23 : BrowserContextKeyedServiceFactory( |
25 "OfflinePageModel", | 24 "OfflinePageModel", |
26 BrowserContextDependencyManager::GetInstance()) { | 25 BrowserContextDependencyManager::GetInstance()) { |
27 } | 26 } |
28 | 27 |
29 // static | 28 // static |
30 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { | 29 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { |
31 return base::Singleton<OfflinePageModelFactory>::get(); | 30 return base::Singleton<OfflinePageModelFactory>::get(); |
32 } | 31 } |
33 | 32 |
34 // static | 33 // static |
35 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( | 34 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( |
36 content::BrowserContext* context) { | 35 content::BrowserContext* context) { |
37 return static_cast<OfflinePageModelImpl*>( | 36 return static_cast<OfflinePageModelImpl*>( |
38 GetInstance()->GetServiceForBrowserContext(context, true)); | 37 GetInstance()->GetServiceForBrowserContext(context, true)); |
39 } | 38 } |
40 | 39 |
41 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( | 40 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( |
42 content::BrowserContext* context) const { | 41 content::BrowserContext* context) const { |
43 Profile* profile = Profile::FromBrowserContext(context); | 42 Profile* profile = Profile::FromBrowserContext(context); |
44 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 43 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
45 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 44 base::CreateSequencedTaskRunnerWithTraits( |
46 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 45 base::TaskTraits().MayBlock().WithPriority( |
46 base::TaskPriority::BACKGROUND)); | |
dewittj
2017/04/24 18:44:11
The tasks on this task runner will sometimes be us
fdoray
2017/04/26 19:33:06
Switched to no explicit priority. Priority will be
| |
47 | 47 |
48 base::FilePath store_path = | 48 base::FilePath store_path = |
49 profile->GetPath().Append(chrome::kOfflinePageMetadataDirname); | 49 profile->GetPath().Append(chrome::kOfflinePageMetadataDirname); |
50 std::unique_ptr<OfflinePageMetadataStore> metadata_store( | 50 std::unique_ptr<OfflinePageMetadataStore> metadata_store( |
51 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); | 51 new OfflinePageMetadataStoreSQL(background_task_runner, store_path)); |
52 | 52 |
53 base::FilePath archives_dir = | 53 base::FilePath archives_dir = |
54 profile->GetPath().Append(chrome::kOfflinePageArchivesDirname); | 54 profile->GetPath().Append(chrome::kOfflinePageArchivesDirname); |
55 | 55 |
56 return new OfflinePageModelImpl(std::move(metadata_store), archives_dir, | 56 return new OfflinePageModelImpl(std::move(metadata_store), archives_dir, |
57 background_task_runner); | 57 background_task_runner); |
58 } | 58 } |
59 | 59 |
60 } // namespace offline_pages | 60 } // namespace offline_pages |
OLD | NEW |