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

Side by Side Diff: chrome/browser/history/chrome_history_client.cc

Issue 631253002: Refactor sending NOTIFICATION_HISTORY_URL_VISITED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/history/chrome_history_client.h" 5 #include "chrome/browser/history/chrome_history_client.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/history/history_notifications.h" 9 #include "chrome/browser/history/history_notifications.h"
10 #include "chrome/browser/history/history_service.h"
10 #include "chrome/browser/history/top_sites.h" 11 #include "chrome/browser/history/top_sites.h"
11 #include "chrome/browser/ui/profile_error_dialog.h" 12 #include "chrome/browser/ui/profile_error_dialog.h"
12 #include "chrome/common/chrome_version_info.h" 13 #include "chrome/common/chrome_version_info.h"
13 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "components/bookmarks/browser/bookmark_model.h" 16 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 18
18 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model, 19 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model,
19 Profile* profile, 20 Profile* profile,
20 history::TopSites* top_sites) 21 history::TopSites* top_sites)
21 : bookmark_model_(bookmark_model), 22 : bookmark_model_(bookmark_model),
22 profile_(profile), 23 profile_(profile),
24 history_service_(nullptr),
23 top_sites_(top_sites) { 25 top_sites_(top_sites) {
24 DCHECK(bookmark_model_); 26 DCHECK(bookmark_model_);
25 if (top_sites_) 27 if (top_sites_)
26 top_sites_->AddObserver(this); 28 top_sites_->AddObserver(this);
27 } 29 }
28 30
29 ChromeHistoryClient::~ChromeHistoryClient() { 31 ChromeHistoryClient::~ChromeHistoryClient() {
30 if (top_sites_) 32 if (top_sites_)
31 top_sites_->RemoveObserver(this); 33 top_sites_->RemoveObserver(this);
32 } 34 }
33 35
36 void ChromeHistoryClient::SetHistoryService(HistoryService* history_service) {
37 DCHECK(history_service);
38 history_service_ = history_service;
39 history_service_->AddHistoryServiceObserver(this);
40 }
41
34 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { 42 void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
35 bookmark_model_->BlockTillLoaded(); 43 bookmark_model_->BlockTillLoaded();
36 } 44 }
37 45
38 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { 46 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
39 return bookmark_model_->IsBookmarked(url); 47 return bookmark_model_->IsBookmarked(url);
40 } 48 }
41 49
42 void ChromeHistoryClient::GetBookmarks( 50 void ChromeHistoryClient::GetBookmarks(
43 std::vector<history::URLAndTitle>* bookmarks) { 51 std::vector<history::URLAndTitle>* bookmarks) {
(...skipping 28 matching lines...) Expand all
72 80
73 void ChromeHistoryClient::Shutdown() { 81 void ChromeHistoryClient::Shutdown() {
74 // It's possible that bookmarks haven't loaded and history is waiting for 82 // It's possible that bookmarks haven't loaded and history is waiting for
75 // bookmarks to complete loading. In such a situation history can't shutdown 83 // bookmarks to complete loading. In such a situation history can't shutdown
76 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To 84 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
77 // break the deadlock we tell BookmarkModel it's about to be deleted so that 85 // break the deadlock we tell BookmarkModel it's about to be deleted so that
78 // it can release the signal history is waiting on, allowing history to 86 // it can release the signal history is waiting on, allowing history to
79 // shutdown (HistoryService::Cleanup to complete). In such a scenario history 87 // shutdown (HistoryService::Cleanup to complete). In such a scenario history
80 // sees an incorrect view of bookmarks, but it's better than a deadlock. 88 // sees an incorrect view of bookmarks, but it's better than a deadlock.
81 bookmark_model_->Shutdown(); 89 bookmark_model_->Shutdown();
90 if (history_service_)
91 history_service_->RemoveHistoryServiceObserver(this);
92 }
93
94 void ChromeHistoryClient::OnURLVisited(ui::PageTransition transition,
95 const history::URLRow& row,
96 const history::RedirectList& redirects,
97 const base::Time& visit_time) {
98 scoped_ptr<history::URLVisitedDetails> details(
blundell 2014/10/08 09:59:13 This should have a TODO and bug reference about re
sdefresne 2014/10/09 09:38:15 Done.
99 new history::URLVisitedDetails);
100 details->transition = transition;
101 details->row = row;
102 details->redirects = redirects;
103 details->visit_time = visit_time;
104 content::NotificationService::current()->Notify(
105 chrome::NOTIFICATION_HISTORY_URL_VISITED,
106 content::Source<Profile>(profile_),
107 content::Details<history::HistoryDetails>(details.get()));
82 } 108 }
83 109
84 void ChromeHistoryClient::TopSitesLoaded(history::TopSites* top_sites) { 110 void ChromeHistoryClient::TopSitesLoaded(history::TopSites* top_sites) {
85 content::NotificationService::current()->Notify( 111 content::NotificationService::current()->Notify(
86 chrome::NOTIFICATION_TOP_SITES_LOADED, 112 chrome::NOTIFICATION_TOP_SITES_LOADED,
87 content::Source<Profile>(profile_), 113 content::Source<Profile>(profile_),
88 content::Details<history::TopSites>(top_sites)); 114 content::Details<history::TopSites>(top_sites));
89 } 115 }
90 116
91 void ChromeHistoryClient::TopSitesChanged(history::TopSites* top_sites) { 117 void ChromeHistoryClient::TopSitesChanged(history::TopSites* top_sites) {
92 content::NotificationService::current()->Notify( 118 content::NotificationService::current()->Notify(
93 chrome::NOTIFICATION_TOP_SITES_CHANGED, 119 chrome::NOTIFICATION_TOP_SITES_CHANGED,
94 content::Source<history::TopSites>(top_sites), 120 content::Source<history::TopSites>(top_sites),
95 content::NotificationService::NoDetails()); 121 content::NotificationService::NoDetails());
96 } 122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698