| 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/content/browser/web_contents_top_sites_observer.h" | 5 #include "components/history/content/browser/web_contents_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 "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 11 | 12 |
| 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(history::WebContentsTopSitesObserver); | 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(history::WebContentsTopSitesObserver); |
| 13 | 14 |
| 14 namespace history { | 15 namespace history { |
| 15 | 16 |
| 16 // static | 17 // static |
| 17 void WebContentsTopSitesObserver::CreateForWebContents( | 18 void WebContentsTopSitesObserver::CreateForWebContents( |
| 18 content::WebContents* web_contents, | 19 content::WebContents* web_contents, |
| 19 TopSites* top_sites) { | 20 TopSites* top_sites) { |
| 20 DCHECK(web_contents); | 21 DCHECK(web_contents); |
| 21 if (!FromWebContents(web_contents)) { | 22 if (!FromWebContents(web_contents)) { |
| 22 web_contents->SetUserData(UserDataKey(), new WebContentsTopSitesObserver( | 23 web_contents->SetUserData(UserDataKey(), |
| 23 web_contents, top_sites)); | 24 base::WrapUnique(new WebContentsTopSitesObserver( |
| 25 web_contents, top_sites))); |
| 24 } | 26 } |
| 25 } | 27 } |
| 26 | 28 |
| 27 WebContentsTopSitesObserver::WebContentsTopSitesObserver( | 29 WebContentsTopSitesObserver::WebContentsTopSitesObserver( |
| 28 content::WebContents* web_contents, | 30 content::WebContents* web_contents, |
| 29 TopSites* top_sites) | 31 TopSites* top_sites) |
| 30 : content::WebContentsObserver(web_contents), top_sites_(top_sites) { | 32 : content::WebContentsObserver(web_contents), top_sites_(top_sites) { |
| 31 } | 33 } |
| 32 | 34 |
| 33 WebContentsTopSitesObserver::~WebContentsTopSitesObserver() { | 35 WebContentsTopSitesObserver::~WebContentsTopSitesObserver() { |
| 34 } | 36 } |
| 35 | 37 |
| 36 void WebContentsTopSitesObserver::NavigationEntryCommitted( | 38 void WebContentsTopSitesObserver::NavigationEntryCommitted( |
| 37 const content::LoadCommittedDetails& load_details) { | 39 const content::LoadCommittedDetails& load_details) { |
| 38 DCHECK(load_details.entry); | 40 DCHECK(load_details.entry); |
| 39 if (top_sites_) | 41 if (top_sites_) |
| 40 top_sites_->OnNavigationCommitted(load_details.entry->GetURL()); | 42 top_sites_->OnNavigationCommitted(load_details.entry->GetURL()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 } // namespace history | 45 } // namespace history |
| OLD | NEW |