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

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

Issue 6660028: Decouple TabRestoreService from Browser (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add doc references and fix lint 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
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 "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 command_updater_(this), 199 command_updater_(this),
200 toolbar_model_(this), 200 toolbar_model_(this),
201 chrome_updater_factory_(this), 201 chrome_updater_factory_(this),
202 is_attempting_to_close_browser_(false), 202 is_attempting_to_close_browser_(false),
203 cancel_download_confirmation_state_(NOT_PROMPTED), 203 cancel_download_confirmation_state_(NOT_PROMPTED),
204 maximized_state_(MAXIMIZED_STATE_DEFAULT), 204 maximized_state_(MAXIMIZED_STATE_DEFAULT),
205 method_factory_(this), 205 method_factory_(this),
206 block_command_execution_(false), 206 block_command_execution_(false),
207 last_blocked_command_id_(-1), 207 last_blocked_command_id_(-1),
208 last_blocked_command_disposition_(CURRENT_TAB), 208 last_blocked_command_disposition_(CURRENT_TAB),
209 pending_web_app_action_(NONE) { 209 pending_web_app_action_(NONE),
210 tab_restore_service_delegate_(this) {
210 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED, 211 registrar_.Add(this, NotificationType::SSL_VISIBLE_STATE_CHANGED,
211 NotificationService::AllSources()); 212 NotificationService::AllSources());
212 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED, 213 registrar_.Add(this, NotificationType::EXTENSION_UPDATE_DISABLED,
213 NotificationService::AllSources()); 214 NotificationService::AllSources());
214 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 215 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
215 NotificationService::AllSources()); 216 NotificationService::AllSources());
216 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 217 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
217 NotificationService::AllSources()); 218 NotificationService::AllSources());
218 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, 219 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED,
219 NotificationService::AllSources()); 220 NotificationService::AllSources());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 profile_->ResetTabRestoreService(); 293 profile_->ResetTabRestoreService();
293 } 294 }
294 #endif 295 #endif
295 296
296 SessionService* session_service = profile_->GetSessionService(); 297 SessionService* session_service = profile_->GetSessionService();
297 if (session_service) 298 if (session_service)
298 session_service->WindowClosed(session_id_); 299 session_service->WindowClosed(session_id_);
299 300
300 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); 301 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService();
301 if (tab_restore_service) 302 if (tab_restore_service)
302 tab_restore_service->BrowserClosed(this); 303 tab_restore_service->BrowserClosed(tab_restore_service_delegate());
303 304
304 encoding_auto_detect_.Destroy(); 305 encoding_auto_detect_.Destroy();
305 printing_enabled_.Destroy(); 306 printing_enabled_.Destroy();
306 dev_tools_disabled_.Destroy(); 307 dev_tools_disabled_.Destroy();
307 incognito_mode_allowed_.Destroy(); 308 incognito_mode_allowed_.Destroy();
308 instant_enabled_.Destroy(); 309 instant_enabled_.Destroy();
309 use_vertical_tabs_.Destroy(); 310 use_vertical_tabs_.Destroy();
310 311
311 if (profile_->IsOffTheRecord() && 312 if (profile_->IsOffTheRecord() &&
312 !BrowserList::IsOffTheRecordSessionActive()) { 313 !BrowserList::IsOffTheRecordSessionActive()) {
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 exiting = true; 888 exiting = true;
888 } 889 }
889 890
890 // Don't use HasSessionService here, we want to force creation of the 891 // Don't use HasSessionService here, we want to force creation of the
891 // session service so that user can restore what was open. 892 // session service so that user can restore what was open.
892 SessionService* session_service = profile()->GetSessionService(); 893 SessionService* session_service = profile()->GetSessionService();
893 if (session_service) 894 if (session_service)
894 session_service->WindowClosing(session_id()); 895 session_service->WindowClosing(session_id());
895 896
896 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); 897 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService();
897 if (tab_restore_service) 898 if (tab_restore_service && type() == TYPE_NORMAL && tab_count())
898 tab_restore_service->BrowserClosing(this); 899 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
899 900
900 // TODO(sky): convert session/tab restore to use notification. 901 // TODO(sky): convert session/tab restore to use notification.
901 NotificationService::current()->Notify( 902 NotificationService::current()->Notify(
902 NotificationType::BROWSER_CLOSING, 903 NotificationType::BROWSER_CLOSING,
903 Source<Browser>(this), 904 Source<Browser>(this),
904 Details<bool>(&exiting)); 905 Details<bool>(&exiting));
905 906
906 CloseAllTabs(); 907 CloseAllTabs();
907 } 908 }
908 909
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); 960 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index);
960 if (wrapper) 961 if (wrapper)
961 return wrapper->tab_contents(); 962 return wrapper->tab_contents();
962 return NULL; 963 return NULL;
963 } 964 }
964 965
965 void Browser::SelectTabContentsAt(int index, bool user_gesture) { 966 void Browser::SelectTabContentsAt(int index, bool user_gesture) {
966 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture); 967 tab_handler_->GetTabStripModel()->SelectTabContentsAt(index, user_gesture);
967 } 968 }
968 969
970 bool Browser::IsTabPinned(int index) const {
971 return tabstrip_model()->IsTabPinned(index);
972 }
973
969 void Browser::CloseAllTabs() { 974 void Browser::CloseAllTabs() {
970 tab_handler_->GetTabStripModel()->CloseAllTabs(); 975 tab_handler_->GetTabStripModel()->CloseAllTabs();
971 } 976 }
972 977
973 //////////////////////////////////////////////////////////////////////////////// 978 ////////////////////////////////////////////////////////////////////////////////
974 // Browser, Tab adding/showing functions: 979 // Browser, Tab adding/showing functions:
975 980
976 bool Browser::IsTabStripEditable() const { 981 bool Browser::IsTabStripEditable() const {
977 return window()->IsTabStripEditable(); 982 return window()->IsTabStripEditable();
978 } 983 }
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_); 1454 UserMetrics::RecordAction(UserMetricsAction("Duplicate"), profile_);
1450 DuplicateContentsAt(selected_index()); 1455 DuplicateContentsAt(selected_index());
1451 } 1456 }
1452 1457
1453 void Browser::RestoreTab() { 1458 void Browser::RestoreTab() {
1454 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_); 1459 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"), profile_);
1455 TabRestoreService* service = profile_->GetTabRestoreService(); 1460 TabRestoreService* service = profile_->GetTabRestoreService();
1456 if (!service) 1461 if (!service)
1457 return; 1462 return;
1458 1463
1459 service->RestoreMostRecentEntry(this); 1464 service->RestoreMostRecentEntry(tab_restore_service_delegate());
1460 } 1465 }
1461 1466
1462 void Browser::WriteCurrentURLToClipboard() { 1467 void Browser::WriteCurrentURLToClipboard() {
1463 // TODO(ericu): There isn't currently a metric for this. Should there be? 1468 // TODO(ericu): There isn't currently a metric for this. Should there be?
1464 // We don't appear to track the action when it comes from the 1469 // We don't appear to track the action when it comes from the
1465 // RenderContextViewMenu. 1470 // RenderContextViewMenu.
1466 1471
1467 TabContents* contents = GetSelectedTabContents(); 1472 TabContents* contents = GetSelectedTabContents();
1468 if (!contents->ShouldDisplayURL()) 1473 if (!contents->ShouldDisplayURL())
1469 return; 1474 return;
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 // We don't create historical tabs for incognito windows or windows without 2567 // We don't create historical tabs for incognito windows or windows without
2563 // profiles. 2568 // profiles.
2564 if (!profile() || profile()->IsOffTheRecord() || 2569 if (!profile() || profile()->IsOffTheRecord() ||
2565 !profile()->GetTabRestoreService()) { 2570 !profile()->GetTabRestoreService()) {
2566 return; 2571 return;
2567 } 2572 }
2568 2573
2569 // We only create historical tab entries for tabbed browser windows. 2574 // We only create historical tab entries for tabbed browser windows.
2570 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2575 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2571 profile()->GetTabRestoreService()->CreateHistoricalTab( 2576 profile()->GetTabRestoreService()->CreateHistoricalTab(
2572 &contents->controller()); 2577 &contents->controller(),
2578 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents));
2573 } 2579 }
2574 } 2580 }
2575 2581
2576 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { 2582 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) {
2577 return Browser::RunUnloadEventsHelper(contents->tab_contents()); 2583 return Browser::RunUnloadEventsHelper(contents->tab_contents());
2578 } 2584 }
2579 2585
2580 bool Browser::CanReloadContents(TabContents* source) const { 2586 bool Browser::CanReloadContents(TabContents* source) const {
2581 return type() != TYPE_DEVTOOLS; 2587 return type() != TYPE_DEVTOOLS;
2582 } 2588 }
(...skipping 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after
4386 // The page transition below is only for the purpose of inserting the tab. 4392 // The page transition below is only for the purpose of inserting the tab.
4387 browser->AddTab(view_source_contents, PageTransition::LINK); 4393 browser->AddTab(view_source_contents, PageTransition::LINK);
4388 } 4394 }
4389 4395
4390 if (profile_->HasSessionService()) { 4396 if (profile_->HasSessionService()) {
4391 SessionService* session_service = profile_->GetSessionService(); 4397 SessionService* session_service = profile_->GetSessionService();
4392 if (session_service) 4398 if (session_service)
4393 session_service->TabRestored(&view_source_contents->controller(), false); 4399 session_service->TabRestored(&view_source_contents->controller(), false);
4394 } 4400 }
4395 } 4401 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698