| 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" | |
| 11 #include "chrome/browser/ui/profile_error_dialog.h" | 8 #include "chrome/browser/ui/profile_error_dialog.h" |
| 12 #include "chrome/common/chrome_version_info.h" | 9 #include "chrome/common/chrome_version_info.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 | 13 |
| 18 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model, | 14 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model) |
| 19 Profile* profile, | 15 : bookmark_model_(bookmark_model) { |
| 20 history::TopSites* top_sites) | |
| 21 : bookmark_model_(bookmark_model), | |
| 22 profile_(profile), | |
| 23 top_sites_(top_sites) { | |
| 24 DCHECK(bookmark_model_); | 16 DCHECK(bookmark_model_); |
| 25 if (top_sites_) | |
| 26 top_sites_->AddObserver(this); | |
| 27 } | 17 } |
| 28 | 18 |
| 29 ChromeHistoryClient::~ChromeHistoryClient() { | 19 ChromeHistoryClient::~ChromeHistoryClient() { |
| 30 if (top_sites_) | |
| 31 top_sites_->RemoveObserver(this); | |
| 32 } | 20 } |
| 33 | 21 |
| 34 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { | 22 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { |
| 35 bookmark_model_->BlockTillLoaded(); | 23 bookmark_model_->BlockTillLoaded(); |
| 36 } | 24 } |
| 37 | 25 |
| 38 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { | 26 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { |
| 39 return bookmark_model_->IsBookmarked(url); | 27 return bookmark_model_->IsBookmarked(url); |
| 40 } | 28 } |
| 41 | 29 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void ChromeHistoryClient::Shutdown() { | 61 void ChromeHistoryClient::Shutdown() { |
| 74 // It's possible that bookmarks haven't loaded and history is waiting for | 62 // 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 | 63 // bookmarks to complete loading. In such a situation history can't shutdown |
| 76 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 64 // (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 | 65 // 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 | 66 // it can release the signal history is waiting on, allowing history to |
| 79 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 67 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
| 80 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 68 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
| 81 bookmark_model_->Shutdown(); | 69 bookmark_model_->Shutdown(); |
| 82 } | 70 } |
| 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 |