| 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/browser/ui/webui/web_ui_util.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 void TabToValue(const TabRestoreService::Tab& tab, | 20 void TabToValue(const TabRestoreService::Tab& tab, |
| 21 DictionaryValue* dictionary) { | 21 DictionaryValue* dictionary) { |
| 22 const TabNavigation& current_navigation = | 22 const TabNavigation& current_navigation = |
| 23 tab.navigations.at(tab.current_navigation_index); | 23 tab.navigations.at(tab.current_navigation_index); |
| 24 NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(), | 24 NewTabUI::SetURLTitleAndDirection(dictionary, current_navigation.title(), |
| 25 current_navigation.virtual_url()); | 25 current_navigation.virtual_url()); |
| 26 dictionary->SetString("type", "tab"); | 26 dictionary->SetString("type", "tab"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { | 57 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { |
| 58 if (tab_restore_service_) | 58 if (tab_restore_service_) |
| 59 tab_restore_service_->RemoveObserver(this); | 59 tab_restore_service_->RemoveObserver(this); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { | 62 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { |
| 63 TabRestoreServiceDelegate* delegate = | 63 TabRestoreServiceDelegate* delegate = |
| 64 TabRestoreServiceDelegate::FindDelegateForController( | 64 TabRestoreServiceDelegate::FindDelegateForController( |
| 65 &web_ui()->tab_contents()->GetController(), NULL); | 65 &web_ui()->web_contents()->GetController(), NULL); |
| 66 if (!delegate || !tab_restore_service_) | 66 if (!delegate || !tab_restore_service_) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 double index = -1.0; | 69 double index = -1.0; |
| 70 CHECK(args->GetDouble(1, &index)); | 70 CHECK(args->GetDouble(1, &index)); |
| 71 | 71 |
| 72 // 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. |
| 73 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", | 73 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", |
| 74 static_cast<int>(index), 20); | 74 static_cast<int>(index), 20); |
| 75 | 75 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 DCHECK_EQ(entry->type, TabRestoreService::WINDOW); | 139 DCHECK_EQ(entry->type, TabRestoreService::WINDOW); |
| 140 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), | 140 WindowToValue(*static_cast<TabRestoreService::Window*>(entry), |
| 141 entry_dict.get()); | 141 entry_dict.get()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 entry_dict->SetInteger("sessionId", entry->id); | 144 entry_dict->SetInteger("sessionId", entry->id); |
| 145 entry_list_value->Append(entry_dict.release()); | 145 entry_list_value->Append(entry_dict.release()); |
| 146 added_count++; | 146 added_count++; |
| 147 } | 147 } |
| 148 } | 148 } |
| OLD | NEW |