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

Side by Side Diff: components/dom_distiller/core/task_tracker.h

Issue 146843010: Add support for multipage distillation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_
6 #define COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ 6 #define COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "components/dom_distiller/core/article_entry.h" 14 #include "components/dom_distiller/core/article_entry.h"
15 #include "components/dom_distiller/core/distiller.h" 15 #include "components/dom_distiller/core/distiller.h"
16 #include "components/dom_distiller/core/proto/distilled_page.pb.h" 16 #include "components/dom_distiller/core/proto/distilled_page.pb.h"
17 17
18 class GURL; 18 class GURL;
19 19
20 namespace dom_distiller { 20 namespace dom_distiller {
21 21
22 class DistilledPageProto; 22 class DistilledArticleProto;
23 23
24 // A handle to a request to view a DOM distiller entry or URL. The request will 24 // A handle to a request to view a DOM distiller entry or URL. The request will
25 // be cancelled when the handle is destroyed. 25 // be cancelled when the handle is destroyed.
26 class ViewerHandle { 26 class ViewerHandle {
27 typedef base::Callback<void()> CancelCallback; 27 typedef base::Callback<void()> CancelCallback;
28 28
29 public: 29 public:
30 explicit ViewerHandle(CancelCallback callback); 30 explicit ViewerHandle(CancelCallback callback);
31 ~ViewerHandle(); 31 ~ViewerHandle();
32 32
33 private: 33 private:
34 CancelCallback cancel_callback_; 34 CancelCallback cancel_callback_;
35 DISALLOW_COPY_AND_ASSIGN(ViewerHandle); 35 DISALLOW_COPY_AND_ASSIGN(ViewerHandle);
36 }; 36 };
37 37
38 // Interface for a DOM distiller entry viewer. Implement this to make a view 38 // Interface for a DOM distiller entry viewer. Implement this to make a view
39 // request and receive the data for an entry when it becomes available. 39 // request and receive the data for an entry when it becomes available.
40 class ViewRequestDelegate { 40 class ViewRequestDelegate {
41 public: 41 public:
42 virtual ~ViewRequestDelegate() {} 42 virtual ~ViewRequestDelegate() {}
43 // Called when the distilled article contents are available. The 43 // Called when the distilled article contents are available. The
44 // DistilledPageProto is owned by a TaskTracker instance and is invalidated 44 // DistilledArticleProto is owned by a TaskTracker instance and is invalidated
45 // when the corresponding ViewerHandle is destroyed (or when the 45 // when the corresponding ViewerHandle is destroyed (or when the
46 // DomDistillerService is destroyed). 46 // DomDistillerService is destroyed).
47 virtual void OnArticleReady(DistilledPageProto* proto) = 0; 47 virtual void OnArticleReady(const DistilledArticleProto* article_proto) = 0;
48 }; 48 };
49 49
50 // A TaskTracker manages the various tasks related to viewing, saving, 50 // A TaskTracker manages the various tasks related to viewing, saving,
51 // distilling, and fetching an article's distilled content. 51 // distilling, and fetching an article's distilled content.
52 // 52 //
53 // There are two sources of distilled content, a Distiller and the BlobFetcher. 53 // There are two sources of distilled content, a Distiller and the BlobFetcher.
54 // At any time, at most one of each of these will be in-progress (if one 54 // At any time, at most one of each of these will be in-progress (if one
55 // finishes, the other will be cancelled). 55 // finishes, the other will be cancelled).
56 // 56 //
57 // There are also two consumers of that content, a view request and a save 57 // There are also two consumers of that content, a view request and a save
58 // request. There is at most one save request (i.e. we are either adding this to 58 // request. There is at most one save request (i.e. we are either adding this to
59 // the reading list or we aren't), and may be multiple view requests. When 59 // the reading list or we aren't), and may be multiple view requests. When
60 // the distilled content is ready, each of these requests will be notified. 60 // the distilled content is ready, each of these requests will be notified.
61 // 61 //
62 // A view request is cancelled by deleting the corresponding ViewerHandle. Once 62 // A view request is cancelled by deleting the corresponding ViewerHandle. Once
63 // all view requests are cancelled (and the save callback has been called if 63 // all view requests are cancelled (and the save callback has been called if
64 // appropriate) the cancel callback will be called. 64 // appropriate) the cancel callback will be called.
65 // 65 //
66 // After creating a TaskTracker, a consumer of distilled content should be added 66 // After creating a TaskTracker, a consumer of distilled content should be added
67 // and at least one of the sources should be started. 67 // and at least one of the sources should be started.
68 class TaskTracker { 68 class TaskTracker {
69 public: 69 public:
70 typedef base::Callback<void(TaskTracker*)> CancelCallback; 70 typedef base::Callback<void(TaskTracker*)> CancelCallback;
71 typedef base::Callback<void(const ArticleEntry&, DistilledPageProto*, bool)> 71 typedef base::Callback<
72 void(const ArticleEntry&, const DistilledArticleProto*, bool)>
72 SaveCallback; 73 SaveCallback;
73 74
74 TaskTracker(const ArticleEntry& entry, CancelCallback callback); 75 TaskTracker(const ArticleEntry& entry, CancelCallback callback);
75 ~TaskTracker(); 76 ~TaskTracker();
76 77
77 // |factory| will not be stored after this call. 78 // |factory| will not be stored after this call.
78 void StartDistiller(DistillerFactory* factory); 79 void StartDistiller(DistillerFactory* factory);
79 void StartBlobFetcher(); 80 void StartBlobFetcher();
80 81
81 void AddSaveCallback(const SaveCallback& callback); 82 void AddSaveCallback(const SaveCallback& callback);
82 83
83 void CancelSaveCallbacks(); 84 void CancelSaveCallbacks();
84 85
85 // The ViewerHandle should be destroyed before the ViewRequestDelegate. 86 // The ViewerHandle should be destroyed before the ViewRequestDelegate.
86 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); 87 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate);
87 88
88 const std::string& GetEntryId() const; 89 const std::string& GetEntryId() const;
89 bool HasEntryId(const std::string& entry_id) const; 90 bool HasEntryId(const std::string& entry_id) const;
90 bool HasUrl(const GURL& url) const; 91 bool HasUrl(const GURL& url) const;
91 92
92 private: 93 private:
93 void OnDistilledDataReady(scoped_ptr<DistilledPageProto> distilled_page); 94 void OnDistilledDataReady(
95 scoped_ptr<DistilledArticleProto> distilled_article);
94 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. 96 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|.
95 void ScheduleSaveCallbacks(bool distillation_succeeded); 97 void ScheduleSaveCallbacks(bool distillation_succeeded);
96 98
97 // Runs all callbacks passing |distillation_succeeded| and clears them. Should 99 // Runs all callbacks passing |distillation_succeeded| and clears them. Should
98 // be called through ScheduleSaveCallbacks. 100 // be called through ScheduleSaveCallbacks.
99 void DoSaveCallbacks(bool distillation_succeeded); 101 void DoSaveCallbacks(bool distillation_succeeded);
100 102
101 void RemoveViewer(ViewRequestDelegate* delegate); 103 void RemoveViewer(ViewRequestDelegate* delegate);
102 void NotifyViewer(ViewRequestDelegate* delegate); 104 void NotifyViewer(ViewRequestDelegate* delegate);
103 105
104 void MaybeCancel(); 106 void MaybeCancel();
105 107
106 CancelCallback cancel_callback_; 108 CancelCallback cancel_callback_;
107 std::vector<SaveCallback> save_callbacks_; 109 std::vector<SaveCallback> save_callbacks_;
108 110
109 scoped_ptr<Distiller> distiller_; 111 scoped_ptr<Distiller> distiller_;
110 112
111 // A ViewRequestDelegate will be added to this list when a view request is 113 // A ViewRequestDelegate will be added to this list when a view request is
112 // made and removed when the corresponding ViewerHandle is destroyed. 114 // made and removed when the corresponding ViewerHandle is destroyed.
113 std::vector<ViewRequestDelegate*> viewers_; 115 std::vector<ViewRequestDelegate*> viewers_;
114 116
115 ArticleEntry entry_; 117 ArticleEntry entry_;
116 scoped_ptr<DistilledPageProto> distilled_page_; 118 scoped_ptr<DistilledArticleProto> distilled_article_;
119 bool distillation_complete_;
117 120
118 // Note: This should remain the last member so it'll be destroyed and 121 // Note: This should remain the last member so it'll be destroyed and
119 // invalidate its weak pointers before any other members are destroyed. 122 // invalidate its weak pointers before any other members are destroyed.
120 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; 123 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_;
121 124
122 DISALLOW_COPY_AND_ASSIGN(TaskTracker); 125 DISALLOW_COPY_AND_ASSIGN(TaskTracker);
123 }; 126 };
124 127
125 } // namespace dom_distiller 128 } // namespace dom_distiller
126 129
127 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ 130 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_
OLDNEW
« no previous file with comments | « components/dom_distiller/core/proto/distilled_page.proto ('k') | components/dom_distiller/core/task_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698