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

Side by Side Diff: chrome/browser/ui/webui/new_tab_ui.cc

Issue 6660028: Decouple TabRestoreService from Browser (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix mac build and handle NULL in delegate statics Created 9 years, 9 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
« no previous file with comments | « chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/ui/webui/new_tab_ui.h" 7 #include "chrome/browser/ui/webui/new_tab_ui.h"
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/singleton.h" 15 #include "base/singleton.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/metrics/user_metrics.h" 19 #include "chrome/browser/metrics/user_metrics.h"
20 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sessions/session_types.h" 22 #include "chrome/browser/sessions/session_types.h"
23 #include "chrome/browser/sessions/tab_restore_service.h" 23 #include "chrome/browser/sessions/tab_restore_service.h"
24 #include "chrome/browser/sessions/tab_restore_service_delegate.h"
24 #include "chrome/browser/sessions/tab_restore_service_observer.h" 25 #include "chrome/browser/sessions/tab_restore_service_observer.h"
25 #include "chrome/browser/sync/profile_sync_service.h" 26 #include "chrome/browser/sync/profile_sync_service.h"
26 #include "chrome/browser/themes/browser_theme_provider.h" 27 #include "chrome/browser/themes/browser_theme_provider.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/webui/app_launcher_handler.h" 29 #include "chrome/browser/ui/webui/app_launcher_handler.h"
29 #include "chrome/browser/ui/webui/foreign_session_handler.h" 30 #include "chrome/browser/ui/webui/foreign_session_handler.h"
30 #include "chrome/browser/ui/webui/most_visited_handler.h" 31 #include "chrome/browser/ui/webui/most_visited_handler.h"
31 #include "chrome/browser/ui/webui/new_tab_page_sync_handler.h" 32 #include "chrome/browser/ui/webui/new_tab_page_sync_handler.h"
32 #include "chrome/browser/ui/webui/ntp_login_handler.h" 33 #include "chrome/browser/ui/webui/ntp_login_handler.h"
33 #include "chrome/browser/ui/webui/ntp_resource_cache.h" 34 #include "chrome/browser/ui/webui/ntp_resource_cache.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 web_ui_->RegisterMessageCallback("reopenTab", 108 web_ui_->RegisterMessageCallback("reopenTab",
108 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab)); 109 NewCallback(this, &RecentlyClosedTabsHandler::HandleReopenTab));
109 } 110 }
110 111
111 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() { 112 RecentlyClosedTabsHandler::~RecentlyClosedTabsHandler() {
112 if (tab_restore_service_) 113 if (tab_restore_service_)
113 tab_restore_service_->RemoveObserver(this); 114 tab_restore_service_->RemoveObserver(this);
114 } 115 }
115 116
116 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) { 117 void RecentlyClosedTabsHandler::HandleReopenTab(const ListValue* args) {
117 Browser* browser = Browser::GetBrowserForController( 118 TabRestoreServiceDelegate* delegate =
119 TabRestoreServiceDelegate::FindDelegateForController(
118 &web_ui_->tab_contents()->controller(), NULL); 120 &web_ui_->tab_contents()->controller(), NULL);
119 if (!browser) 121 if (!delegate)
120 return; 122 return;
121 123
122 int session_to_restore; 124 int session_to_restore;
123 if (ExtractIntegerValue(args, &session_to_restore)) 125 if (ExtractIntegerValue(args, &session_to_restore))
124 tab_restore_service_->RestoreEntryById(browser, session_to_restore, true); 126 tab_restore_service_->RestoreEntryById(delegate, session_to_restore, true);
125 // The current tab has been nuked at this point; don't touch any member 127 // The current tab has been nuked at this point; don't touch any member
126 // variables. 128 // variables.
127 } 129 }
128 130
129 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs( 131 void RecentlyClosedTabsHandler::HandleGetRecentlyClosedTabs(
130 const ListValue* args) { 132 const ListValue* args) {
131 if (!tab_restore_service_) { 133 if (!tab_restore_service_) {
132 tab_restore_service_ = web_ui_->GetProfile()->GetTabRestoreService(); 134 tab_restore_service_ = web_ui_->GetProfile()->GetTabRestoreService();
133 135
134 // GetTabRestoreService() can return NULL (i.e., when in Off the 136 // GetTabRestoreService() can return NULL (i.e., when in Off the
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 SendResponse(request_id, html_bytes); 597 SendResponse(request_id, html_bytes);
596 } 598 }
597 599
598 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { 600 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const {
599 return "text/html"; 601 return "text/html";
600 } 602 }
601 603
602 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { 604 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const {
603 return false; 605 return false;
604 } 606 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/history_menu_cocoa_controller.mm ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698