| 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/distiller.h" | 5 #include "components/dom_distiller/core/distiller.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/message_loop/message_loop.h" | |
| 16 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "components/dom_distiller/core/distiller_page.h" | 21 #include "components/dom_distiller/core/distiller_page.h" |
| 21 #include "components/dom_distiller/core/distiller_url_fetcher.h" | 22 #include "components/dom_distiller/core/distiller_url_fetcher.h" |
| 22 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 23 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| 23 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 24 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 // Maximum number of distilled pages in an article. | 28 // Maximum number of distilled pages in an article. |
| 28 const size_t kMaxPagesInArticle = 32; | 29 const size_t kMaxPagesInArticle = 32; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DCHECK(url_fetcher); | 313 DCHECK(url_fetcher); |
| 313 ScopedVector<DistillerURLFetcher>::iterator fetcher_it = | 314 ScopedVector<DistillerURLFetcher>::iterator fetcher_it = |
| 314 std::find(page_data->image_fetchers_.begin(), | 315 std::find(page_data->image_fetchers_.begin(), |
| 315 page_data->image_fetchers_.end(), | 316 page_data->image_fetchers_.end(), |
| 316 url_fetcher); | 317 url_fetcher); |
| 317 | 318 |
| 318 DCHECK(fetcher_it != page_data->image_fetchers_.end()); | 319 DCHECK(fetcher_it != page_data->image_fetchers_.end()); |
| 319 // Delete the |url_fetcher| by DeleteSoon since the OnFetchImageDone | 320 // Delete the |url_fetcher| by DeleteSoon since the OnFetchImageDone |
| 320 // callback is invoked by the |url_fetcher|. | 321 // callback is invoked by the |url_fetcher|. |
| 321 page_data->image_fetchers_.weak_erase(fetcher_it); | 322 page_data->image_fetchers_.weak_erase(fetcher_it); |
| 322 base::MessageLoop::current()->DeleteSoon(FROM_HERE, url_fetcher); | 323 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, url_fetcher); |
| 323 | 324 |
| 324 DistilledPageProto_Image* image = | 325 DistilledPageProto_Image* image = |
| 325 page_data->distilled_page_proto->data.add_image(); | 326 page_data->distilled_page_proto->data.add_image(); |
| 326 image->set_name(id); | 327 image->set_name(id); |
| 327 image->set_data(response); | 328 image->set_data(response); |
| 328 image->set_url(original_url); | 329 image->set_url(original_url); |
| 329 | 330 |
| 330 AddPageIfDone(page_num); | 331 AddPageIfDone(page_num); |
| 331 } | 332 } |
| 332 | 333 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 DCHECK(finished_pages_index_.empty()); | 395 DCHECK(finished_pages_index_.empty()); |
| 395 | 396 |
| 396 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, | 397 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, |
| 397 false); | 398 false); |
| 398 finished_cb_.Run(std::move(article_proto)); | 399 finished_cb_.Run(std::move(article_proto)); |
| 399 finished_cb_.Reset(); | 400 finished_cb_.Reset(); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 } // namespace dom_distiller | 404 } // namespace dom_distiller |
| OLD | NEW |