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

Unified Diff: chrome/browser/history/chrome_history_client.cc

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android unit tests Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/history/chrome_history_client.cc
diff --git a/chrome/browser/history/chrome_history_client.cc b/chrome/browser/history/chrome_history_client.cc
index d6310c8877dba3a05ee40586620174f39d1d26c8..61f4b21fee0bb77b8623a0c7826202365e813f92 100644
--- a/chrome/browser/history/chrome_history_client.cc
+++ b/chrome/browser/history/chrome_history_client.cc
@@ -4,5 +4,44 @@
#include "chrome/browser/history/chrome_history_client.h"
-ChromeHistoryClient::ChromeHistoryClient() {
+#include "base/logging.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+
+ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model)
+ : bookmark_model_(bookmark_model) {
+ DCHECK(bookmark_model_);
+}
+
+void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
+ bookmark_model_->BlockTillLoaded();
+}
+
+bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
+ return bookmark_model_->IsBookmarked(url);
+}
+
+void ChromeHistoryClient::GetBookmarks(
+ std::vector<history::URLAndTitle>* bookmarks) {
+ std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title;
+ bookmark_model_->GetBookmarks(&bookmarks_url_and_title);
+
+ bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
+ for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
+ history::URLAndTitle value = {
+ bookmarks_url_and_title[i].url,
+ bookmarks_url_and_title[i].title,
+ };
+ bookmarks->push_back(value);
+ }
+}
+
+void ChromeHistoryClient::Shutdown() {
+ // It's possible that bookmarks haven't loaded and history is waiting for
+ // bookmarks to complete loading. In such a situation history can't shutdown
+ // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
+ // break the deadlock we tell BookmarkModel it's about to be deleted so that
+ // it can release the signal history is waiting on, allowing history to
+ // shutdown (HistoryService::Cleanup to complete). In such a scenario history
+ // sees an incorrect view of bookmarks, but it's better than a deadlock.
+ bookmark_model_->Shutdown();
}
« no previous file with comments | « chrome/browser/history/chrome_history_client.h ('k') | chrome/browser/history/chrome_history_client_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698