forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Offline pages] Adding OfflinePageModelFactory
BUG=491352 Review URL: https://codereview.chromium.org/1231013003 Cr-Commit-Position: refs/heads/master@{#339485}
- Loading branch information
Showing
9 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
chrome/browser/android/offline_pages/offline_page_model_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/memory/singleton.h" | ||
#include "base/path_service.h" | ||
#include "base/sequenced_task_runner.h" | ||
#include "chrome/browser/offline_pages/offline_page_metadata_store_impl.h" | ||
#include "chrome/browser/offline_pages/offline_pages.pb.h" | ||
#include "chrome/browser/profiles/incognito_helpers.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/common/chrome_paths.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
#include "components/leveldb_proto/proto_database_impl.h" | ||
#include "components/offline_pages/offline_page_model.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
namespace offline_pages { | ||
|
||
OfflinePageModelFactory::OfflinePageModelFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"OfflinePageModel", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
} | ||
|
||
// static | ||
OfflinePageModelFactory* OfflinePageModelFactory::GetInstance() { | ||
return Singleton<OfflinePageModelFactory>::get(); | ||
} | ||
|
||
// static | ||
OfflinePageModel* OfflinePageModelFactory::GetForBrowserContext( | ||
content::BrowserContext* context) { | ||
if (context->IsOffTheRecord()) | ||
return nullptr; | ||
|
||
return static_cast<OfflinePageModel*>( | ||
GetInstance()->GetServiceForBrowserContext(context, true)); | ||
} | ||
|
||
KeyedService* OfflinePageModelFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
DCHECK(!context->IsOffTheRecord()); | ||
|
||
scoped_refptr<base::SequencedTaskRunner> background_task_runner = | ||
content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | ||
content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | ||
|
||
scoped_ptr<leveldb_proto::ProtoDatabaseImpl<OfflinePageEntry>> database( | ||
new leveldb_proto::ProtoDatabaseImpl<OfflinePageEntry>( | ||
background_task_runner)); | ||
|
||
base::FilePath store_path; | ||
CHECK(PathService::Get(chrome::DIR_OFFLINE_PAGE_METADATA, &store_path)); | ||
scoped_ptr<OfflinePageMetadataStoreImpl> metadata_store( | ||
new OfflinePageMetadataStoreImpl(database.Pass(), store_path)); | ||
|
||
return new OfflinePageModel(metadata_store.Pass(), background_task_runner); | ||
} | ||
|
||
content::BrowserContext* OfflinePageModelFactory::GetBrowserContextToUse( | ||
content::BrowserContext* context) const { | ||
return chrome::GetBrowserContextRedirectedInIncognito(context); | ||
} | ||
|
||
} // namespace offline_pages | ||
|
42 changes: 42 additions & 0 deletions
42
chrome/browser/android/offline_pages/offline_page_model_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_FACTORY_H_ | ||
#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_FACTORY_H_ | ||
|
||
#include "base/macros.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
template <typename T> | ||
struct DefaultSingletonTraits; | ||
|
||
namespace offline_pages { | ||
|
||
class OfflinePageModel; | ||
|
||
// A factory to create one unique OfflinePageModel. | ||
class OfflinePageModelFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static OfflinePageModelFactory* GetInstance(); | ||
static OfflinePageModel* GetForBrowserContext( | ||
content::BrowserContext* context); | ||
|
||
private: | ||
friend struct DefaultSingletonTraits<OfflinePageModelFactory>; | ||
|
||
OfflinePageModelFactory(); | ||
~OfflinePageModelFactory() override {} | ||
|
||
KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* context) const override; | ||
|
||
content::BrowserContext* GetBrowserContextToUse( | ||
content::BrowserContext* context) const override; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(OfflinePageModelFactory); | ||
}; | ||
|
||
} // namespace offline_pages | ||
|
||
#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_MODEL_FACTORY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters