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/chrome_notification_types.h" | |
9 #include "chrome/browser/history/history_notifications.h" | |
10 #include "chrome/browser/history/top_sites.h" | |
11 #include "chrome/browser/ui/profile_error_dialog.h" | 8 #include "chrome/browser/ui/profile_error_dialog.h" |
12 #include "chrome/common/chrome_version_info.h" | 9 #include "chrome/common/chrome_version_info.h" |
13 #include "chrome/grit/chromium_strings.h" | 10 #include "chrome/grit/chromium_strings.h" |
14 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
15 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
16 #include "content/public/browser/notification_service.h" | |
17 | 13 |
18 using bookmarks::BookmarkModel; | 14 ChromeHistoryClient::ChromeHistoryClient( |
19 | 15 bookmarks::BookmarkModel* bookmark_model) |
20 ChromeHistoryClient::ChromeHistoryClient(BookmarkModel* bookmark_model, | 16 : bookmark_model_(bookmark_model) { |
21 Profile* profile, | |
22 history::TopSites* top_sites) | |
23 : bookmark_model_(bookmark_model), | |
24 profile_(profile), | |
25 top_sites_(top_sites) { | |
26 DCHECK(bookmark_model_); | 17 DCHECK(bookmark_model_); |
27 if (top_sites_) | |
28 top_sites_->AddObserver(this); | |
29 } | 18 } |
30 | 19 |
31 ChromeHistoryClient::~ChromeHistoryClient() { | 20 ChromeHistoryClient::~ChromeHistoryClient() { |
32 if (top_sites_) | |
33 top_sites_->RemoveObserver(this); | |
34 } | 21 } |
35 | 22 |
36 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { | 23 void ChromeHistoryClient::BlockUntilBookmarksLoaded() { |
37 bookmark_model_->BlockTillLoaded(); | 24 bookmark_model_->BlockTillLoaded(); |
38 } | 25 } |
39 | 26 |
40 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { | 27 bool ChromeHistoryClient::IsBookmarked(const GURL& url) { |
41 return bookmark_model_->IsBookmarked(url); | 28 return bookmark_model_->IsBookmarked(url); |
42 } | 29 } |
43 | 30 |
44 void ChromeHistoryClient::GetBookmarks( | 31 void ChromeHistoryClient::GetBookmarks( |
45 std::vector<history::URLAndTitle>* bookmarks) { | 32 std::vector<history::URLAndTitle>* bookmarks) { |
46 std::vector<BookmarkModel::URLAndTitle> bookmarks_url_and_title; | 33 std::vector<bookmarks::BookmarkModel::URLAndTitle> bookmarks_url_and_title; |
47 bookmark_model_->GetBookmarks(&bookmarks_url_and_title); | 34 bookmark_model_->GetBookmarks(&bookmarks_url_and_title); |
48 | 35 |
49 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size()); | 36 bookmarks->reserve(bookmarks->size() + bookmarks_url_and_title.size()); |
50 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) { | 37 for (size_t i = 0; i < bookmarks_url_and_title.size(); ++i) { |
51 history::URLAndTitle value = { | 38 history::URLAndTitle value = { |
52 bookmarks_url_and_title[i].url, | 39 bookmarks_url_and_title[i].url, |
53 bookmarks_url_and_title[i].title, | 40 bookmarks_url_and_title[i].title, |
54 }; | 41 }; |
55 bookmarks->push_back(value); | 42 bookmarks->push_back(value); |
56 } | 43 } |
(...skipping 18 matching lines...) Expand all Loading... |
75 void ChromeHistoryClient::Shutdown() { | 62 void ChromeHistoryClient::Shutdown() { |
76 // It's possible that bookmarks haven't loaded and history is waiting for | 63 // It's possible that bookmarks haven't loaded and history is waiting for |
77 // bookmarks to complete loading. In such a situation history can't shutdown | 64 // bookmarks to complete loading. In such a situation history can't shutdown |
78 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To | 65 // (meaning if we invoked HistoryService::Cleanup now, we would deadlock). To |
79 // break the deadlock we tell BookmarkModel it's about to be deleted so that | 66 // break the deadlock we tell BookmarkModel it's about to be deleted so that |
80 // it can release the signal history is waiting on, allowing history to | 67 // it can release the signal history is waiting on, allowing history to |
81 // shutdown (HistoryService::Cleanup to complete). In such a scenario history | 68 // shutdown (HistoryService::Cleanup to complete). In such a scenario history |
82 // sees an incorrect view of bookmarks, but it's better than a deadlock. | 69 // sees an incorrect view of bookmarks, but it's better than a deadlock. |
83 bookmark_model_->Shutdown(); | 70 bookmark_model_->Shutdown(); |
84 } | 71 } |
85 | |
86 void ChromeHistoryClient::TopSitesLoaded(history::TopSites* top_sites) { | |
87 content::NotificationService::current()->Notify( | |
88 chrome::NOTIFICATION_TOP_SITES_LOADED, | |
89 content::Source<Profile>(profile_), | |
90 content::Details<history::TopSites>(top_sites)); | |
91 } | |
92 | |
93 void ChromeHistoryClient::TopSitesChanged(history::TopSites* top_sites) { | |
94 content::NotificationService::current()->Notify( | |
95 chrome::NOTIFICATION_TOP_SITES_CHANGED, | |
96 content::Source<history::TopSites>(top_sites), | |
97 content::NotificationService::NoDetails()); | |
98 } | |
OLD | NEW |