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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..64c9f0ffa040039238c890d5a263fe056321fc9f |
--- /dev/null |
+++ b/chrome/browser/history/chrome_history_client.cc |
@@ -0,0 +1,61 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/history/chrome_history_client.h" |
+ |
+#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
+#include "components/bookmarks/core/browser/bookmark_model.h" |
+ |
+namespace history { |
+ |
+ChromeHistoryClient::ChromeHistoryClient(Profile* profile) |
+ : profile_(profile) { |
+ history_service_.reset(new HistoryService(this, profile_)); |
+} |
+ |
+bool ChromeHistoryClient::IsBookmarked(const GURL& url) { |
+ BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
+ if (!bookmark_model) |
+ return false; |
+ |
+ bookmark_model->BlockTillLoaded(); |
+ return bookmark_model->IsBookmarked(url); |
+} |
+ |
+void ChromeHistoryClient::GetBookmarks(std::vector<URLAndTitle>* bookmarks) { |
+ BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_); |
+ if (bookmark_model) { |
+ bookmark_model->BlockTillLoaded(); |
+ 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) { |
+ 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 history_service_->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 (history_service_->Cleanup to complete). In such a |
+ // scenario history sees an incorrect view of bookmarks, but it's better |
+ // than a deadlock. |
+ BookmarkModel* bookmark_model = |
+ BookmarkModelFactory::GetForProfileIfExists(profile_); |
+ if (bookmark_model) |
+ bookmark_model->Shutdown(); |
+ |
+ history_service_->Cleanup(); |
+} |
+ |
+} // namespace history |