Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_distiller_page.mm

Issue 2604773002: Create distiller files for Reading List. (Closed)
Patch Set: feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/reading_list/reading_list_distiller_page.h"
6
7 #include "base/bind.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "components/favicon/ios/web_favicon_driver.h"
10 #include "ios/chrome/browser/reading_list/favicon_web_state_dispatcher_impl.h"
11 #import "ios/web/public/web_state/web_state.h"
12
13 namespace {
14 // The delay between the page load and the distillation in seconds.
15 const int64_t kDistillationDelayInSeconds = 2;
16 } // namespace
17
18 namespace reading_list {
19
20 ReadingListDistillerPage::ReadingListDistillerPage(
21 web::BrowserState* browser_state,
22 FaviconWebStateDispatcher* web_state_dispatcher)
23 : dom_distiller::DistillerPageIOS(browser_state),
24 web_state_dispatcher_(web_state_dispatcher),
25 weak_ptr_factory_(this) {}
26
27 ReadingListDistillerPage::~ReadingListDistillerPage() {}
28
29 void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
30 const std::string& script) {
31 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
32 if (old_web_state) {
33 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
34 }
35 std::unique_ptr<web::WebState> new_web_state =
36 web_state_dispatcher_->RequestWebState();
37 if (new_web_state) {
38 favicon::WebFaviconDriver* favicon_driver =
39 favicon::WebFaviconDriver::FromWebState(new_web_state.get());
40 favicon_driver->FetchFavicon(url);
41 }
42 AttachWebState(std::move(new_web_state));
43
44 DistillerPageIOS::DistillPageImpl(url, script);
45 }
46
47 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
48 const base::Value* value) {
49 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
50 if (old_web_state) {
51 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
52 }
53 DistillerPageIOS::OnDistillationDone(page_url, value);
54 }
55
56 void ReadingListDistillerPage::OnLoadURLDone(
57 web::PageLoadCompletionStatus load_completion_status) {
58 if (load_completion_status == web::PageLoadCompletionStatus::FAILURE) {
59 DistillerPageIOS::OnLoadURLDone(load_completion_status);
60 return;
61 }
62 base::WeakPtr<ReadingListDistillerPage> weak_this =
63 weak_ptr_factory_.GetWeakPtr();
64 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
65 FROM_HERE, base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone,
66 weak_this, load_completion_status),
67 base::TimeDelta::FromSeconds(kDistillationDelayInSeconds));
68 }
69
70 void ReadingListDistillerPage::DelayedOnLoadURLDone(
71 web::PageLoadCompletionStatus load_completion_status) {
72 DistillerPageIOS::OnLoadURLDone(load_completion_status);
73 }
74 } // namespace reading_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698