OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/history/ios/browser/web_state_top_sites_observer.h" | 5 #include "components/history/ios/browser/web_state_top_sites_observer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "components/history/core/browser/top_sites.h" | 9 #include "components/history/core/browser/top_sites.h" |
9 #include "ios/web/public/load_committed_details.h" | 10 #include "ios/web/public/load_committed_details.h" |
10 #include "ios/web/public/navigation_item.h" | 11 #include "ios/web/public/navigation_item.h" |
11 | 12 |
12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
13 #error "This file requires ARC support." | 14 #error "This file requires ARC support." |
14 #endif | 15 #endif |
15 | 16 |
16 DEFINE_WEB_STATE_USER_DATA_KEY(history::WebStateTopSitesObserver); | 17 DEFINE_WEB_STATE_USER_DATA_KEY(history::WebStateTopSitesObserver); |
17 | 18 |
18 namespace history { | 19 namespace history { |
19 | 20 |
20 // static | 21 // static |
21 void WebStateTopSitesObserver::CreateForWebState(web::WebState* web_state, | 22 void WebStateTopSitesObserver::CreateForWebState(web::WebState* web_state, |
22 TopSites* top_sites) { | 23 TopSites* top_sites) { |
23 DCHECK(web_state); | 24 DCHECK(web_state); |
24 if (!FromWebState(web_state)) { | 25 if (!FromWebState(web_state)) { |
25 web_state->SetUserData(UserDataKey(), | 26 web_state->SetUserData( |
26 new WebStateTopSitesObserver(web_state, top_sites)); | 27 UserDataKey(), |
| 28 base::WrapUnique(new WebStateTopSitesObserver(web_state, top_sites))); |
27 } | 29 } |
28 } | 30 } |
29 | 31 |
30 WebStateTopSitesObserver::WebStateTopSitesObserver(web::WebState* web_state, | 32 WebStateTopSitesObserver::WebStateTopSitesObserver(web::WebState* web_state, |
31 TopSites* top_sites) | 33 TopSites* top_sites) |
32 : web::WebStateObserver(web_state), top_sites_(top_sites) { | 34 : web::WebStateObserver(web_state), top_sites_(top_sites) { |
33 } | 35 } |
34 | 36 |
35 WebStateTopSitesObserver::~WebStateTopSitesObserver() { | 37 WebStateTopSitesObserver::~WebStateTopSitesObserver() { |
36 } | 38 } |
37 | 39 |
38 void WebStateTopSitesObserver::NavigationItemCommitted( | 40 void WebStateTopSitesObserver::NavigationItemCommitted( |
39 const web::LoadCommittedDetails& load_details) { | 41 const web::LoadCommittedDetails& load_details) { |
40 DCHECK(load_details.item); | 42 DCHECK(load_details.item); |
41 if (top_sites_) | 43 if (top_sites_) |
42 top_sites_->OnNavigationCommitted(load_details.item->GetURL()); | 44 top_sites_->OnNavigationCommitted(load_details.item->GetURL()); |
43 } | 45 } |
44 | 46 |
45 } // namespace history | 47 } // namespace history |
OLD | NEW |