| 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_entry.h" | 15 #include "components/dom_distiller/core/article_entry.h" |
| 15 #include "components/dom_distiller/core/distiller.h" | 16 #include "components/dom_distiller/core/distiller.h" |
| 16 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 17 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 | 20 |
| 20 namespace dom_distiller { | 21 namespace dom_distiller { |
| 21 | 22 |
| 22 class DistilledArticleProto; | 23 class DistilledArticleProto; |
| 23 | 24 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 38 // Interface for a DOM distiller entry viewer. Implement this to make a view | 39 // 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. | 40 // request and receive the data for an entry when it becomes available. |
| 40 class ViewRequestDelegate { | 41 class ViewRequestDelegate { |
| 41 public: | 42 public: |
| 42 virtual ~ViewRequestDelegate() {} | 43 virtual ~ViewRequestDelegate() {} |
| 43 // Called when the distilled article contents are available. The | 44 // Called when the distilled article contents are available. The |
| 44 // DistilledArticleProto is owned by a TaskTracker instance and is invalidated | 45 // DistilledArticleProto is owned by a TaskTracker instance and is invalidated |
| 45 // when the corresponding ViewerHandle is destroyed (or when the | 46 // when the corresponding ViewerHandle is destroyed (or when the |
| 46 // DomDistillerService is destroyed). | 47 // DomDistillerService is destroyed). |
| 47 virtual void OnArticleReady(const DistilledArticleProto* article_proto) = 0; | 48 virtual void OnArticleReady(const DistilledArticleProto* article_proto) = 0; |
| 49 |
| 50 // Called when an article that is currently under distillation is updated. |
| 51 virtual void OnArticleUpdated(ArticleDistillationUpdate article_update) = 0; |
| 48 }; | 52 }; |
| 49 | 53 |
| 50 // A TaskTracker manages the various tasks related to viewing, saving, | 54 // A TaskTracker manages the various tasks related to viewing, saving, |
| 51 // distilling, and fetching an article's distilled content. | 55 // distilling, and fetching an article's distilled content. |
| 52 // | 56 // |
| 53 // There are two sources of distilled content, a Distiller and the BlobFetcher. | 57 // 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 | 58 // At any time, at most one of each of these will be in-progress (if one |
| 55 // finishes, the other will be cancelled). | 59 // finishes, the other will be cancelled). |
| 56 // | 60 // |
| 57 // There are also two consumers of that content, a view request and a save | 61 // There are also two consumers of that content, a view request and a save |
| (...skipping 26 matching lines...) Expand all Loading... |
| 84 void CancelSaveCallbacks(); | 88 void CancelSaveCallbacks(); |
| 85 | 89 |
| 86 // The ViewerHandle should be destroyed before the ViewRequestDelegate. | 90 // The ViewerHandle should be destroyed before the ViewRequestDelegate. |
| 87 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); | 91 scoped_ptr<ViewerHandle> AddViewer(ViewRequestDelegate* delegate); |
| 88 | 92 |
| 89 const std::string& GetEntryId() const; | 93 const std::string& GetEntryId() const; |
| 90 bool HasEntryId(const std::string& entry_id) const; | 94 bool HasEntryId(const std::string& entry_id) const; |
| 91 bool HasUrl(const GURL& url) const; | 95 bool HasUrl(const GURL& url) const; |
| 92 | 96 |
| 93 private: | 97 private: |
| 94 void OnDistilledDataReady( | 98 void OnDistilledArticleReady( |
| 95 scoped_ptr<DistilledArticleProto> distilled_article); | 99 scoped_ptr<DistilledArticleProto> distilled_article); |
| 100 void OnArticleDistillationUpdated( |
| 101 const ArticleDistillationUpdate& article_update); |
| 96 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. | 102 // Posts a task to run DoSaveCallbacks with |distillation_succeeded|. |
| 97 void ScheduleSaveCallbacks(bool distillation_succeeded); | 103 void ScheduleSaveCallbacks(bool distillation_succeeded); |
| 98 | 104 |
| 99 // Runs all callbacks passing |distillation_succeeded| and clears them. Should | 105 // Runs all callbacks passing |distillation_succeeded| and clears them. Should |
| 100 // be called through ScheduleSaveCallbacks. | 106 // be called through ScheduleSaveCallbacks. |
| 101 void DoSaveCallbacks(bool distillation_succeeded); | 107 void DoSaveCallbacks(bool distillation_succeeded); |
| 102 | 108 |
| 103 void RemoveViewer(ViewRequestDelegate* delegate); | 109 void RemoveViewer(ViewRequestDelegate* delegate); |
| 104 void NotifyViewer(ViewRequestDelegate* delegate); | 110 void NotifyViewer(ViewRequestDelegate* delegate); |
| 105 | 111 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 // Note: This should remain the last member so it'll be destroyed and | 127 // Note: This should remain the last member so it'll be destroyed and |
| 122 // invalidate its weak pointers before any other members are destroyed. | 128 // invalidate its weak pointers before any other members are destroyed. |
| 123 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; | 129 base::WeakPtrFactory<TaskTracker> weak_ptr_factory_; |
| 124 | 130 |
| 125 DISALLOW_COPY_AND_ASSIGN(TaskTracker); | 131 DISALLOW_COPY_AND_ASSIGN(TaskTracker); |
| 126 }; | 132 }; |
| 127 | 133 |
| 128 } // namespace dom_distiller | 134 } // namespace dom_distiller |
| 129 | 135 |
| 130 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ | 136 #endif // COMPONENTS_DOM_DISTILLER_CORE_TASK_TRACKER_H_ |
| OLD | NEW |