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 #include "components/dom_distiller/core/dom_distiller_service.h" | 5 #include "components/dom_distiller/core/dom_distiller_service.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "components/dom_distiller/core/distilled_content_store.h" | 9 #include "components/dom_distiller/core/distilled_content_store.h" |
10 #include "components/dom_distiller/core/dom_distiller_store.h" | 10 #include "components/dom_distiller/core/dom_distiller_store.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 const ArticleEntry& entry, | 31 const ArticleEntry& entry, |
32 const DistilledArticleProto* article_proto, | 32 const DistilledArticleProto* article_proto, |
33 bool distillation_succeeded) { | 33 bool distillation_succeeded) { |
34 article_cb.Run(distillation_succeeded); | 34 article_cb.Run(distillation_succeeded); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 DomDistillerService::DomDistillerService( | 39 DomDistillerService::DomDistillerService( |
40 scoped_ptr<DomDistillerStoreInterface> store, | 40 scoped_ptr<DomDistillerStoreInterface> store, |
41 scoped_ptr<DistillerFactory> distiller_factory) | 41 scoped_ptr<DistillerFactory> distiller_factory, |
| 42 scoped_ptr<DistillerPageFactory> distiller_page_factory) |
42 : store_(store.Pass()), | 43 : store_(store.Pass()), |
43 content_store_(new InMemoryContentStore()), | 44 content_store_(new InMemoryContentStore()), |
44 distiller_factory_(distiller_factory.Pass()) {} | 45 distiller_factory_(distiller_factory.Pass()), |
| 46 distiller_page_factory_(distiller_page_factory.Pass()) { |
| 47 } |
45 | 48 |
46 DomDistillerService::~DomDistillerService() {} | 49 DomDistillerService::~DomDistillerService() {} |
47 | 50 |
48 syncer::SyncableService* DomDistillerService::GetSyncableService() const { | 51 syncer::SyncableService* DomDistillerService::GetSyncableService() const { |
49 return store_->GetSyncableService(); | 52 return store_->GetSyncableService(); |
50 } | 53 } |
51 | 54 |
| 55 scoped_ptr<DistillerPage> DomDistillerService::CreateDefaultDistillerPage() { |
| 56 return distiller_page_factory_->CreateDistillerPage().Pass(); |
| 57 } |
| 58 |
52 const std::string DomDistillerService::AddToList( | 59 const std::string DomDistillerService::AddToList( |
53 const GURL& url, | 60 const GURL& url, |
| 61 scoped_ptr<DistillerPage> distiller_page, |
54 const ArticleAvailableCallback& article_cb) { | 62 const ArticleAvailableCallback& article_cb) { |
55 ArticleEntry entry; | 63 ArticleEntry entry; |
56 const bool is_already_added = store_->GetEntryByUrl(url, &entry); | 64 const bool is_already_added = store_->GetEntryByUrl(url, &entry); |
57 | 65 |
58 TaskTracker* task_tracker; | 66 TaskTracker* task_tracker; |
59 if (is_already_added) { | 67 if (is_already_added) { |
60 task_tracker = GetTaskTrackerForEntry(entry); | 68 task_tracker = GetTaskTrackerForEntry(entry); |
61 if (task_tracker == NULL) { | 69 if (task_tracker == NULL) { |
62 // Entry is in the store but there is no task tracker. This could | 70 // Entry is in the store but there is no task tracker. This could |
63 // happen when distillation has already completed. For now just return | 71 // happen when distillation has already completed. For now just return |
(...skipping 10 matching lines...) Expand all Loading... |
74 } | 82 } |
75 | 83 |
76 if (!article_cb.is_null()) { | 84 if (!article_cb.is_null()) { |
77 task_tracker->AddSaveCallback( | 85 task_tracker->AddSaveCallback( |
78 base::Bind(&RunArticleAvailableCallback, article_cb)); | 86 base::Bind(&RunArticleAvailableCallback, article_cb)); |
79 } | 87 } |
80 | 88 |
81 if (!is_already_added) { | 89 if (!is_already_added) { |
82 task_tracker->AddSaveCallback(base::Bind( | 90 task_tracker->AddSaveCallback(base::Bind( |
83 &DomDistillerService::AddDistilledPageToList, base::Unretained(this))); | 91 &DomDistillerService::AddDistilledPageToList, base::Unretained(this))); |
84 task_tracker->StartDistiller(distiller_factory_.get()); | 92 task_tracker->StartDistiller(distiller_factory_.get(), |
| 93 distiller_page.Pass()); |
85 task_tracker->StartBlobFetcher(); | 94 task_tracker->StartBlobFetcher(); |
86 } | 95 } |
87 | 96 |
88 return task_tracker->GetEntryId(); | 97 return task_tracker->GetEntryId(); |
89 } | 98 } |
90 | 99 |
91 std::vector<ArticleEntry> DomDistillerService::GetEntries() const { | 100 std::vector<ArticleEntry> DomDistillerService::GetEntries() const { |
92 return store_->GetEntries(); | 101 return store_->GetEntries(); |
93 } | 102 } |
94 | 103 |
(...skipping 11 matching lines...) Expand all Loading... |
106 } | 115 } |
107 | 116 |
108 if (store_->RemoveEntry(*entry)) { | 117 if (store_->RemoveEntry(*entry)) { |
109 return entry.Pass(); | 118 return entry.Pass(); |
110 } | 119 } |
111 return scoped_ptr<ArticleEntry>(); | 120 return scoped_ptr<ArticleEntry>(); |
112 } | 121 } |
113 | 122 |
114 scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry( | 123 scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry( |
115 ViewRequestDelegate* delegate, | 124 ViewRequestDelegate* delegate, |
| 125 scoped_ptr<DistillerPage> distiller_page, |
116 const std::string& entry_id) { | 126 const std::string& entry_id) { |
117 ArticleEntry entry; | 127 ArticleEntry entry; |
118 if (!store_->GetEntryById(entry_id, &entry)) { | 128 if (!store_->GetEntryById(entry_id, &entry)) { |
119 return scoped_ptr<ViewerHandle>(); | 129 return scoped_ptr<ViewerHandle>(); |
120 } | 130 } |
121 | 131 |
122 TaskTracker* task_tracker = GetOrCreateTaskTrackerForEntry(entry); | 132 TaskTracker* task_tracker = GetOrCreateTaskTrackerForEntry(entry); |
123 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); | 133 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); |
124 task_tracker->StartDistiller(distiller_factory_.get()); | 134 task_tracker->StartDistiller(distiller_factory_.get(), distiller_page.Pass()); |
125 task_tracker->StartBlobFetcher(); | 135 task_tracker->StartBlobFetcher(); |
126 | 136 |
127 return viewer_handle.Pass(); | 137 return viewer_handle.Pass(); |
128 } | 138 } |
129 | 139 |
130 scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl( | 140 scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl( |
131 ViewRequestDelegate* delegate, | 141 ViewRequestDelegate* delegate, |
| 142 scoped_ptr<DistillerPage> distiller_page, |
132 const GURL& url) { | 143 const GURL& url) { |
133 if (!url.is_valid()) { | 144 if (!url.is_valid()) { |
134 return scoped_ptr<ViewerHandle>(); | 145 return scoped_ptr<ViewerHandle>(); |
135 } | 146 } |
136 | 147 |
137 TaskTracker* task_tracker = GetOrCreateTaskTrackerForUrl(url); | 148 TaskTracker* task_tracker = GetOrCreateTaskTrackerForUrl(url); |
138 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); | 149 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); |
139 task_tracker->StartDistiller(distiller_factory_.get()); | 150 task_tracker->StartDistiller(distiller_factory_.get(), distiller_page.Pass()); |
140 task_tracker->StartBlobFetcher(); | 151 task_tracker->StartBlobFetcher(); |
141 | 152 |
142 return viewer_handle.Pass(); | 153 return viewer_handle.Pass(); |
143 } | 154 } |
144 | 155 |
145 TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForUrl( | 156 TaskTracker* DomDistillerService::GetOrCreateTaskTrackerForUrl( |
146 const GURL& url) { | 157 const GURL& url) { |
147 ArticleEntry entry; | 158 ArticleEntry entry; |
148 if (store_->GetEntryByUrl(url, &entry)) { | 159 if (store_->GetEntryByUrl(url, &entry)) { |
149 return GetOrCreateTaskTrackerForEntry(entry); | 160 return GetOrCreateTaskTrackerForEntry(entry); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 DCHECK(observer); | 225 DCHECK(observer); |
215 store_->AddObserver(observer); | 226 store_->AddObserver(observer); |
216 } | 227 } |
217 | 228 |
218 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { | 229 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { |
219 DCHECK(observer); | 230 DCHECK(observer); |
220 store_->RemoveObserver(observer); | 231 store_->RemoveObserver(observer); |
221 } | 232 } |
222 | 233 |
223 } // namespace dom_distiller | 234 } // namespace dom_distiller |
OLD | NEW |