Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc

Issue 11038014: [Android] Upstream remaining changes to NTP UI code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed indentation nit Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc b/chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc
index da09744e60dae6808d26eb6ed504d4edfb1ae5bf..24e00ecf6e2036b19c184e14f75168d7d879a51f 100644
--- a/chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc
+++ b/chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.cc
@@ -57,6 +57,9 @@ void RecentlyClosedTabsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("reopenTab",
base::Bind(&RecentlyClosedTabsHandler::HandleReopenTab,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback("clearRecentlyClosed",
+ base::Bind(&RecentlyClosedTabsHandler::HandleClearRecentlyClosed,
+ base::Unretained(this)));
}
RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
@@ -68,13 +71,6 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
if (!tab_restore_service_)
return;
- double index = -1.0;
- CHECK(args->GetDouble(1, &index));
-
- // There are actually less than 20 restore tab items displayed in the UI.
- UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore",
- static_cast<int>(index), 20);
-
double session_to_restore = 0.0;
CHECK(args->GetDouble(0, &session_to_restore));
@@ -95,6 +91,13 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
SessionRestore::RestoreForeignSessionTab(web_ui()->GetWebContents(),
session_tab, NEW_FOREGROUND_TAB);
#else
+ double index = -1.0;
+ CHECK(args->GetDouble(1, &index));
+
+ // There are actually less than 20 restore tab items displayed in the UI.
+ UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore",
+ static_cast<int>(index), 20);
+
TabRestoreServiceDelegate* delegate =
TabRestoreServiceDelegate::FindDelegateForWebContents(
web_ui()->GetWebContents());
@@ -110,23 +113,16 @@ void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
#endif
}
-void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
+void RecentlyClosedTabsHandler::HandleClearRecentlyClosed(
const ListValue* args) {
- if (!tab_restore_service_) {
- tab_restore_service_ =
- TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
-
- // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in
- // Off the Record mode)
- if (tab_restore_service_) {
- // This does nothing if the tabs have already been loaded or they
- // shouldn't be loaded.
- tab_restore_service_->LoadTabsFromLastSession();
-
- tab_restore_service_->AddObserver(this);
- }
- }
+ EnsureTabRestoreService();
+ if (tab_restore_service_)
+ tab_restore_service_->ClearEntries();
+}
+void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
+ const ListValue* args) {
+ EnsureTabRestoreService();
if (tab_restore_service_)
TabRestoreServiceChanged(tab_restore_service_);
}
@@ -171,3 +167,20 @@ void RecentlyClosedTabsHandler::CreateRecentlyClosedValues(
added_count++;
}
}
+
+void RecentlyClosedTabsHandler::EnsureTabRestoreService() {
+ if (tab_restore_service_)
+ return;
+
+ tab_restore_service_ =
+ TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
+
+ // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in
+ // Off the Record mode)
+ if (tab_restore_service_) {
+ // This does nothing if the tabs have already been loaded or they
+ // shouldn't be loaded.
+ tab_restore_service_->LoadTabsFromLastSession();
+ tab_restore_service_->AddObserver(this);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698