1 // Copyright 2014 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/dom_distiller/lazy_dom_distiller_service.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/dom_distiller/core/dom_distiller_service.h"
11 #include "content/public/browser/notification_source.h"
13 namespace dom_distiller
{
15 LazyDomDistillerService::LazyDomDistillerService(
17 const DomDistillerServiceFactory
* service_factory
)
18 : profile_(profile
), service_factory_(service_factory
) {
20 chrome::NOTIFICATION_PROFILE_DESTROYED
,
21 content::Source
<Profile
>(profile
));
24 LazyDomDistillerService::~LazyDomDistillerService() {
27 // This will create an object and schedule work the first time it's called
28 // and just return an existing object after that.
29 DomDistillerServiceInterface
* LazyDomDistillerService::instance() const {
30 return service_factory_
->GetForBrowserContext(profile_
);
33 void LazyDomDistillerService::Observe(
35 const content::NotificationSource
& source
,
36 const content::NotificationDetails
& details
) {
37 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED
, type
);
38 DCHECK_EQ(profile_
, content::Source
<Profile
>(source
).ptr());
42 syncer::SyncableService
* LazyDomDistillerService::GetSyncableService() const {
43 return instance()->GetSyncableService();
46 const std::string
LazyDomDistillerService::AddToList(
48 scoped_ptr
<DistillerPage
> distiller_page
,
49 const ArticleAvailableCallback
& article_cb
) {
50 return instance()->AddToList(url
, distiller_page
.Pass(), article_cb
);
53 std::vector
<ArticleEntry
> LazyDomDistillerService::GetEntries() const {
54 return instance()->GetEntries();
57 scoped_ptr
<ArticleEntry
> LazyDomDistillerService::RemoveEntry(
58 const std::string
& entry_id
) {
59 return instance()->RemoveEntry(entry_id
);
62 scoped_ptr
<ViewerHandle
> LazyDomDistillerService::ViewEntry(
63 ViewRequestDelegate
* delegate
,
64 scoped_ptr
<DistillerPage
> distiller_page
,
65 const std::string
& entry_id
) {
66 return instance()->ViewEntry(delegate
, distiller_page
.Pass(), entry_id
);
69 scoped_ptr
<ViewerHandle
> LazyDomDistillerService::ViewUrl(
70 ViewRequestDelegate
* delegate
,
71 scoped_ptr
<DistillerPage
> distiller_page
,
73 return instance()->ViewUrl(delegate
, distiller_page
.Pass(), url
);
76 scoped_ptr
<DistillerPage
>
77 LazyDomDistillerService::CreateDefaultDistillerPage() {
78 return instance()->CreateDefaultDistillerPage();
81 void LazyDomDistillerService::AddObserver(DomDistillerObserver
* observer
) {
82 instance()->AddObserver(observer
);
85 void LazyDomDistillerService::RemoveObserver(DomDistillerObserver
* observer
) {
86 instance()->RemoveObserver(observer
);
89 } // namespace dom_distiller