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 "base/logging.h" 8 #include "chrome/browser/ui/profile_error_dialog.h" 9 #include "components/bookmarks/browser/bookmark_model.h" 10 #include "grit/chromium_strings.h" 11 #include "grit/generated_resources.h" 12 13 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model) 14 : bookmark_model_(bookmark_model) { 15 DCHECK(bookmark_model_); 16 } 17 18 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { 19 bookmark_model_->BlockTillLoaded(); 20 } 21 22 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { 23 return bookmark_model_->IsBookmarked(url); 24 } 25 26 void ChromeHistoryClient::GetBookmarks( 27 std::vector<history::URLAndTitle>* bookmarks) { 28 std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title; 29 bookmark_model_->GetBookmarks(&bookmarks_url_and_title); 30 31 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size()); 32 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) { 33 history::URLAndTitle value = { 34 bookmarks_url_and_title[i].url, 35 bookmarks_url_and_title[i].title, 36 }; 37 bookmarks->push_back(value); 38 } 39 } 40 41 void ChromeHistoryClient::NotifyProfileError(sql::InitStatus init_status) { 42 ShowProfileErrorDialog( 43 PROFILE_ERROR_HISTORY, 44 (init_status == sql::INIT_FAILURE) ? 45 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 46 } 47 48 void ChromeHistoryClient::Shutdown() { 49 // It's possible that bookmarks haven't loaded and history is waiting for 50 // bookmarks to complete loading. In such a situation history can't shutdown 51 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To 52 // break the deadlock we tell BookmarkModel it's about to be deleted so that 53 // it can release the signal history is waiting on, allowing history to 54 // shutdown (HistoryService::Cleanup to complete). In such a scenario history 55 // sees an incorrect view of bookmarks, but it's better than a deadlock. 56 bookmark_model_->Shutdown(); 57 } 58