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

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 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
new file mode 100644
index 0000000000000000000000000000000000000000..a39943a70ba426a123b16b170f1aac1550e6b55d
--- /dev/null
+++ b/chrome/browser/history/chrome_history_client.cc
@@ -0,0 +1,59 @@
+// 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 "chrome/browser/history/history_service.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+
+namespace history {
+
+ChromeHistoryClient::ChromeHistoryClient(Profile* profile)
+ : bookmark_model_(NULL) {
+ history_service_.reset(new HistoryService(this, profile));
+ bookmark_model_ = BookmarkModelFactory::GetForProfile(profile);
+}
+
+void ChromeHistoryClient::BlockTillBookmarksLoaded() {
+ if (bookmark_model_)
+ bookmark_model_->BlockTillLoaded();
+}
+
+bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
+ return bookmark_model_ && bookmark_model_->IsBookmarked(url);
+}
+
+void ChromeHistoryClient::GetBookmarks(std::vector<URLAndTitle>* bookmarks) {
+ if (bookmark_model_) {
+ 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.
+ if (bookmark_model_)
+ bookmark_model_->Shutdown();
+
+ history_service_->Cleanup();
+}
+
+} // namespace history

Powered by Google App Engine
This is Rietveld 408576698