Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / dom_distiller / lazy_dom_distiller_service.h
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 #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
13 namespace content {
14 class NotificationSource;
15 class NotificationDetails;
16 }  // namespace content
17
18 class Profile;
19
20 namespace dom_distiller {
21
22 class 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.
27 class 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:
36   virtual syncer::SyncableService* GetSyncableService() const OVERRIDE;
37   virtual const std::string AddToList(
38       const GURL& url,
39       scoped_ptr<DistillerPage> distiller_page,
40       const ArticleAvailableCallback& article_cb) OVERRIDE;
41   virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;
42   virtual scoped_ptr<ArticleEntry> RemoveEntry(
43       const std::string& entry_id) OVERRIDE;
44   virtual scoped_ptr<ViewerHandle> ViewEntry(
45       ViewRequestDelegate* delegate,
46       scoped_ptr<DistillerPage> distiller_page,
47       const std::string& entry_id) OVERRIDE;
48   virtual scoped_ptr<ViewerHandle> ViewUrl(
49       ViewRequestDelegate* delegate,
50       scoped_ptr<DistillerPage> distiller_page,
51       const GURL& url) OVERRIDE;
52   virtual scoped_ptr<DistillerPage> CreateDefaultDistillerPage() OVERRIDE;
53   virtual void AddObserver(DomDistillerObserver* observer) OVERRIDE;
54   virtual void RemoveObserver(DomDistillerObserver* observer) OVERRIDE;
55
56  private:
57   // Accessor method for the backing service instance.
58   DomDistillerServiceInterface* instance() const;
59
60   // content::NotificationObserver implementation:
61   virtual void Observe(int type,
62                        const content::NotificationSource& source,
63                        const content::NotificationDetails& details) OVERRIDE;
64
65   // The Profile to use when retrieving the DomDistillerService and also the
66   // profile to listen for destruction of.
67   Profile* profile_;
68
69   // A BrowserContextKeyedServiceFactory for the DomDistillerService.
70   const DomDistillerServiceFactory* service_factory_;
71
72   // Used to track when the profile is shut down.
73   content::NotificationRegistrar registrar_;
74
75   DISALLOW_COPY_AND_ASSIGN(LazyDomDistillerService);
76 };
77
78 }  // namespace dom_distiller
79
80 #endif  // CHROME_BROWSER_DOM_DISTILLER_LAZY_DOM_DISTILLER_SERVICE_H_