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