Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / dom_distiller / lazy_dom_distiller_service.cc
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.
4
5 #include "chrome/browser/dom_distiller/lazy_dom_distiller_service.h"
6
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"
12
13 namespace dom_distiller {
14
15 LazyDomDistillerService::LazyDomDistillerService(
16     Profile* profile,
17     const DomDistillerServiceFactory* service_factory)
18     : profile_(profile), service_factory_(service_factory) {
19   registrar_.Add(this,
20                  chrome::NOTIFICATION_PROFILE_DESTROYED,
21                  content::Source<Profile>(profile));
22 }
23
24 LazyDomDistillerService::~LazyDomDistillerService() {
25 }
26
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_);
31 }
32
33 void LazyDomDistillerService::Observe(
34     int type,
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());
39   delete this;
40 }
41
42 syncer::SyncableService* LazyDomDistillerService::GetSyncableService() const {
43   return instance()->GetSyncableService();
44 }
45
46 const std::string LazyDomDistillerService::AddToList(
47     const GURL& url,
48     scoped_ptr<DistillerPage> distiller_page,
49     const ArticleAvailableCallback& article_cb) {
50   return instance()->AddToList(url, distiller_page.Pass(), article_cb);
51 }
52
53 std::vector<ArticleEntry> LazyDomDistillerService::GetEntries() const {
54   return instance()->GetEntries();
55 }
56
57 scoped_ptr<ArticleEntry> LazyDomDistillerService::RemoveEntry(
58     const std::string& entry_id) {
59   return instance()->RemoveEntry(entry_id);
60 }
61
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);
67 }
68
69 scoped_ptr<ViewerHandle> LazyDomDistillerService::ViewUrl(
70     ViewRequestDelegate* delegate,
71     scoped_ptr<DistillerPage> distiller_page,
72     const GURL& url) {
73   return instance()->ViewUrl(delegate, distiller_page.Pass(), url);
74 }
75
76 scoped_ptr<DistillerPage>
77 LazyDomDistillerService::CreateDefaultDistillerPage() {
78   return instance()->CreateDefaultDistillerPage();
79 }
80
81 void LazyDomDistillerService::AddObserver(DomDistillerObserver* observer) {
82   instance()->AddObserver(observer);
83 }
84
85 void LazyDomDistillerService::RemoveObserver(DomDistillerObserver* observer) {
86   instance()->RemoveObserver(observer);
87 }
88
89 }  // namespace dom_distiller