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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/history/chrome_history_client.h"
6
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #include "chrome/browser/history/history_service.h"
9 #include "components/bookmarks/browser/bookmark_model.h"
10
11 namespace history {
12
13 ChromeHistoryClient::ChromeHistoryClient(Profile* profile)
14 : bookmark_model_(NULL) {
15 history_service_.reset(new HistoryService(this, profile));
16 bookmark_model_ = BookmarkModelFactory::GetForProfile(profile);
17 }
18
19 void ChromeHistoryClient::BlockTillBookmarksLoaded() {
20 if (bookmark_model_)
21 bookmark_model_->BlockTillLoaded();
22 }
23
24 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
25 return bookmark_model_ && bookmark_model_->IsBookmarked(url);
26 }
27
28 void ChromeHistoryClient::GetBookmarks(std::vector<URLAndTitle>* bookmarks) {
29 if (bookmark_model_) {
30 std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title;
31 bookmark_model_->GetBookmarks(&bookmarks_url_and_title);
32
33 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
34 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
35 URLAndTitle value = {
36 bookmarks_url_and_title[i].url,
37 bookmarks_url_and_title[i].title,
38 };
39 bookmarks->push_back(value);
40 }
41 }
42 }
43
44 void ChromeHistoryClient::Shutdown() {
45 // It's possible that bookmarks haven't loaded and history is waiting for
46 // bookmarks to complete loading. In such a situation history can't shutdown
47 // (meaning if we invoked history_service_->Cleanup now, we would
48 // deadlock). To break the deadlock we tell BookmarkModel it's about to be
49 // deleted so that it can release the signal history is waiting on, allowing
50 // history to shutdown (history_service_->Cleanup to complete). In such a
51 // scenario history sees an incorrect view of bookmarks, but it's better
52 // than a deadlock.
53 if (bookmark_model_)
54 bookmark_model_->Shutdown();
55
56 history_service_->Cleanup();
57 }
58
59 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698