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

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

Issue 189833002: Add a DistilledContentStore (and an in-memory impl) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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_distillation_update.h" 14 #include "components/dom_distiller/core/article_distillation_update.h"
15 #include "components/dom_distiller/core/article_entry.h" 15 #include "components/dom_distiller/core/article_entry.h"
16 #include "components/dom_distiller/core/distiller.h" 16 #include "components/dom_distiller/core/distiller.h"
17 #include "components/dom_distiller/core/proto/distilled_page.pb.h" 17 #include "components/dom_distiller/core/proto/distilled_page.pb.h"
18 18
19 class GURL; 19 class GURL;
20 20
21 namespace dom_distiller { 21 namespace dom_distiller {
22 22
23 class DistilledArticleProto; 23 class DistilledArticleProto;
24 class DistilledContentStore;
24 25
25 // A handle to a request to view a DOM distiller entry or URL. The request will 26 // A handle to a request to view a DOM distiller entry or URL. The request will
26 // be cancelled when the handle is destroyed. 27 // be cancelled when the handle is destroyed.
27 class ViewerHandle { 28 class ViewerHandle {
28 public: 29 public:
29 typedef base::Callback<void()> CancelCallback; 30 typedef base::Callback<void()> CancelCallback;
30 explicit ViewerHandle(CancelCallback callback); 31 explicit ViewerHandle(CancelCallback callback);
31 ~ViewerHandle(); 32 ~ViewerHandle();
32 33
33 private: 34 private:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // 69 //
69 // After creating a TaskTracker, a consumer of distilled content should be added 70 // After creating a TaskTracker, a consumer of distilled content should be added
70 // and at least one of the sources should be started. 71 // and at least one of the sources should be started.
71 class TaskTracker { 72 class TaskTracker {
72 public: 73 public:
73 typedef base::Callback<void(TaskTracker*)> CancelCallback; 74 typedef base::Callback<void(TaskTracker*)> CancelCallback;
74 typedef base::Callback< 75 typedef base::Callback<
75 void(const ArticleEntry&, const DistilledArticleProto*, bool)> 76 void(const ArticleEntry&, const DistilledArticleProto*, bool)>
76 SaveCallback; 77 SaveCallback;
77 78
78 TaskTracker(const ArticleEntry& entry, CancelCallback callback); 79 TaskTracker(const ArticleEntry& entry,
80 CancelCallback callback,
81 DistilledContentStore* content_store);
79 ~TaskTracker(); 82 ~TaskTracker();
80 83
81 // |factory| will not be stored after this call. 84 // |factory| will not be stored after this call.
82 void StartDistiller(DistillerFactory* factory); 85 void StartDistiller(DistillerFactory* factory);
83 void StartBlobFetcher(); 86 void StartBlobFetcher();
84 87
85 void AddSaveCallback(const SaveCallback& callback); 88 void AddSaveCallback(const SaveCallback& callback);
86 89
87 void CancelSaveCallbacks(); 90 void CancelSaveCallbacks();
88 91
89 // The ViewerHandle should be destroyed before the ViewRequestDelegate. 92 // The ViewerHandle should be destroyed before the ViewRequestDelegate.
90 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); 93 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate);
91 94
92 const std::string& GetEntryId() const; 95 const std::string& GetEntryId() const;
93 bool HasEntryId(const std::string& entry_id) const; 96 bool HasEntryId(const std::string& entry_id) const;
94 bool HasUrl(const GURL& url) const; 97 bool HasUrl(const GURL& url) const;
95 98
96 private: 99 private:
97 void OnDistillerFinished(scoped_ptr<DistilledArticleProto> distilled_article);
98
99 void OnDistilledArticleReady(
100 scoped_ptr<DistilledArticleProto> distilled_article);
101 void OnArticleDistillationUpdated( 100 void OnArticleDistillationUpdated(
102 const ArticleDistillationUpdate& article_update); 101 const ArticleDistillationUpdate& article_update);
102
103 void OnDistillerFinished(scoped_ptr<DistilledArticleProto> distilled_article);
104 void OnBlobFetched(bool success,
105 scoped_ptr<DistilledArticleProto> distilled_article);
106
107 void RemoveViewer(ViewRequestDelegate* delegate);
108
109 void DistilledArticleReady(
110 scoped_ptr<DistilledArticleProto> distilled_article);
111
103 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. 112 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|.
104 void ScheduleSaveCallbacks(bool distillation_succeeded); 113 void ScheduleSaveCallbacks(bool distillation_succeeded);
105 114
106 // Runs all callbacks passing |distillation_succeeded| and clears them. Should 115 // Runs all callbacks passing |distillation_succeeded| and clears them.
107 // be called through ScheduleSaveCallbacks.
108 void DoSaveCallbacks(bool distillation_succeeded); 116 void DoSaveCallbacks(bool distillation_succeeded);
109 117
110 void RemoveViewer(ViewRequestDelegate* delegate); 118 void AddDistilledContentToStore(const DistilledArticleProto& content);
119
120 void NotifyViewersAndCallbacks();
111 void NotifyViewer(ViewRequestDelegate* delegate); 121 void NotifyViewer(ViewRequestDelegate* delegate);
112 122
123 bool IsAnySourceRunning() const;
124 void ContentSourceFinished();
125
126 void CancelPendingSources();
113 void MaybeCancel(); 127 void MaybeCancel();
114 128
115 CancelCallback cancel_callback_; 129 CancelCallback cancel_callback_;
130
131 DistilledContentStore* content_store_;
132
116 std::vector<SaveCallback> save_callbacks_; 133 std::vector<SaveCallback> save_callbacks_;
117
118 scoped_ptr<Distiller> distiller_;
119
120 // A ViewRequestDelegate will be added to this list when a view request is 134 // A ViewRequestDelegate will be added to this list when a view request is
121 // made and removed when the corresponding ViewerHandle is destroyed. 135 // made and removed when the corresponding ViewerHandle is destroyed.
122 std::vector<ViewRequestDelegate*> viewers_; 136 std::vector<ViewRequestDelegate*> viewers_;
123 137
138 scoped_ptr<Distiller> distiller_;
139 bool blob_fetcher_running_;
140
124 ArticleEntry entry_; 141 ArticleEntry entry_;
125 scoped_ptr<DistilledArticleProto> distilled_article_; 142 scoped_ptr<DistilledArticleProto> distilled_article_;
126 143
127 bool content_ready_; 144 bool content_ready_;
128 145
129 bool destruction_allowed_; 146 bool destruction_allowed_;
130 147
131 // Note: This should remain the last member so it'll be destroyed and 148 // Note: This should remain the last member so it'll be destroyed and
132 // invalidate its weak pointers before any other members are destroyed. 149 // invalidate its weak pointers before any other members are destroyed.
133 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; 150 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_;
134 151
135 DISALLOW_COPY_AND_ASSIGN(TaskTracker); 152 DISALLOW_COPY_AND_ASSIGN(TaskTracker);
136 }; 153 };
137 154
138 } // namespace dom_distiller 155 } // namespace dom_distiller
139 156
140 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ 157 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.cc ('k') | components/dom_distiller/core/task_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698