Upstream version 6.35.121.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 // 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_);
30 }
31
32 void LazyDomDistillerService::Observe(
33     int type,
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());
38   delete this;
39 }
40
41 syncer::SyncableService* LazyDomDistillerService::GetSyncableService() const {
42   return instance()->GetSyncableService();
43 }
44
45 const std::string LazyDomDistillerService::AddToList(
46     const GURL& url,
47     const ArticleAvailableCallback& article_cb) {
48   return instance()->AddToList(url, article_cb);
49 }
50
51 std::vector<ArticleEntry> LazyDomDistillerService::GetEntries() const {
52   return instance()->GetEntries();
53 }
54
55 scoped_ptr<ArticleEntry> LazyDomDistillerService::RemoveEntry(
56     const std::string& entry_id) {
57   return instance()->RemoveEntry(entry_id);
58 }
59
60 scoped_ptr<ViewerHandle> LazyDomDistillerService::ViewEntry(
61     ViewRequestDelegate* delegate,
62     const std::string& entry_id) {
63   return instance()->ViewEntry(delegate, entry_id);
64 }
65
66 scoped_ptr<ViewerHandle> LazyDomDistillerService::ViewUrl(
67     ViewRequestDelegate* delegate,
68     const GURL& url) {
69   return instance()->ViewUrl(delegate, url);
70 }
71
72 void LazyDomDistillerService::AddObserver(DomDistillerObserver* observer) {
73   instance()->AddObserver(observer);
74 }
75
76 void LazyDomDistillerService::RemoveObserver(DomDistillerObserver* observer) {
77   instance()->RemoveObserver(observer);
78 }
79
80 }  // namespace dom_distiller