| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 11 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
| 12 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 12 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 13 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 13 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 14 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 void TabToValue(const TabRestoreService::Tab& tab, | 20 void TabToValue(const TabRestoreService::Tab& tab, |
| 20 DictionaryValue* dictionary) { | 21 DictionaryValue* dictionary) { |
| 21 const TabNavigation& current_navigation = | 22 const TabNavigation& current_navigation = |
| 22 tab.navigations.at(tab.current_navigation_index); | 23 tab.navigations.at(tab.current_navigation_index); |
| 23 NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(), | 24 NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 tab_restore_service_->RemoveObserver(this); | 59 tab_restore_service_->RemoveObserver(this); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { | 62 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { |
| 62 TabRestoreServiceDelegate* delegate = | 63 TabRestoreServiceDelegate* delegate = |
| 63 TabRestoreServiceDelegate::FindDelegateForController( | 64 TabRestoreServiceDelegate::FindDelegateForController( |
| 64 &web_ui_->tab_contents()->controller(), NULL); | 65 &web_ui_->tab_contents()->controller(), NULL); |
| 65 if (!delegate || !tab_restore_service_) | 66 if (!delegate || !tab_restore_service_) |
| 66 return; | 67 return; |
| 67 | 68 |
| 68 int session_to_restore; | 69 double index = -1.0; |
| 69 if (!ExtractIntegerValue(args, &session_to_restore)) | 70 CHECK(args->GetDouble(1, &index)); |
| 70 return; | |
| 71 | 71 |
| 72 const TabRestoreService::Entries& entries = tab_restore_service_->entries(); | |
| 73 int index = 0; | |
| 74 for (TabRestoreService::Entries::const_iterator iter = entries.begin(); | |
| 75 iter != entries.end(); ++iter, ++index) { | |
| 76 if (session_to_restore == (*iter)->id) | |
| 77 break; | |
| 78 } | |
| 79 // There are actually less than 20 restore tab items displayed in the UI. | 72 // There are actually less than 20 restore tab items displayed in the UI. |
| 80 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", index, 20); | 73 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", |
| 74 static_cast<int>(index), 20); |
| 81 | 75 |
| 82 tab_restore_service_->RestoreEntryById(delegate, session_to_restore, true); | 76 double session_to_restore = 0.0; |
| 77 CHECK(args->GetDouble(0, &session_to_restore)); |
| 78 |
| 79 WindowOpenDisposition disposition = |
| 80 web_ui_util::GetDispositionFromClick(args, 2); |
| 81 tab_restore_service_->RestoreEntryById(delegate, |
| 82 static_cast<int>(session_to_restore), |
| 83 disposition); |
| 83 // The current tab has been nuked at this point; don't touch any member | 84 // The current tab has been nuked at this point; don't touch any member |
| 84 // variables. | 85 // variables. |
| 85 } | 86 } |
| 86 | 87 |
| 87 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( | 88 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( |
| 88 const ListValue* args) { | 89 const ListValue* args) { |
| 89 if (!tab_restore_service_) { | 90 if (!tab_restore_service_) { |
| 90 tab_restore_service_ = | 91 tab_restore_service_ = |
| 91 TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_)); | 92 TabRestoreServiceFactory::GetForProfile(Profile::FromWebUI(web_ui_)); |
| 92 | 93 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 DCHECK_EQ(entry->type, TabRestoreService::WINDOW); | 139 DCHECK_EQ(entry->type, TabRestoreService::WINDOW); |
| 139 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), | 140 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), |
| 140 entry_dict.get()); | 141 entry_dict.get()); |
| 141 } | 142 } |
| 142 | 143 |
| 143 entry_dict->SetInteger("sessionId", entry->id); | 144 entry_dict->SetInteger("sessionId", entry->id); |
| 144 entry_list_value->Append(entry_dict.release()); | 145 entry_list_value->Append(entry_dict.release()); |
| 145 added_count++; | 146 added_count++; |
| 146 } | 147 } |
| 147 } | 148 } |
| OLD | NEW |