[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 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 | |
dcheng | c0e39d57 | 2016-04-19 06:15:17 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 11 | #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 | |
| 16 | namespace content { |
| 17 | class NotificationSource; |
| 18 | class NotificationDetails; |
| 19 | } // namespace content |
| 20 | |
| 21 | class Profile; |
| 22 | |
| 23 | namespace dom_distiller { |
| 24 | |
| 25 | class 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. |
| 30 | class LazyDomDistillerService : public DomDistillerServiceInterface, |
| 31 | public content::NotificationObserver { |
| 32 | public: |
| 33 | LazyDomDistillerService(Profile* profile, |
| 34 | const DomDistillerServiceFactory* service_factory); |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 35 | ~LazyDomDistillerService() override; |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 36 | |
| 37 | public: |
| 38 | // DomDistillerServiceInterface implementation: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 39 | bool HasEntry(const std::string& entry_id) override; |
| 40 | std::string GetUrlForEntry(const std::string& entry_id) override; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 41 | 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( |
mostynb | 01d8b10e | 2014-10-13 09:44:44 | [diff] [blame] | 50 | const gfx::Size& render_view_size) override; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 51 | std::unique_ptr<DistillerPage> CreateDefaultDistillerPageWithHandle( |
| 52 | std::unique_ptr<SourcePageHandle> handle) override; |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 53 | DistilledPagePrefs* GetDistilledPagePrefs() override; |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | // Accessor method for the backing service instance. |
| 57 | DomDistillerServiceInterface* instance() const; |
| 58 | |
| 59 | // content::NotificationObserver implementation: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 60 | void Observe(int type, |
| 61 | const content::NotificationSource& source, |
| 62 | const content::NotificationDetails& details) override; |
[email protected] | 7e856dde | 2014-03-15 00:34:05 | [diff] [blame] | 63 | |
| 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_ |