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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/sessions/tab_restore_service_delegate.h" | 9 #include "chrome/browser/sessions/tab_restore_service_delegate.h" |
9 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 10 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
12 #include "content/browser/tab_contents/tab_contents.h" | 13 #include "content/browser/tab_contents/tab_contents.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 bool IsTabUnique(const DictionaryValue* tab, | 17 bool IsTabUnique(const DictionaryValue* tab, |
17 std::set<std::string>* unique_items) { | 18 std::set<std::string>* unique_items) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", index, 20); | 105 UMA_HISTOGRAM_ENUMERATION("NewTabPage.SessionRestore", index, 20); |
105 | 106 |
106 tab_restore_service_->RestoreEntryById(delegate, session_to_restore, true); | 107 tab_restore_service_->RestoreEntryById(delegate, session_to_restore, true); |
107 // The current tab has been nuked at this point; don't touch any member | 108 // The current tab has been nuked at this point; don't touch any member |
108 // variables. | 109 // variables. |
109 } | 110 } |
110 | 111 |
111 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( | 112 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( |
112 const ListValue* args) { | 113 const ListValue* args) { |
113 if (!tab_restore_service_) { | 114 if (!tab_restore_service_) { |
| 115 Profile* profile = |
| 116 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
114 tab_restore_service_ = | 117 tab_restore_service_ = |
115 TabRestoreServiceFactory::GetForProfile(web_ui_->GetProfile()); | 118 TabRestoreServiceFactory::GetForProfile(profile); |
116 | 119 |
117 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in | 120 // TabRestoreServiceFactory::GetForProfile() can return NULL (i.e., when in |
118 // Off the Record mode) | 121 // Off the Record mode) |
119 if (tab_restore_service_) { | 122 if (tab_restore_service_) { |
120 // This does nothing if the tabs have already been loaded or they | 123 // This does nothing if the tabs have already been loaded or they |
121 // shouldn't be loaded. | 124 // shouldn't be loaded. |
122 tab_restore_service_->LoadTabsFromLastSession(); | 125 tab_restore_service_->LoadTabsFromLastSession(); |
123 | 126 |
124 tab_restore_service_->AddObserver(this); | 127 tab_restore_service_->AddObserver(this); |
125 } | 128 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 (entry->type == TabRestoreService::WINDOW && | 166 (entry->type == TabRestoreService::WINDOW && |
164 WindowToValue( | 167 WindowToValue( |
165 *static_cast<TabRestoreService::Window*>(entry), | 168 *static_cast<TabRestoreService::Window*>(entry), |
166 entry_dict.get()))) { | 169 entry_dict.get()))) { |
167 entry_dict->SetInteger("sessionId", entry->id); | 170 entry_dict->SetInteger("sessionId", entry->id); |
168 entry_list_value->Append(entry_dict.release()); | 171 entry_list_value->Append(entry_dict.release()); |
169 added_count++; | 172 added_count++; |
170 } | 173 } |
171 } | 174 } |
172 } | 175 } |
OLD | NEW |