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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/ntp/recently_closed_tabs_handler.h" 5 #include "chrome/browser/ui/webui/ntp/recently_closed_tabs_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 } // namespace 51 } // namespace
52 52
53 void RecentlyClosedTabsHandler::RegisterMessages() { 53 void RecentlyClosedTabsHandler::RegisterMessages() {
54 web_ui()->RegisterMessageCallback("getRecentlyClosedTabs", 54 web_ui()->RegisterMessageCallback("getRecentlyClosedTabs",
55 base::Bind(&RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs, 55 base::Bind(&RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs,
56 base::Unretained(this))); 56 base::Unretained(this)));
57 web_ui()->RegisterMessageCallback("reopenTab", 57 web_ui()->RegisterMessageCallback("reopenTab",
58 base::Bind(&RecentlyClosedTabsHandler::HandleReopenTab, 58 base::Bind(&RecentlyClosedTabsHandler::HandleReopenTab,
59 base::Unretained(this))); 59 base::Unretained(this)));
60 web_ui()->RegisterMessageCallback("clearRecentlyClosed",
61 base::Bind(&RecentlyClosedTabsHandler::HandleClearRecentlyClosed,
62 base::Unretained(this)));
60 } 63 }
61 64
62 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { 65 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
63 if (tab_restore_service_) 66 if (tab_restore_service_)
64 tab_restore_service_->RemoveObserver(this); 67 tab_restore_service_->RemoveObserver(this);
65 } 68 }
66 69
67 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { 70 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
68 if (!tab_restore_service_) 71 if (!tab_restore_service_)
69 return; 72 return;
70 73
71 double index = -1.0;
72 CHECK(args->GetDouble(1, &index));
73
74 // There are actually less than 20 restore tab items displayed in the UI.
75 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore",
76 static_cast<int>(index), 20);
77
78 double session_to_restore = 0.0; 74 double session_to_restore = 0.0;
79 CHECK(args->GetDouble(0, &session_to_restore)); 75 CHECK(args->GetDouble(0, &session_to_restore));
80 76
81 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
82 // Find and remove the corresponding tab entry from TabRestoreService. 78 // Find and remove the corresponding tab entry from TabRestoreService.
83 // We take ownership of the returned tab. 79 // We take ownership of the returned tab.
84 scoped_ptr<TabRestoreService::Tab> tab_entry( 80 scoped_ptr<TabRestoreService::Tab> tab_entry(
85 tab_restore_service_->RemoveTabEntryById(static_cast<int>( 81 tab_restore_service_->RemoveTabEntryById(static_cast<int>(
86 session_to_restore))); 82 session_to_restore)));
87 if (tab_entry.get() == NULL) 83 if (tab_entry.get() == NULL)
88 return; 84 return;
89 85
90 // RestoreForeignSessionTab needs a SessionTab. 86 // RestoreForeignSessionTab needs a SessionTab.
91 SessionTab session_tab; 87 SessionTab session_tab;
92 session_tab.current_navigation_index = tab_entry->current_navigation_index; 88 session_tab.current_navigation_index = tab_entry->current_navigation_index;
93 session_tab.navigations = tab_entry->navigations; 89 session_tab.navigations = tab_entry->navigations;
94 90
95 SessionRestore::RestoreForeignSessionTab(web_ui()->GetWebContents(), 91 SessionRestore::RestoreForeignSessionTab(web_ui()->GetWebContents(),
96 session_tab, NEW_FOREGROUND_TAB); 92 session_tab, NEW_FOREGROUND_TAB);
97 #else 93 #else
94 double index = -1.0;
95 CHECK(args->GetDouble(1, &index));
96
97 // There are actually less than 20 restore tab items displayed in the UI.
98 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore",
99 static_cast<int>(index), 20);
100
98 TabRestoreServiceDelegate* delegate = 101 TabRestoreServiceDelegate* delegate =
99 TabRestoreServiceDelegate::FindDelegateForWebContents( 102 TabRestoreServiceDelegate::FindDelegateForWebContents(
100 web_ui()->GetWebContents()); 103 web_ui()->GetWebContents());
101 if (!delegate) 104 if (!delegate)
102 return; 105 return;
103 WindowOpenDisposition disposition = 106 WindowOpenDisposition disposition =
104 web_ui_util::GetDispositionFromClick(args, 2); 107 web_ui_util::GetDispositionFromClick(args, 2);
105 tab_restore_service_->RestoreEntryById(delegate, 108 tab_restore_service_->RestoreEntryById(delegate,
106 static_cast<int>(session_to_restore), 109 static_cast<int>(session_to_restore),
107 disposition); 110 disposition);
108 // The current tab has been nuked at this point; don't touch any member 111 // The current tab has been nuked at this point; don't touch any member
109 // variables. 112 // variables.
110 #endif 113 #endif
111 } 114 }
112 115
116 void RecentlyClosedTabsHandler::HandleClearRecentlyClosed(
117 const ListValue* args) {
118 if (tab_restore_service_)
newt (away) 2012/10/02 13:07:31 Not totally sure about this. If tab_restore_servi
Evan Stade 2012/10/02 14:42:43 pull out an EnsureTabRestoreService function that
newt (away) 2012/10/05 13:31:05 Done.
119 tab_restore_service_->ClearEntries();
120 }
121
113 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( 122 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
114 const ListValue* args) { 123 const ListValue* args) {
115 if (!tab_restore_service_) { 124 if (!tab_restore_service_) {
116 tab_restore_service_ = 125 tab_restore_service_ =
117 TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 126 TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
118 127
119 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in 128 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in
120 // Off the Record mode) 129 // Off the Record mode)
121 if (tab_restore_service_) { 130 if (tab_restore_service_) {
122 // This does nothing if the tabs have already been loaded or they 131 // This does nothing if the tabs have already been loaded or they
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 DCHECK_EQ(entry->type, TabRestoreService::WINDOW); 173 DCHECK_EQ(entry->type, TabRestoreService::WINDOW);
165 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), 174 WindowToValue(*static_cast<TabRestoreService::Window*>(entry),
166 entry_dict.get()); 175 entry_dict.get());
167 } 176 }
168 177
169 entry_dict->SetInteger("sessionId", entry->id); 178 entry_dict->SetInteger("sessionId", entry->id);
170 entry_list_value->Append(entry_dict.release()); 179 entry_list_value->Append(entry_dict.release());
171 added_count++; 180 added_count++;
172 } 181 }
173 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698