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 kDefaultDelayFavicon = 10; | |
sdefresne
2016/12/20 15:41:00
Please add unit in the variable name. Like kDefaul
gambard
2016/12/20 17:11:43
Done.
| |
18 } | |
19 | |
20 namespace dom_distiller { | |
21 | |
22 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl( | |
23 web::BrowserState* browser_state) | |
24 : FaviconWebStateDispatcherImpl(browser_state, -1) {} | |
25 FaviconWebStateDispatcherImpl::FaviconWebStateDispatcherImpl( | |
sdefresne
2016/12/20 15:41:00
Please leave an empty line between methods
gambard
2016/12/20 17:11:42
Done.
| |
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() {} | |
sdefresne
2016/12/20 15:41:00
ditto
gambard
2016/12/20 17:11:43
Done.
| |
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); | |
sdefresne
2016/12/20 15:41:00
This is really strange. Do you really need a std::
gambard
2016/12/20 17:11:43
Done.
| |
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)), | |
sdefresne
2016/12/20 15:41:00
C style cast are forbidden by the style guide, use
gambard
2016/12/20 17:11:42
The C style cast is the default snippet for dispat
| |
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 | |
OLD | NEW |