| 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 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void(const ArticleEntry&, const DistilledArticleProto*, bool)> | 77 void(const ArticleEntry&, const DistilledArticleProto*, bool)> |
| 78 SaveCallback; | 78 SaveCallback; |
| 79 | 79 |
| 80 TaskTracker(const ArticleEntry& entry, | 80 TaskTracker(const ArticleEntry& entry, |
| 81 CancelCallback callback, | 81 CancelCallback callback, |
| 82 DistilledContentStore* content_store); | 82 DistilledContentStore* content_store); |
| 83 ~TaskTracker(); | 83 ~TaskTracker(); |
| 84 | 84 |
| 85 // |factory| will not be stored after this call. | 85 // |factory| will not be stored after this call. |
| 86 void StartDistiller(DistillerFactory* factory, | 86 void StartDistiller(DistillerFactory* factory, |
| 87 scoped_ptr<DistillerPage> distiller_page); | 87 std::unique_ptr<DistillerPage> distiller_page); |
| 88 void StartBlobFetcher(); | 88 void StartBlobFetcher(); |
| 89 | 89 |
| 90 void AddSaveCallback(const SaveCallback& callback); | 90 void AddSaveCallback(const SaveCallback& callback); |
| 91 | 91 |
| 92 void CancelSaveCallbacks(); | 92 void CancelSaveCallbacks(); |
| 93 | 93 |
| 94 // The ViewerHandle should be destroyed before the ViewRequestDelegate. | 94 // The ViewerHandle should be destroyed before the ViewRequestDelegate. |
| 95 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); | 95 std::unique_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); |
| 96 | 96 |
| 97 const std::string& GetEntryId() const; | 97 const std::string& GetEntryId() const; |
| 98 bool HasEntryId(const std::string& entry_id) const; | 98 bool HasEntryId(const std::string& entry_id) const; |
| 99 bool HasUrl(const GURL& url) const; | 99 bool HasUrl(const GURL& url) const; |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 void OnArticleDistillationUpdated( | 102 void OnArticleDistillationUpdated( |
| 103 const ArticleDistillationUpdate& article_update); | 103 const ArticleDistillationUpdate& article_update); |
| 104 | 104 |
| 105 void OnDistillerFinished(scoped_ptr<DistilledArticleProto> distilled_article); | 105 void OnDistillerFinished( |
| 106 std::unique_ptr<DistilledArticleProto> distilled_article); |
| 106 void OnBlobFetched(bool success, | 107 void OnBlobFetched(bool success, |
| 107 scoped_ptr<DistilledArticleProto> distilled_article); | 108 std::unique_ptr<DistilledArticleProto> distilled_article); |
| 108 | 109 |
| 109 void RemoveViewer(ViewRequestDelegate* delegate); | 110 void RemoveViewer(ViewRequestDelegate* delegate); |
| 110 | 111 |
| 111 void DistilledArticleReady( | 112 void DistilledArticleReady( |
| 112 scoped_ptr<DistilledArticleProto> distilled_article); | 113 std::unique_ptr<DistilledArticleProto> distilled_article); |
| 113 | 114 |
| 114 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. | 115 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. |
| 115 void ScheduleSaveCallbacks(bool distillation_succeeded); | 116 void ScheduleSaveCallbacks(bool distillation_succeeded); |
| 116 | 117 |
| 117 // Runs all callbacks passing |distillation_succeeded| and clears them. | 118 // Runs all callbacks passing |distillation_succeeded| and clears them. |
| 118 void DoSaveCallbacks(bool distillation_succeeded); | 119 void DoSaveCallbacks(bool distillation_succeeded); |
| 119 | 120 |
| 120 void AddDistilledContentToStore(const DistilledArticleProto& content); | 121 void AddDistilledContentToStore(const DistilledArticleProto& content); |
| 121 | 122 |
| 122 void NotifyViewersAndCallbacks(); | 123 void NotifyViewersAndCallbacks(); |
| 123 void NotifyViewer(ViewRequestDelegate* delegate); | 124 void NotifyViewer(ViewRequestDelegate* delegate); |
| 124 | 125 |
| 125 bool IsAnySourceRunning() const; | 126 bool IsAnySourceRunning() const; |
| 126 void ContentSourceFinished(); | 127 void ContentSourceFinished(); |
| 127 | 128 |
| 128 void CancelPendingSources(); | 129 void CancelPendingSources(); |
| 129 void MaybeCancel(); | 130 void MaybeCancel(); |
| 130 | 131 |
| 131 CancelCallback cancel_callback_; | 132 CancelCallback cancel_callback_; |
| 132 | 133 |
| 133 DistilledContentStore* content_store_; | 134 DistilledContentStore* content_store_; |
| 134 | 135 |
| 135 std::vector<SaveCallback> save_callbacks_; | 136 std::vector<SaveCallback> save_callbacks_; |
| 136 // A ViewRequestDelegate will be added to this list when a view request is | 137 // A ViewRequestDelegate will be added to this list when a view request is |
| 137 // made and removed when the corresponding ViewerHandle is destroyed. | 138 // made and removed when the corresponding ViewerHandle is destroyed. |
| 138 std::vector<ViewRequestDelegate*> viewers_; | 139 std::vector<ViewRequestDelegate*> viewers_; |
| 139 | 140 |
| 140 scoped_ptr<Distiller> distiller_; | 141 std::unique_ptr<Distiller> distiller_; |
| 141 bool blob_fetcher_running_; | 142 bool blob_fetcher_running_; |
| 142 | 143 |
| 143 ArticleEntry entry_; | 144 ArticleEntry entry_; |
| 144 scoped_ptr<DistilledArticleProto> distilled_article_; | 145 std::unique_ptr<DistilledArticleProto> distilled_article_; |
| 145 | 146 |
| 146 bool content_ready_; | 147 bool content_ready_; |
| 147 | 148 |
| 148 bool destruction_allowed_; | 149 bool destruction_allowed_; |
| 149 | 150 |
| 150 // Note: This should remain the last member so it'll be destroyed and | 151 // Note: This should remain the last member so it'll be destroyed and |
| 151 // invalidate its weak pointers before any other members are destroyed. | 152 // invalidate its weak pointers before any other members are destroyed. |
| 152 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; | 153 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; |
| 153 | 154 |
| 154 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 155 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
| 155 }; | 156 }; |
| 156 | 157 |
| 157 } // namespace dom_distiller | 158 } // namespace dom_distiller |
| 158 | 159 |
| 159 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ | 160 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ |
| OLD | NEW |