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

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: Attach/Detach 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 #import "ios/web/public/web_state/web_state.h"
11
12 namespace reading_list {
13
14 ReadingListDistillerPage::ReadingListDistillerPage(
15 web::BrowserState* browser_state,
16 FaviconWebStateDispatcher* web_state_dispatcher)
17 : dom_distiller::DistillerPageIOS(browser_state),
18 web_state_dispatcher_(web_state_dispatcher),
19 weak_ptr_factory_(this) {}
20
21 ReadingListDistillerPage::~ReadingListDistillerPage() {}
22
23 void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
24 const std::string& script) {
25 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
26 if (old_web_state) {
27 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
28 }
29 std::unique_ptr<web::WebState> new_web_state =
30 web_state_dispatcher_->RequestWebState();
31 if (new_web_state) {
32 favicon::WebFaviconDriver* favicon_driver =
33 favicon::WebFaviconDriver::FromWebState(new_web_state.get());
34 favicon_driver->FetchFavicon(url);
35 }
36 AttachWebState(std::move(new_web_state));
37
38 DistillerPageIOS::DistillPageImpl(url, script);
39 }
40
41 void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
42 const base::Value* value) {
43 std::unique_ptr<web::WebState> old_web_state = DetachWebState();
44 if (old_web_state) {
45 web_state_dispatcher_->ReturnWebState(std::move(old_web_state));
46 }
47 DistillerPageIOS::OnDistillationDone(page_url, value);
48 }
49
50 void ReadingListDistillerPage::OnLoadURLDone(
51 web::PageLoadCompletionStatus load_completion_status) {
52 if (load_completion_status == web::PageLoadCompletionStatus::FAILURE) {
53 DistillerPageIOS::OnLoadURLDone(load_completion_status);
54 return;
55 }
56 base::WeakPtr<ReadingListDistillerPage> weak_this =
57 weak_ptr_factory_.GetWeakPtr();
58 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
59 FROM_HERE, base::Bind(&ReadingListDistillerPage::DelayedOnLoadURLDone,
60 weak_this, load_completion_status),
61 base::TimeDelta::FromSeconds(2));
gambard 2016/12/27 13:56:57 Nit: Use constant instead of "2"
Olivier 2016/12/27 14:52:15 Done.
62 }
63
64 void ReadingListDistillerPage::DelayedOnLoadURLDone(
65 web::PageLoadCompletionStatus load_completion_status) {
66 DistillerPageIOS::OnLoadURLDone(load_completion_status);
67 }
68 } // namespace reading_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698