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 #ifndef CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_
6 #define CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_
8 #include "components/dom_distiller/core/dom_distiller_service.h"
9 #include "components/dom_distiller/core/task_tracker.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
14 class NotificationSource
;
15 class NotificationDetails
;
16 } // namespace content
20 namespace dom_distiller
{
22 class DomDistillerServiceFactory
;
24 // A class which helps with lazy instantiation of the DomDistillerService, using
25 // the BrowserContextKeyedServiceFactory for it. This class will delete itself
26 // when the profile is destroyed.
27 class LazyDomDistillerService
: public DomDistillerServiceInterface
,
28 public content::NotificationObserver
{
30 LazyDomDistillerService(Profile
* profile
,
31 const DomDistillerServiceFactory
* service_factory
);
32 ~LazyDomDistillerService() override
;
35 // DomDistillerServiceInterface implementation:
36 syncer::SyncableService
* GetSyncableService() const override
;
37 const std::string
AddToList(
39 scoped_ptr
<DistillerPage
> distiller_page
,
40 const ArticleAvailableCallback
& article_cb
) override
;
41 bool HasEntry(const std::string
& entry_id
) override
;
42 std::string
GetUrlForEntry(const std::string
& entry_id
) override
;
43 std::vector
<ArticleEntry
> GetEntries() const override
;
44 scoped_ptr
<ArticleEntry
> RemoveEntry(const std::string
& entry_id
) override
;
45 scoped_ptr
<ViewerHandle
> ViewEntry(ViewRequestDelegate
* delegate
,
46 scoped_ptr
<DistillerPage
> distiller_page
,
47 const std::string
& entry_id
) override
;
48 scoped_ptr
<ViewerHandle
> ViewUrl(ViewRequestDelegate
* delegate
,
49 scoped_ptr
<DistillerPage
> distiller_page
,
50 const GURL
& url
) override
;
51 scoped_ptr
<DistillerPage
> CreateDefaultDistillerPage(
52 const gfx::Size
& render_view_size
) override
;
53 scoped_ptr
<DistillerPage
> CreateDefaultDistillerPageWithHandle(
54 scoped_ptr
<SourcePageHandle
> handle
) override
;
55 void AddObserver(DomDistillerObserver
* observer
) override
;
56 void RemoveObserver(DomDistillerObserver
* observer
) override
;
57 DistilledPagePrefs
* GetDistilledPagePrefs() override
;
60 // Accessor method for the backing service instance.
61 DomDistillerServiceInterface
* instance() const;
63 // content::NotificationObserver implementation:
64 void Observe(int type
,
65 const content::NotificationSource
& source
,
66 const content::NotificationDetails
& details
) override
;
68 // The Profile to use when retrieving the DomDistillerService and also the
69 // profile to listen for destruction of.
72 // A BrowserContextKeyedServiceFactory for the DomDistillerService.
73 const DomDistillerServiceFactory
* service_factory_
;
75 // Used to track when the profile is shut down.
76 content::NotificationRegistrar registrar_
;
78 DISALLOW_COPY_AND_ASSIGN(LazyDomDistillerService
);
81 } // namespace dom_distiller
83 #endif // CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_