blob: 976689d33f0833f68ddee35dae8bcbb17030f5a2 [file] [log] [blame]
[email protected]7e856dde2014-03-15 00:34:051// 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#ifndef CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_
6#define CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_
7
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"
12
13namespace content {
14class NotificationSource;
15class NotificationDetails;
16} // namespace content
17
18class Profile;
19
20namespace dom_distiller {
21
22class DomDistillerServiceFactory;
23
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.
27class LazyDomDistillerService : public DomDistillerServiceInterface,
28 public content::NotificationObserver {
29 public:
30 LazyDomDistillerService(Profile* profile,
31 const DomDistillerServiceFactory* service_factory);
32 virtual ~LazyDomDistillerService();
33
34 public:
35 // DomDistillerServiceInterface implementation:
mostynb01d8b10e2014-10-13 09:44:4436 virtual syncer::SyncableService* GetSyncableService() const override;
[email protected]7e856dde2014-03-15 00:34:0537 virtual const std::string AddToList(
38 const GURL& url,
[email protected]2ea5fc12014-04-28 08:14:0139 scoped_ptr<DistillerPage> distiller_page,
mostynb01d8b10e2014-10-13 09:44:4440 const ArticleAvailableCallback& article_cb) override;
41 virtual bool HasEntry(const std::string& entry_id) override;
42 virtual std::string GetUrlForEntry(const std::string& entry_id) override;
43 virtual std::vector<ArticleEntry> GetEntries() const override;
[email protected]2ea5fc12014-04-28 08:14:0144 virtual scoped_ptr<ArticleEntry> RemoveEntry(
mostynb01d8b10e2014-10-13 09:44:4445 const std::string& entry_id) override;
[email protected]2ea5fc12014-04-28 08:14:0146 virtual scoped_ptr<ViewerHandle> ViewEntry(
47 ViewRequestDelegate* delegate,
48 scoped_ptr<DistillerPage> distiller_page,
mostynb01d8b10e2014-10-13 09:44:4449 const std::string& entry_id) override;
[email protected]2ea5fc12014-04-28 08:14:0150 virtual scoped_ptr<ViewerHandle> ViewUrl(
51 ViewRequestDelegate* delegate,
52 scoped_ptr<DistillerPage> distiller_page,
mostynb01d8b10e2014-10-13 09:44:4453 const GURL& url) override;
[email protected]2ba6b282014-07-18 14:26:1154 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage(
mostynb01d8b10e2014-10-13 09:44:4455 const gfx::Size& render_view_size) override;
[email protected]d289bd72014-05-28 01:24:1256 virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
mostynb01d8b10e2014-10-13 09:44:4457 scoped_ptr<SourcePageHandle> handle) override;
58 virtual void AddObserver(DomDistillerObserver* observer) override;
59 virtual void RemoveObserver(DomDistillerObserver* observer) override;
60 virtual DistilledPagePrefs* GetDistilledPagePrefs() override;
[email protected]7e856dde2014-03-15 00:34:0561
62 private:
63 // Accessor method for the backing service instance.
64 DomDistillerServiceInterface* instance() const;
65
66 // content::NotificationObserver implementation:
67 virtual void Observe(int type,
68 const content::NotificationSource& source,
mostynb01d8b10e2014-10-13 09:44:4469 const content::NotificationDetails& details) override;
[email protected]7e856dde2014-03-15 00:34:0570
71 // The Profile to use when retrieving the DomDistillerService and also the
72 // profile to listen for destruction of.
73 Profile* profile_;
74
75 // A BrowserContextKeyedServiceFactory for the DomDistillerService.
76 const DomDistillerServiceFactory* service_factory_;
77
78 // Used to track when the profile is shut down.
79 content::NotificationRegistrar registrar_;
80
81 DISALLOW_COPY_AND_ASSIGN(LazyDomDistillerService);
82};
83
84} // namespace dom_distiller
85
86#endif // CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_