OLD | NEW |
---|---|
(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 kDefaultDelayFaviconSecond = 10; | |
18 } | |
19 | |
20 namespace dom_distiller { | |
21 | |
22 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl( | |
23 web::BrowserState* browser_state) | |
24 : FaviconWebStateDispatcherImpl(browser_state, -1) {} | |
25 | |
26 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl( | |
27 web::BrowserState* browser_state, | |
28 int keep_alive_time_second) | |
29 : FaviconWebStateDispatcher(), | |
30 browser_state_(browser_state), | |
31 keep_alive_time_second_(keep_alive_time_second), | |
Eugene But (OOO till 7-30)
2016/12/20 17:36:18
How about this?:
keep_alive_time_second_(kDefaultD
sdefresne
2016/12/20 18:05:31
I think you wanted to write:
keep_alive_time_se
Eugene But (OOO till 7-30)
2016/12/20 18:59:02
Sorry. I wanted to suggest changing the first cons
| |
32 weak_ptr_factory_(this) {} | |
33 | |
34 FaviconWebStateDispatcherImpl::~FaviconWebStateDispatcherImpl() {} | |
35 | |
36 web::WebState* FaviconWebStateDispatcherImpl::RequestWebState() { | |
37 const web::WebState::CreateParams web_state_create_params(browser_state_); | |
38 std::unique_ptr<web::WebState> web_state_unique = | |
sdefresne
2016/12/20 18:05:31
To avoid creating two local variables, I would do
gambard
2016/12/21 08:42:52
Acknowledged.
| |
39 web::WebState::Create(web_state_create_params); | |
40 web::WebState* web_state = web_state_unique.get(); | |
41 | |
42 web_states_.push_back(std::move(web_state_unique)); | |
43 | |
44 ios::ChromeBrowserState* original_browser_state = | |
45 ios::ChromeBrowserState::FromBrowserState(browser_state_); | |
46 | |
47 favicon::WebFaviconDriver::CreateForWebState( | |
48 web_state, | |
49 ios::FaviconServiceFactory::GetForBrowserState( | |
50 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS), | |
51 ios::HistoryServiceFactory::GetForBrowserState( | |
52 original_browser_state, ServiceAccessType::EXPLICIT_ACCESS), | |
53 ios::BookmarkModelFactory::GetForBrowserState(original_browser_state)); | |
54 | |
55 return web_state; | |
56 } | |
57 | |
58 void FaviconWebStateDispatcherImpl::ReturnWebState(web::WebState* web_state) { | |
59 base::WeakPtr<FaviconWebStateDispatcherImpl> weak_this = | |
60 weak_ptr_factory_.GetWeakPtr(); | |
61 int callback_time = keep_alive_time_second_ < 0 ? kDefaultDelayFaviconSecond | |
sdefresne
2016/12/20 18:05:31
I like eugenebut@ suggestion of doing the check in
gambard
2016/12/21 08:42:52
Done.
Making the constructor take a int64_t as arg
| |
62 : keep_alive_time_second_; | |
63 dispatch_after( | |
64 dispatch_time(DISPATCH_TIME_NOW, | |
65 static_cast<int64_t>(callback_time * NSEC_PER_SEC)), | |
66 dispatch_get_main_queue(), ^{ | |
67 FaviconWebStateDispatcherImpl* web_state_dispatcher = weak_this.get(); | |
68 if (web_state_dispatcher) { | |
69 auto it = find_if( | |
70 web_state_dispatcher->web_states_.begin(), | |
71 web_state_dispatcher->web_states_.end(), | |
72 [web_state](std::unique_ptr<web::WebState>& unique_web_state) { | |
73 return unique_web_state.get() == web_state; | |
74 }); | |
sdefresne
2016/12/20 18:05:31
I think you can DCHECK here:
DCHECK(it != web_s
gambard
2016/12/21 08:42:52
Acknowledged.
| |
75 if (it != web_state_dispatcher->web_states_.end()) | |
76 web_state_dispatcher->web_states_.erase(it); | |
77 } | |
78 }); | |
79 } | |
80 | |
81 } // namespace dom_distiller | |
OLD | NEW |