Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / android / offline_pages / offline_page_model_factory.cc
blob5c55b34612cc62a73e4364e5313eab84553739a3
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
3 // found in the LICENSE file.
5 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/singleton.h"
9 #include "base/path_service.h"
10 #include "base/sequenced_task_runner.h"
11 #include "chrome/browser/profiles/incognito_helpers.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/leveldb_proto/proto_database_impl.h"
16 #include "components/offline_pages/offline_page_metadata_store_impl.h"
17 #include "components/offline_pages/offline_page_model.h"
18 #include "components/offline_pages/proto/offline_pages.pb.h"
19 #include "content/public/browser/browser_thread.h"
21 namespace offline_pages {
23 OfflinePageModelFactory::OfflinePageModelFactory()
24 : BrowserContextKeyedServiceFactory(
25 "OfflinePageModel",
26 BrowserContextDependencyManager::GetInstance()) {
29 // static
30 OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() {
31 return Singleton<OfflinePageModelFactory>::get();
34 // static
35 OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext(
36 content::BrowserContext* context) {
37 if (context->IsOffTheRecord())
38 return nullptr;
40 return static_cast<OfflinePageModel*>(
41 GetInstance()->GetServiceForBrowserContext(context, true));
44 KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor(
45 content::BrowserContext* context) const {
46 DCHECK(!context->IsOffTheRecord());
48 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
49 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
50 content::BrowserThread::GetBlockingPool()->GetSequenceToken());
52 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<OfflinePageEntry>> database(
53 new leveldb_proto::ProtoDatabaseImpl<OfflinePageEntry>(
54 background_task_runner));
56 base::FilePath store_path;
57 CHECK(PathService::Get(chrome::DIR_OFFLINE_PAGE_METADATA, &store_path));
58 scoped_ptr<OfflinePageMetadataStoreImpl> metadata_store(
59 new OfflinePageMetadataStoreImpl(database.Pass(), store_path));
61 return new OfflinePageModel(metadata_store.Pass(), background_task_runner);
64 content::BrowserContext* OfflinePageModelFactory::GetBrowserContextToUse(
65 content::BrowserContext* context) const {
66 return chrome::GetBrowserContextRedirectedInIncognito(context);
69 } // namespace offline_pages