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

Side by Side Diff: ios/chrome/browser/dom_distiller/web_state_dispatcher_impl.mm

Issue 2529283002: Save favicon during reading list distillation (Closed)
Patch Set: Fix constructor Created 4 years 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/dom_distiller/web_state_dispatcher_impl.h"
6
7 #include "components/favicon/ios/web_favicon_driver.h"
8 #include "components/keyed_service/core/service_access_type.h"
9 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/chrome/browser/favicon/favicon_service_factory.h"
12 #include "ios/chrome/browser/history/history_service_factory.h"
13 #import "ios/web/public/web_state/web_state.h"
14
15 namespace {
16 // Delay to download the favicon when the WebState is handed back.
17 const int kMaxDelayFavicon = 10;
18 }
19
20 namespace dom_distiller {
21
22 WebStateDispatcherImpl::WebStateDispatcherImpl(web::BrowserState* browser_state)
23 : WebStateDispatcher(),
24 browser_state_(browser_state),
25 weak_ptr_factory_(this) {}
26 WebStateDispatcherImpl::~WebStateDispatcherImpl() {}
27
28 web::WebState* WebStateDispatcherImpl::RequestWebState() {
29 const web::WebState::CreateParams web_state_create_params(browser_state_);
30 std::unique_ptr<web::WebState> web_state_unique =
31 web::WebState::Create(web_state_create_params);
32 web::WebState* web_state = web_state_unique.get();
33
34 web_states_[web_state] = std::move(web_state_unique);
35
36 ios::ChromeBrowserState* original_browser_state =
37 ios::ChromeBrowserState::FromBrowserState(browser_state_);
38
39 favicon::WebFaviconDriver::CreateForWebState(
40 web_state,
41 ios::FaviconServiceFactory::GetForBrowserState(
42 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
43 ios::HistoryServiceFactory::GetForBrowserState(
44 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
45 ios::BookmarkModelFactory::GetForBrowserState(original_browser_state));
46
47 return web_state;
48 }
49
50 void WebStateDispatcherImpl::ReturnWebState(web::WebState* web_state) {
51 base::WeakPtr<WebStateDispatcherImpl> weak_this =
52 weak_ptr_factory_.GetWeakPtr();
53 dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
54 (int64_t)(kMaxDelayFavicon * NSEC_PER_SEC)),
55 dispatch_get_main_queue(), ^{
56 WebStateDispatcherImpl* web_state_dispatcher =
57 weak_this.get();
58 if (web_state_dispatcher)
59 web_state_dispatcher->web_states_.erase(web_state);
60 });
61 }
62
63 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698