| OLD | NEW |
| 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 Loading... |
| 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); | 100 void OnDistillerFinished(scoped_ptr<DistilledArticleProto> distilled_article); |
| 101 void OnBlobFetched(bool success, |
| 102 scoped_ptr<DistilledArticleProto> distilled_article); |
| 98 | 103 |
| 99 void OnDistilledArticleReady( | 104 void OnDistilledArticleReady( |
| 100 scoped_ptr<DistilledArticleProto> distilled_article); | 105 scoped_ptr<DistilledArticleProto> distilled_article); |
| 101 void OnArticleDistillationUpdated( | 106 void OnArticleDistillationUpdated( |
| 102 const ArticleDistillationUpdate& article_update); | 107 const ArticleDistillationUpdate& article_update); |
| 103 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. | 108 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. |
| 104 void ScheduleSaveCallbacks(bool distillation_succeeded); | 109 void ScheduleSaveCallbacks(bool distillation_succeeded); |
| 105 | 110 |
| 106 // Runs all callbacks passing |distillation_succeeded| and clears them. Should | 111 // Runs all callbacks passing |distillation_succeeded| and clears them. Should |
| 107 // be called through ScheduleSaveCallbacks. | 112 // be called through ScheduleSaveCallbacks. |
| 108 void DoSaveCallbacks(bool distillation_succeeded); | 113 void DoSaveCallbacks(bool distillation_succeeded); |
| 109 | 114 |
| 115 void AddDistilledContentToStore(); |
| 116 |
| 110 void RemoveViewer(ViewRequestDelegate* delegate); | 117 void RemoveViewer(ViewRequestDelegate* delegate); |
| 111 void NotifyViewer(ViewRequestDelegate* delegate); | 118 void NotifyViewer(ViewRequestDelegate* delegate); |
| 112 | 119 |
| 113 void MaybeCancel(); | 120 void MaybeCancel(); |
| 114 | 121 |
| 115 CancelCallback cancel_callback_; | 122 CancelCallback cancel_callback_; |
| 123 |
| 124 DistilledContentStore* content_store_; |
| 125 |
| 116 std::vector<SaveCallback> save_callbacks_; | 126 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 | 127 // A ViewRequestDelegate will be added to this list when a view request is |
| 121 // made and removed when the corresponding ViewerHandle is destroyed. | 128 // made and removed when the corresponding ViewerHandle is destroyed. |
| 122 std::vector<ViewRequestDelegate*> viewers_; | 129 std::vector<ViewRequestDelegate*> viewers_; |
| 123 | 130 |
| 131 scoped_ptr<Distiller> distiller_; |
| 132 |
| 124 ArticleEntry entry_; | 133 ArticleEntry entry_; |
| 125 scoped_ptr<DistilledArticleProto> distilled_article_; | 134 scoped_ptr<DistilledArticleProto> distilled_article_; |
| 126 | 135 |
| 127 bool content_ready_; | 136 bool content_ready_; |
| 128 | 137 |
| 129 bool destruction_allowed_; | 138 bool destruction_allowed_; |
| 130 | 139 |
| 131 // Note: This should remain the last member so it'll be destroyed and | 140 // Note: This should remain the last member so it'll be destroyed and |
| 132 // invalidate its weak pointers before any other members are destroyed. | 141 // invalidate its weak pointers before any other members are destroyed. |
| 133 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; | 142 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; |
| 134 | 143 |
| 135 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 144 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
| 136 }; | 145 }; |
| 137 | 146 |
| 138 } // namespace dom_distiller | 147 } // namespace dom_distiller |
| 139 | 148 |
| 140 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ | 149 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ |
| OLD | NEW |