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

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

Issue 2529283002: Save favicon during reading list distillation (Closed)
Patch Set: Add constructor comments 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/favicon_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 // Default delay to download the favicon when the WebState is handed back.
17 const int kDefaultDelayFavicon = 10;
18 }
19
20 namespace dom_distiller {
21
22 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl(
23 web::BrowserState* browser_state)
24 : FaviconWebStateDispatcherImpl(browser_state, -1) {}
25 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl(
26 web::BrowserState* browser_state,
27 int keep_alive_time)
28 : FaviconWebStateDispatcher(),
29 browser_state_(browser_state),
30 keep_alive_time_(keep_alive_time),
31 weak_ptr_factory_(this) {}
32 FaviconWebStateDispatcherImpl::~FaviconWebStateDispatcherImpl() {}
33
34 web::WebState* FaviconWebStateDispatcherImpl::RequestWebState() {
35 const web::WebState::CreateParams web_state_create_params(browser_state_);
36 std::unique_ptr<web::WebState> web_state_unique =
37 web::WebState::Create(web_state_create_params);
38 web::WebState* web_state = web_state_unique.get();
39
40 web_states_[web_state] = std::move(web_state_unique);
41
42 ios::ChromeBrowserState* original_browser_state =
43 ios::ChromeBrowserState::FromBrowserState(browser_state_);
44
45 favicon::WebFaviconDriver::CreateForWebState(
46 web_state,
47 ios::FaviconServiceFactory::GetForBrowserState(
48 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
49 ios::HistoryServiceFactory::GetForBrowserState(
50 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS),
51 ios::BookmarkModelFactory::GetForBrowserState(original_browser_state));
52
53 return web_state;
54 }
55
56 void FaviconWebStateDispatcherImpl::ReturnWebState(web::WebState* web_state) {
57 base::WeakPtr<FaviconWebStateDispatcherImpl> weak_this =
58 weak_ptr_factory_.GetWeakPtr();
59 int callback_time =
60 keep_alive_time_ == -1 ? kDefaultDelayFavicon : keep_alive_time_;
61 dispatch_after(
62 dispatch_time(DISPATCH_TIME_NOW, (int64_t)(callback_time * NSEC_PER_SEC)),
63 dispatch_get_main_queue(), ^{
64 FaviconWebStateDispatcherImpl* web_state_dispatcher = weak_this.get();
65 if (web_state_dispatcher)
66 web_state_dispatcher->web_states_.erase(web_state);
67 });
68 }
69
70 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698