Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: ios/chrome/browser/dom_distiller/distiller_viewer.h

Issue 2666643002: Remove usage of DomDistillerService in ReadingListDownloadService. (Closed)
Patch Set: missing JS Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_ 5 #ifndef IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_
6 #define IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_ 6 #define IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "components/dom_distiller/core/dom_distiller_request_view_base.h" 12 #include "components/dom_distiller/core/dom_distiller_request_view_base.h"
13 #include "components/dom_distiller/core/task_tracker.h" 13 #include "components/dom_distiller/core/task_tracker.h"
14 14
15 class GURL; 15 class GURL;
16 16
17 namespace dom_distiller { 17 namespace dom_distiller {
18 18
19 class DistilledPagePrefs; 19 class DistilledPagePrefs;
20 class Distiller;
20 21
21 // An interface for a dom_distiller ViewRequestDelegate that distills a URL and 22 // An interface for a dom_distiller ViewRequestDelegate that distills a URL and
22 // calls the given callback with the distilled HTML string and the images it 23 // calls the given callback with the distilled HTML string and the images it
23 // contains. 24 // contains.
24 class DistillerViewerInterface : public DomDistillerRequestViewBase { 25 class DistillerViewerInterface : public DomDistillerRequestViewBase {
25 public: 26 public:
26 struct ImageInfo { 27 struct ImageInfo {
27 // The url of the image. 28 // The url of the image.
28 GURL url; 29 GURL url;
29 // The image data as a string. 30 // The image data as a string.
30 std::string data; 31 std::string data;
31 }; 32 };
32 typedef base::Callback<void(const GURL& url, 33 typedef base::Callback<void(const GURL& url,
33 const std::string& html, 34 const std::string& html,
34 const std::vector<ImageInfo>& images, 35 const std::vector<ImageInfo>& images,
35 const std::string& title)> 36 const std::string& title)>
36 DistillationFinishedCallback; 37 DistillationFinishedCallback;
37 38
38 DistillerViewerInterface(dom_distiller::DomDistillerService* distillerService, 39 DistillerViewerInterface(PrefService* prefs)
39 PrefService* prefs)
40 : DomDistillerRequestViewBase(new DistilledPagePrefs(prefs)) {} 40 : DomDistillerRequestViewBase(new DistilledPagePrefs(prefs)) {}
41 ~DistillerViewerInterface() override {} 41 ~DistillerViewerInterface() override {}
42 42
43 void OnArticleReady( 43 void OnArticleReady(
44 const dom_distiller::DistilledArticleProto* article_proto) override = 0; 44 const dom_distiller::DistilledArticleProto* article_proto) override = 0;
45 45
46 void SendJavaScript(const std::string& buffer) override = 0; 46 void SendJavaScript(const std::string& buffer) override = 0;
47 47
48 DISALLOW_COPY_AND_ASSIGN(DistillerViewerInterface); 48 DISALLOW_COPY_AND_ASSIGN(DistillerViewerInterface);
49 }; 49 };
50 50
51 // A very simple and naive implementation of the DistillerViewer. 51 // A very simple and naive implementation of the DistillerViewer.
52 class DistillerViewer : public DistillerViewerInterface { 52 class DistillerViewer : public DistillerViewerInterface {
53 public: 53 public:
54 // Creates a |DistillerView| that will be used to distill |url|. 54 // Creates a |DistillerView| that will be used to distill |url|.
55 // If |page| is not null, it will be used to load |url| and inject the page.
56 // If |page| is null, the default factory of |distillerService| will be used.
57 // |callback| is called when distillation is finished with the protobuf 55 // |callback| is called when distillation is finished with the protobuf
58 // containing the distilled page. 56 // containing the distilled page.
59 DistillerViewer(dom_distiller::DomDistillerService* distillerService, 57 DistillerViewer(dom_distiller::DomDistillerService* distillerService,
jif 2017/01/31 10:07:53 I think this constructor is not used.
Olivier 2017/01/31 10:25:24 It is used in ReaderModeController below (even if
60 PrefService* prefs, 58 PrefService* prefs,
61 const GURL& url, 59 const GURL& url,
62 const DistillationFinishedCallback& callback, 60 const DistillationFinishedCallback& callback);
63 std::unique_ptr<dom_distiller::DistillerPage> page); 61
62 // Creates a |DistillerView| without depending on the DomDistillerService.
63 // Caller must provide |distiller_factory| and |page| which cannot be null.
64 // |callback| is called when distillation is finished with the protobuf
65 // containing the distilled page.
66 DistillerViewer(dom_distiller::DistillerFactory* distiller_factory,
67 std::unique_ptr<dom_distiller::DistillerPage> page,
68 PrefService* prefs,
69 const GURL& url,
70 const DistillationFinishedCallback& callback);
64 ~DistillerViewer() override; 71 ~DistillerViewer() override;
65 72
73 // Called by the distiller service when article is ready.
66 void OnArticleReady( 74 void OnArticleReady(
jif 2017/01/31 10:07:53 Can you add a "// DistillerViewerInterface impleme
Olivier 2017/01/31 10:25:24 Done.
67 const dom_distiller::DistilledArticleProto* article_proto) override; 75 const dom_distiller::DistilledArticleProto* article_proto) override;
68 76
77 // Called by the distiller when article is ready.
78 void OnDistillerFinished(
jif 2017/01/31 10:07:53 OnDistillerFinished and OnArticleDistillationUpdat
Olivier 2017/01/31 10:25:24 Done.
79 std::unique_ptr<dom_distiller::DistilledArticleProto> distilled_article);
80
81 // Called by the distiller when article is updated.
82 void OnArticleDistillationUpdated(
83 const dom_distiller::ArticleDistillationUpdate& article_update);
84
69 void SendJavaScript(const std::string& buffer) override; 85 void SendJavaScript(const std::string& buffer) override;
70 86
71 private: 87 private:
72 // The url of the distilled page. 88 // The url of the distilled page.
73 const GURL url_; 89 const GURL url_;
74 // JavaScript buffer. 90 // JavaScript buffer.
75 std::string js_buffer_; 91 std::string js_buffer_;
76 // Callback to run once distillation is complete. 92 // Callback to run once distillation is complete.
77 const DistillationFinishedCallback callback_; 93 const DistillationFinishedCallback callback_;
94 // Keep reference of the distiller_ during distillation.
95 std::unique_ptr<Distiller> distiller_;
78 96
79 DISALLOW_COPY_AND_ASSIGN(DistillerViewer); 97 DISALLOW_COPY_AND_ASSIGN(DistillerViewer);
80 }; 98 };
81 99
82 } // namespace dom_distiller 100 } // namespace dom_distiller
83 101
84 #endif // IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_ 102 #endif // IOS_CHROME_BROWSER_DOM_DISTILLER_DISTILLER_VIEWER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698