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.
5 #include "chrome/browser/history/chrome_history_client.h"
7 #include "base/logging.h"
8 #include "chrome/browser/ui/profile_error_dialog.h"
9 #include "chrome/common/chrome_version_info.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
14 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model)
15 : bookmark_model_(bookmark_model) {
16 DCHECK(bookmark_model_);
19 void ChromeHistoryClient::BlockUntilBookmarksLoaded() {
20 bookmark_model_->BlockTillLoaded();
23 bool ChromeHistoryClient::IsBookmarked(const GURL& url) {
24 return bookmark_model_->IsBookmarked(url);
27 void ChromeHistoryClient::GetBookmarks(
28 std::vector<history::URLAndTitle>* bookmarks) {
29 std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title;
30 bookmark_model_->GetBookmarks(&bookmarks_url_and_title);
32 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size());
33 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) {
34 history::URLAndTitle value = {
35 bookmarks_url_and_title[i].url,
36 bookmarks_url_and_title[i].title,
38 bookmarks->push_back(value);
42 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) {
43 ShowProfileErrorDialog(
44 PROFILE_ERROR_HISTORY,
45 (init_status == sql::INIT_FAILURE) ?
46 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
49 bool ChromeHistoryClient::ShouldReportDatabaseError() {
50 // TODO(shess): For now, don't report on beta or stable so as not to
51 // overwhelm the crash server. Once the big fish are fried,
52 // consider reporting at a reduced rate on the bigger channels.
53 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
54 return channel != chrome::VersionInfo::CHANNEL_STABLE &&
55 channel != chrome::VersionInfo::CHANNEL_BETA;
58 void ChromeHistoryClient::Shutdown() {
59 // It's possible that bookmarks haven't loaded and history is waiting for
60 // bookmarks to complete loading. In such a situation history can't shutdown
61 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To
62 // break the deadlock we tell BookmarkModel it's about to be deleted so that
63 // it can release the signal history is waiting on, allowing history to
64 // shutdown (HistoryService::Cleanup to complete). In such a scenario history
65 // sees an incorrect view of bookmarks, but it's better than a deadlock.
66 bookmark_model_->Shutdown();