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() {}
26 // This will create an object and schedule work the first time it's called
27 // and just return an existing object after that.
28 DomDistillerServiceInterface* LazyDomDistillerService::instance() const {
29 return service_factory_->GetForBrowserContext(profile_);
32 void LazyDomDistillerService::Observe(
34 const content::NotificationSource& source,
35 const content::NotificationDetails& details) {
36 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
37 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
41 syncer::SyncableService* LazyDomDistillerService::GetSyncableService() const {
42 return instance()->GetSyncableService();
45 const std::string LazyDomDistillerService::AddToList(
47 const ArticleAvailableCallback& article_cb) {
48 return instance()->AddToList(url, article_cb);
51 std::vector<ArticleEntry> LazyDomDistillerService::GetEntries() const {
52 return instance()->GetEntries();
55 scoped_ptr<ArticleEntry> LazyDomDistillerService::RemoveEntry(
56 const std::string& entry_id) {
57 return instance()->RemoveEntry(entry_id);
60 scoped_ptr<ViewerHandle> LazyDomDistillerService::ViewEntry(
61 ViewRequestDelegate* delegate,
62 const std::string& entry_id) {
63 return instance()->ViewEntry(delegate, entry_id);
66 scoped_ptr<ViewerHandle> LazyDomDistillerService::ViewUrl(
67 ViewRequestDelegate* delegate,
69 return instance()->ViewUrl(delegate, url);
72 void LazyDomDistillerService::AddObserver(DomDistillerObserver* observer) {
73 instance()->AddObserver(observer);
76 void LazyDomDistillerService::RemoveObserver(DomDistillerObserver* observer) {
77 instance()->RemoveObserver(observer);
80 } // namespace dom_distiller