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

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: 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 "components/bookmarks/core/browser/bookmark_model.h"
9
10 namespace history {
11
12 ChromeHistoryClient::ChromeHistoryClient(Profile* profile)
13 : profile_(profile) {
14 history_service_.reset(new HistoryService(this, profile_));
15 }
16
17 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
18 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_);
19 if (!bookmark_model)
20 return false;
21
22 bookmark_model->BlockTillLoaded();
23 return bookmark_model->IsBookmarked(url);
24 }
25
26 void ChromeHistoryClient::GetBookmarks(std::vector<URLAndTitle>* bookmarks) {
27 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile_);
28 if (bookmark_model) {
29 bookmark_model->BlockTillLoaded();
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 BookmarkModel* bookmark_model =
54 BookmarkModelFactory::GetForProfileIfExists(profile_);
55 if (bookmark_model)
56 bookmark_model->Shutdown();
57
58 history_service_->Cleanup();
59 }
60
61 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698