| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const DomDistillerService::ArticleAvailableCallback& article_cb, | 35 const DomDistillerService::ArticleAvailableCallback& article_cb, |
| 36 const ArticleEntry& entry, | 36 const ArticleEntry& entry, |
| 37 const DistilledArticleProto* article_proto, | 37 const DistilledArticleProto* article_proto, |
| 38 bool distillation_succeeded) { | 38 bool distillation_succeeded) { |
| 39 article_cb.Run(distillation_succeeded); | 39 article_cb.Run(distillation_succeeded); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 DomDistillerService::DomDistillerService( | 44 DomDistillerService::DomDistillerService( |
| 45 scoped_ptr<DomDistillerStoreInterface> store, | 45 std::unique_ptr<DomDistillerStoreInterface> store, |
| 46 scoped_ptr<DistillerFactory> distiller_factory, | 46 std::unique_ptr<DistillerFactory> distiller_factory, |
| 47 scoped_ptr<DistillerPageFactory> distiller_page_factory, | 47 std::unique_ptr<DistillerPageFactory> distiller_page_factory, |
| 48 scoped_ptr<DistilledPagePrefs> distilled_page_prefs) | 48 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs) |
| 49 : store_(std::move(store)), | 49 : store_(std::move(store)), |
| 50 content_store_(new InMemoryContentStore(kDefaultMaxNumCachedEntries)), | 50 content_store_(new InMemoryContentStore(kDefaultMaxNumCachedEntries)), |
| 51 distiller_factory_(std::move(distiller_factory)), | 51 distiller_factory_(std::move(distiller_factory)), |
| 52 distiller_page_factory_(std::move(distiller_page_factory)), | 52 distiller_page_factory_(std::move(distiller_page_factory)), |
| 53 distilled_page_prefs_(std::move(distilled_page_prefs)) {} | 53 distilled_page_prefs_(std::move(distilled_page_prefs)) {} |
| 54 | 54 |
| 55 DomDistillerService::~DomDistillerService() { | 55 DomDistillerService::~DomDistillerService() { |
| 56 } | 56 } |
| 57 | 57 |
| 58 syncer::SyncableService* DomDistillerService::GetSyncableService() const { | 58 syncer::SyncableService* DomDistillerService::GetSyncableService() const { |
| 59 return store_->GetSyncableService(); | 59 return store_->GetSyncableService(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 scoped_ptr<DistillerPage> DomDistillerService::CreateDefaultDistillerPage( | 62 std::unique_ptr<DistillerPage> DomDistillerService::CreateDefaultDistillerPage( |
| 63 const gfx::Size& render_view_size) { | 63 const gfx::Size& render_view_size) { |
| 64 return distiller_page_factory_->CreateDistillerPage(render_view_size); | 64 return distiller_page_factory_->CreateDistillerPage(render_view_size); |
| 65 } | 65 } |
| 66 | 66 |
| 67 scoped_ptr<DistillerPage> | 67 std::unique_ptr<DistillerPage> |
| 68 DomDistillerService::CreateDefaultDistillerPageWithHandle( | 68 DomDistillerService::CreateDefaultDistillerPageWithHandle( |
| 69 scoped_ptr<SourcePageHandle> handle) { | 69 std::unique_ptr<SourcePageHandle> handle) { |
| 70 return distiller_page_factory_->CreateDistillerPageWithHandle( | 70 return distiller_page_factory_->CreateDistillerPageWithHandle( |
| 71 std::move(handle)); | 71 std::move(handle)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 const std::string DomDistillerService::AddToList( | 74 const std::string DomDistillerService::AddToList( |
| 75 const GURL& url, | 75 const GURL& url, |
| 76 scoped_ptr<DistillerPage> distiller_page, | 76 std::unique_ptr<DistillerPage> distiller_page, |
| 77 const ArticleAvailableCallback& article_cb) { | 77 const ArticleAvailableCallback& article_cb) { |
| 78 ArticleEntry entry; | 78 ArticleEntry entry; |
| 79 const bool is_already_added = store_->GetEntryByUrl(url, &entry); | 79 const bool is_already_added = store_->GetEntryByUrl(url, &entry); |
| 80 | 80 |
| 81 TaskTracker* task_tracker = nullptr; | 81 TaskTracker* task_tracker = nullptr; |
| 82 if (is_already_added) { | 82 if (is_already_added) { |
| 83 task_tracker = GetTaskTrackerForEntry(entry); | 83 task_tracker = GetTaskTrackerForEntry(entry); |
| 84 if (task_tracker == NULL) { | 84 if (task_tracker == NULL) { |
| 85 // Entry is in the store but there is no task tracker. This could | 85 // Entry is in the store but there is no task tracker. This could |
| 86 // happen when distillation has already completed. For now just return | 86 // happen when distillation has already completed. For now just return |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (store_->GetEntryById(entry_id, &entry)) { | 121 if (store_->GetEntryById(entry_id, &entry)) { |
| 122 return entry.pages().Get(0).url(); | 122 return entry.pages().Get(0).url(); |
| 123 } | 123 } |
| 124 return ""; | 124 return ""; |
| 125 } | 125 } |
| 126 | 126 |
| 127 std::vector<ArticleEntry> DomDistillerService::GetEntries() const { | 127 std::vector<ArticleEntry> DomDistillerService::GetEntries() const { |
| 128 return store_->GetEntries(); | 128 return store_->GetEntries(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 scoped_ptr<ArticleEntry> DomDistillerService::RemoveEntry( | 131 std::unique_ptr<ArticleEntry> DomDistillerService::RemoveEntry( |
| 132 const std::string& entry_id) { | 132 const std::string& entry_id) { |
| 133 scoped_ptr<ArticleEntry> entry(new ArticleEntry); | 133 std::unique_ptr<ArticleEntry> entry(new ArticleEntry); |
| 134 entry->set_entry_id(entry_id); | 134 entry->set_entry_id(entry_id); |
| 135 TaskTracker* task_tracker = GetTaskTrackerForEntry(*entry); | 135 TaskTracker* task_tracker = GetTaskTrackerForEntry(*entry); |
| 136 if (task_tracker != NULL) { | 136 if (task_tracker != NULL) { |
| 137 task_tracker->CancelSaveCallbacks(); | 137 task_tracker->CancelSaveCallbacks(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (!store_->GetEntryById(entry_id, entry.get())) { | 140 if (!store_->GetEntryById(entry_id, entry.get())) { |
| 141 return scoped_ptr<ArticleEntry>(); | 141 return std::unique_ptr<ArticleEntry>(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (store_->RemoveEntry(*entry)) { | 144 if (store_->RemoveEntry(*entry)) { |
| 145 return entry; | 145 return entry; |
| 146 } | 146 } |
| 147 return scoped_ptr<ArticleEntry>(); | 147 return std::unique_ptr<ArticleEntry>(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry( | 150 std::unique_ptr<ViewerHandle> DomDistillerService::ViewEntry( |
| 151 ViewRequestDelegate* delegate, | 151 ViewRequestDelegate* delegate, |
| 152 scoped_ptr<DistillerPage> distiller_page, | 152 std::unique_ptr<DistillerPage> distiller_page, |
| 153 const std::string& entry_id) { | 153 const std::string& entry_id) { |
| 154 ArticleEntry entry; | 154 ArticleEntry entry; |
| 155 if (!store_->GetEntryById(entry_id, &entry)) { | 155 if (!store_->GetEntryById(entry_id, &entry)) { |
| 156 return scoped_ptr<ViewerHandle>(); | 156 return std::unique_ptr<ViewerHandle>(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 TaskTracker* task_tracker = nullptr; | 159 TaskTracker* task_tracker = nullptr; |
| 160 bool was_created = GetOrCreateTaskTrackerForEntry(entry, &task_tracker); | 160 bool was_created = GetOrCreateTaskTrackerForEntry(entry, &task_tracker); |
| 161 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); | 161 std::unique_ptr<ViewerHandle> viewer_handle = |
| 162 task_tracker->AddViewer(delegate); |
| 162 if (was_created) { | 163 if (was_created) { |
| 163 task_tracker->StartDistiller(distiller_factory_.get(), | 164 task_tracker->StartDistiller(distiller_factory_.get(), |
| 164 std::move(distiller_page)); | 165 std::move(distiller_page)); |
| 165 task_tracker->StartBlobFetcher(); | 166 task_tracker->StartBlobFetcher(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 return viewer_handle; | 169 return viewer_handle; |
| 169 } | 170 } |
| 170 | 171 |
| 171 scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl( | 172 std::unique_ptr<ViewerHandle> DomDistillerService::ViewUrl( |
| 172 ViewRequestDelegate* delegate, | 173 ViewRequestDelegate* delegate, |
| 173 scoped_ptr<DistillerPage> distiller_page, | 174 std::unique_ptr<DistillerPage> distiller_page, |
| 174 const GURL& url) { | 175 const GURL& url) { |
| 175 if (!url.is_valid()) { | 176 if (!url.is_valid()) { |
| 176 return scoped_ptr<ViewerHandle>(); | 177 return std::unique_ptr<ViewerHandle>(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 TaskTracker* task_tracker = nullptr; | 180 TaskTracker* task_tracker = nullptr; |
| 180 bool was_created = GetOrCreateTaskTrackerForUrl(url, &task_tracker); | 181 bool was_created = GetOrCreateTaskTrackerForUrl(url, &task_tracker); |
| 181 scoped_ptr<ViewerHandle> viewer_handle = task_tracker->AddViewer(delegate); | 182 std::unique_ptr<ViewerHandle> viewer_handle = |
| 183 task_tracker->AddViewer(delegate); |
| 182 // If a distiller is already running for one URL, don't start another. | 184 // If a distiller is already running for one URL, don't start another. |
| 183 if (was_created) { | 185 if (was_created) { |
| 184 task_tracker->StartDistiller(distiller_factory_.get(), | 186 task_tracker->StartDistiller(distiller_factory_.get(), |
| 185 std::move(distiller_page)); | 187 std::move(distiller_page)); |
| 186 task_tracker->StartBlobFetcher(); | 188 task_tracker->StartBlobFetcher(); |
| 187 } | 189 } |
| 188 | 190 |
| 189 return viewer_handle; | 191 return viewer_handle; |
| 190 } | 192 } |
| 191 | 193 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { | 278 void DomDistillerService::RemoveObserver(DomDistillerObserver* observer) { |
| 277 DCHECK(observer); | 279 DCHECK(observer); |
| 278 store_->RemoveObserver(observer); | 280 store_->RemoveObserver(observer); |
| 279 } | 281 } |
| 280 | 282 |
| 281 DistilledPagePrefs* DomDistillerService::GetDistilledPagePrefs() { | 283 DistilledPagePrefs* DomDistillerService::GetDistilledPagePrefs() { |
| 282 return distilled_page_prefs_.get(); | 284 return distilled_page_prefs_.get(); |
| 283 } | 285 } |
| 284 | 286 |
| 285 } // namespace dom_distiller | 287 } // namespace dom_distiller |
| OLD | NEW |