summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui/new_tab_ui.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/dom_ui/new_tab_ui.cc')
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc56
1 files changed, 41 insertions, 15 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index ef36f49..58ce89d 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -518,37 +518,63 @@ void TemplateURLHandler::OnTemplateURLModelChanged() {
}
RecentlyBookmarkedHandler::RecentlyBookmarkedHandler(DOMUIHost* dom_ui_host)
- : dom_ui_host_(dom_ui_host) {
+ : dom_ui_host_(dom_ui_host),
+ model_(NULL) {
dom_ui_host->RegisterMessageCallback("getRecentlyBookmarked",
NewCallback(this,
&RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked));
}
+RecentlyBookmarkedHandler::~RecentlyBookmarkedHandler() {
+ if (model_)
+ model_->RemoveObserver(this);
+}
+
void RecentlyBookmarkedHandler::HandleGetRecentlyBookmarked(const Value*) {
- HistoryService* hs =
- dom_ui_host_->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
- if (hs) {
- HistoryService::Handle handle = hs->GetMostRecentStarredEntries(
- kRecentBookmarks,
- &cancelable_consumer_,
- NewCallback(this,
- &RecentlyBookmarkedHandler::OnMostRecentStarredEntries));
+ if (!model_) {
+ model_ = dom_ui_host_->profile()->GetBookmarkBarModel();
+ model_->AddObserver(this);
}
+ // If the model is loaded, synchronously send the bookmarks down. Otherwise
+ // when the model loads we'll send the bookmarks down.
+ if (model_->IsLoaded())
+ SendBookmarksToPage();
}
-void RecentlyBookmarkedHandler::OnMostRecentStarredEntries(
- HistoryService::Handle request_handle,
- std::vector<history::StarredEntry>* entries) {
+void RecentlyBookmarkedHandler::SendBookmarksToPage() {
+ std::vector<BookmarkBarNode*> recently_bookmarked;
+ model_->GetMostRecentlyAddedEntries(kRecentBookmarks, &recently_bookmarked);
ListValue list_value;
- for (size_t i = 0; i < entries->size(); ++i) {
- const history::StarredEntry& entry = (*entries)[i];
+ for (size_t i = 0; i < recently_bookmarked.size(); ++i) {
+ BookmarkBarNode* node = recently_bookmarked[i];
DictionaryValue* entry_value = new DictionaryValue;
- SetURLAndTitle(entry_value, entry.title, entry.url);
+ SetURLAndTitle(entry_value, node->GetTitle(), node->GetURL());
list_value.Append(entry_value);
}
dom_ui_host_->CallJavascriptFunction(L"recentlyBookmarked", list_value);
}
+void RecentlyBookmarkedHandler::Loaded(BookmarkBarModel* model) {
+ SendBookmarksToPage();
+}
+
+void RecentlyBookmarkedHandler::BookmarkNodeAdded(BookmarkBarModel* model,
+ BookmarkBarNode* parent,
+ int index) {
+ SendBookmarksToPage();
+}
+
+void RecentlyBookmarkedHandler::BookmarkNodeRemoved(BookmarkBarModel* model,
+ BookmarkBarNode* parent,
+ int index) {
+ SendBookmarksToPage();
+}
+
+void RecentlyBookmarkedHandler::BookmarkNodeChanged(BookmarkBarModel* model,
+ BookmarkBarNode* node) {
+ SendBookmarksToPage();
+}
+
RecentlyClosedTabsHandler::RecentlyClosedTabsHandler(DOMUIHost* dom_ui_host)
: dom_ui_host_(dom_ui_host),
tab_restore_service_(NULL),