blob: a7adba33b4be456c34b3039fddd985499407a807 [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
dchengc0e39d572016-04-19 06:15:178#include <memory>
9
avie4d7b6f2015-12-26 00:59:1810#include "base/macros.h"
[email protected]7e856dde2014-03-15 00:34:0511#include "components/dom_distiller/core/dom_distiller_service.h"
12#include "components/dom_distiller/core/task_tracker.h"
13#include "content/public/browser/notification_observer.h"
14#include "content/public/browser/notification_registrar.h"
15
16namespace content {
17class NotificationSource;
18class NotificationDetails;
19} // namespace content
20
21class Profile;
22
23namespace dom_distiller {
24
25class DomDistillerServiceFactory;
26
27// A class which helps with lazy instantiation of the DomDistillerService, using
28// the BrowserContextKeyedServiceFactory for it. This class will delete itself
29// when the profile is destroyed.
30class LazyDomDistillerService : public DomDistillerServiceInterface,
31 public content::NotificationObserver {
32 public:
33 LazyDomDistillerService(Profile* profile,
34 const DomDistillerServiceFactory* service_factory);
Daniel Chenga542fca2014-10-21 09:51:2935 ~LazyDomDistillerService() override;
[email protected]7e856dde2014-03-15 00:34:0536
37 public:
38 // DomDistillerServiceInterface implementation:
Daniel Chenga542fca2014-10-21 09:51:2939 bool HasEntry(const std::string& entry_id) override;
40 std::string GetUrlForEntry(const std::string& entry_id) override;
dcheng4af48582016-04-19 00:29:3541 std::unique_ptr<ViewerHandle> ViewEntry(
42 ViewRequestDelegate* delegate,
43 std::unique_ptr<DistillerPage> distiller_page,
44 const std::string& entry_id) override;
45 std::unique_ptr<ViewerHandle> ViewUrl(
46 ViewRequestDelegate* delegate,
47 std::unique_ptr<DistillerPage> distiller_page,
48 const GURL& url) override;
49 std::unique_ptr<DistillerPage> CreateDefaultDistillerPage(
mostynb01d8b10e2014-10-13 09:44:4450 const gfx::Size& render_view_size) override;
dcheng4af48582016-04-19 00:29:3551 std::unique_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle(
52 std::unique_ptr<SourcePageHandle> handle) override;
Daniel Chenga542fca2014-10-21 09:51:2953 DistilledPagePrefs* GetDistilledPagePrefs() override;
[email protected]7e856dde2014-03-15 00:34:0554
55 private:
56 // Accessor method for the backing service instance.
57 DomDistillerServiceInterface* instance() const;
58
59 // content::NotificationObserver implementation:
Daniel Chenga542fca2014-10-21 09:51:2960 void Observe(int type,
61 const content::NotificationSource& source,
62 const content::NotificationDetails& details) override;
[email protected]7e856dde2014-03-15 00:34:0563
64 // The Profile to use when retrieving the DomDistillerService and also the
65 // profile to listen for destruction of.
66 Profile* profile_;
67
68 // A BrowserContextKeyedServiceFactory for the DomDistillerService.
69 const DomDistillerServiceFactory* service_factory_;
70
71 // Used to track when the profile is shut down.
72 content::NotificationRegistrar registrar_;
73
74 DISALLOW_COPY_AND_ASSIGN(LazyDomDistillerService);
75};
76
77} // namespace dom_distiller
78
79#endif // CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_