OLD | NEW |
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" |
| 9 #include "chrome/browser/history/history_notifications.h" |
| 10 #include "chrome/browser/history/top_sites.h" |
8 #include "chrome/browser/ui/profile_error_dialog.h" | 11 #include "chrome/browser/ui/profile_error_dialog.h" |
9 #include "chrome/common/chrome_version_info.h" | 12 #include "chrome/common/chrome_version_info.h" |
10 #include "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
11 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
12 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "content/public/browser/notification_service.h" |
13 | 17 |
14 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model) | 18 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model, |
15 : bookmark_model_(bookmark_model) { | 19 Profile* profile, |
| 20 history::TopSites* top_sites) |
| 21 : bookmark_model_(bookmark_model), |
| 22 profile_(profile), |
| 23 top_sites_(top_sites) { |
16 DCHECK(bookmark_model_); | 24 DCHECK(bookmark_model_); |
| 25 if (top_sites_) |
| 26 top_sites_->AddObserver(this); |
| 27 } |
| 28 |
| 29 ChromeHistoryClient::~ChromeHistoryClient() { |
| 30 if (top_sites_) |
| 31 top_sites_->RemoveObserver(this); |
17 } | 32 } |
18 | 33 |
19 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { | 34 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { |
20 bookmark_model_->BlockTillLoaded(); | 35 bookmark_model_->BlockTillLoaded(); |
21 } | 36 } |
22 | 37 |
23 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { | 38 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { |
24 return bookmark_model_->IsBookmarked(url); | 39 return bookmark_model_->IsBookmarked(url); |
25 } | 40 } |
26 | 41 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 void ChromeHistoryClient::Shutdown() { | 73 void ChromeHistoryClient::Shutdown() { |
59 // It's possible that bookmarks haven't loaded and history is waiting for | 74 // It's possible that bookmarks haven't loaded and history is waiting for |
60 // bookmarks to complete loading. In such a situation history can't shutdown | 75 // bookmarks to complete loading. In such a situation history can't shutdown |
61 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 76 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To |
62 // break the deadlock we tell BookmarkModel it's about to be deleted so that | 77 // break the deadlock we tell BookmarkModel it's about to be deleted so that |
63 // it can release the signal history is waiting on, allowing history to | 78 // it can release the signal history is waiting on, allowing history to |
64 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 79 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
65 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 80 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
66 bookmark_model_->Shutdown(); | 81 bookmark_model_->Shutdown(); |
67 } | 82 } |
| 83 |
| 84 void ChromeHistoryClient::TopSitesLoaded(history::TopSites* top_sites) { |
| 85 content::NotificationService::current()->Notify( |
| 86 chrome::NOTIFICATION_TOP_SITES_LOADED, |
| 87 content::Source<Profile>(profile_), |
| 88 content::Details<history::TopSites>(top_sites)); |
| 89 } |
| 90 |
| 91 void ChromeHistoryClient::TopSitesChanged(history::TopSites* top_sites) { |
| 92 content::NotificationService::current()->Notify( |
| 93 chrome::NOTIFICATION_TOP_SITES_CHANGED, |
| 94 content::Source<history::TopSites>(top_sites), |
| 95 content::NotificationService::NoDetails()); |
| 96 } |
OLD | NEW |