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

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

Issue 11377: Changes tab restore service to handle restoring closed windows as a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | « no previous file | chrome/browser/browsing_data_remover.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <windows.h> 5 #include <windows.h>
6 #include <shellapi.h> 6 #include <shellapi.h>
7 7
8 #include "chrome/browser/browser.h" 8 #include "chrome/browser/browser.h"
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // chrome won't shutdown cleanly, and may end up crashing when some 182 // chrome won't shutdown cleanly, and may end up crashing when some
183 // thread tries to use the IO thread (or another thread) that is no longer 183 // thread tries to use the IO thread (or another thread) that is no longer
184 // valid. 184 // valid.
185 profile_->ResetTabRestoreService(); 185 profile_->ResetTabRestoreService();
186 } 186 }
187 187
188 SessionService* session_service = profile_->GetSessionService(); 188 SessionService* session_service = profile_->GetSessionService();
189 if (session_service) 189 if (session_service)
190 session_service->WindowClosed(session_id_); 190 session_service->WindowClosed(session_id_);
191 191
192 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService();
193 if (tab_restore_service)
194 tab_restore_service->BrowserClosed(this);
195
192 NotificationService::current()->RemoveObserver( 196 NotificationService::current()->RemoveObserver(
193 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); 197 this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources());
194 198
195 if (profile_->IsOffTheRecord() && 199 if (profile_->IsOffTheRecord() &&
196 !BrowserList::IsOffTheRecordSessionActive()) { 200 !BrowserList::IsOffTheRecordSessionActive()) {
197 // We reuse the OTR cookie store across OTR windows. If the last OTR 201 // We reuse the OTR cookie store across OTR windows. If the last OTR
198 // window is closed, then we want to wipe the cookie store clean, so when 202 // window is closed, then we want to wipe the cookie store clean, so when
199 // an OTR window is open again, it starts with an empty cookie store. This 203 // an OTR window is open again, it starts with an empty cookie store. This
200 // also frees up the memory that the OTR cookies were using. OTR never 204 // also frees up the memory that the OTR cookies were using. OTR never
201 // loads or writes persistent cookies (there is no backing store), so we 205 // loads or writes persistent cookies (there is no backing store), so we
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 436
433 if (BrowserList::size() == 1) 437 if (BrowserList::size() == 1)
434 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); 438 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
435 439
436 // Don't use HasSessionService here, we want to force creation of the 440 // Don't use HasSessionService here, we want to force creation of the
437 // session service so that user can restore what was open. 441 // session service so that user can restore what was open.
438 SessionService* session_service = profile()->GetSessionService(); 442 SessionService* session_service = profile()->GetSessionService();
439 if (session_service) 443 if (session_service)
440 session_service->WindowClosing(session_id()); 444 session_service->WindowClosing(session_id());
441 445
446 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService();
447 if (tab_restore_service)
448 tab_restore_service->BrowserClosing(this);
449
442 CloseAllTabs(); 450 CloseAllTabs();
443 } 451 }
444 452
445 /////////////////////////////////////////////////////////////////////////////// 453 ///////////////////////////////////////////////////////////////////////////////
446 // Browser, Tab adding/showing functions: 454 // Browser, Tab adding/showing functions:
447 455
448 TabContents* Browser::AddTabWithURL( 456 TabContents* Browser::AddTabWithURL(
449 const GURL& url, const GURL& referrer, PageTransition::Type transition, 457 const GURL& url, const GURL& referrer, PageTransition::Type transition,
450 bool foreground, SiteInstance* instance) { 458 bool foreground, SiteInstance* instance) {
451 if (type_ == TYPE_APP && tabstrip_model_.count() == 1) { 459 if (type_ == TYPE_APP && tabstrip_model_.count() == 1) {
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 UserMetrics::RecordAction(L"Duplicate", profile_); 690 UserMetrics::RecordAction(L"Duplicate", profile_);
683 DuplicateContentsAt(selected_index()); 691 DuplicateContentsAt(selected_index());
684 } 692 }
685 693
686 void Browser::RestoreTab() { 694 void Browser::RestoreTab() {
687 UserMetrics::RecordAction(L"RestoreTab", profile_); 695 UserMetrics::RecordAction(L"RestoreTab", profile_);
688 TabRestoreService* service = profile_->GetTabRestoreService(); 696 TabRestoreService* service = profile_->GetTabRestoreService();
689 if (!service) 697 if (!service)
690 return; 698 return;
691 699
692 const TabRestoreService::Tabs& tabs = service->tabs(); 700 service->RestoreMostRecentEntry(this);
693 if (tabs.empty() || tabs.front().from_last_session)
694 return;
695
696 const TabRestoreService::HistoricalTab& tab = tabs.front();
697 AddRestoredTab(tab.navigations, tab_count(), tab.current_navigation_index,
698 true);
699 service->RemoveHistoricalTabById(tab.id);
700 } 701 }
701 702
702 void Browser::ConvertPopupToTabbedBrowser() { 703 void Browser::ConvertPopupToTabbedBrowser() {
703 UserMetrics::RecordAction(L"ShowAsTab", profile_); 704 UserMetrics::RecordAction(L"ShowAsTab", profile_);
704 705
705 if (type() != TYPE_NORMAL) { 706 if (type() != TYPE_NORMAL) {
706 NOTREACHED(); 707 NOTREACHED();
707 return; 708 return;
708 } 709 }
709 710
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 controller_.UpdateCommandEnabled(IDC_EXIT, true); 1946 controller_.UpdateCommandEnabled(IDC_EXIT, true);
1946 // the debugger doesn't work in single process mode 1947 // the debugger doesn't work in single process mode
1947 controller_.UpdateCommandEnabled(IDC_DEBUGGER, 1948 controller_.UpdateCommandEnabled(IDC_DEBUGGER,
1948 !RenderProcessHost::run_renderer_in_process()); 1949 !RenderProcessHost::run_renderer_in_process());
1949 controller_.UpdateCommandEnabled(IDC_DEVELOPER, true); 1950 controller_.UpdateCommandEnabled(IDC_DEVELOPER, true);
1950 controller_.UpdateCommandEnabled(IDC_HELPMENU, true); 1951 controller_.UpdateCommandEnabled(IDC_HELPMENU, true);
1951 } 1952 }
1952 1953
1953 void Browser::UpdateNavigationCommands() { 1954 void Browser::UpdateNavigationCommands() {
1954 TabContents* current_tab = GetSelectedTabContents(); 1955 TabContents* current_tab = GetSelectedTabContents();
1956 if (!current_tab) {
1957 // It's possible for this to be null during tab restore.
1958 return;
1959 }
1960
1955 NavigationController* nc = current_tab->controller(); 1961 NavigationController* nc = current_tab->controller();
1956 controller_.UpdateCommandEnabled(IDC_BACK, nc->CanGoBack()); 1962 controller_.UpdateCommandEnabled(IDC_BACK, nc->CanGoBack());
1957 controller_.UpdateCommandEnabled(IDC_FORWARD, nc->CanGoForward()); 1963 controller_.UpdateCommandEnabled(IDC_FORWARD, nc->CanGoForward());
1958 1964
1959 WebContents* web_contents = current_tab->AsWebContents(); 1965 WebContents* web_contents = current_tab->AsWebContents();
1960 1966
1961 if (web_contents) { 1967 if (web_contents) {
1962 controller_.UpdateCommandEnabled(IDC_STAR, true); 1968 controller_.UpdateCommandEnabled(IDC_STAR, true);
1963 SetStarredButtonToggled(web_contents->is_starred()); 1969 SetStarredButtonToggled(web_contents->is_starred());
1964 1970
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 2351
2346 // We need to register the window position pref. 2352 // We need to register the window position pref.
2347 std::wstring window_pref(prefs::kBrowserWindowPlacement); 2353 std::wstring window_pref(prefs::kBrowserWindowPlacement);
2348 window_pref.append(L"_"); 2354 window_pref.append(L"_");
2349 window_pref.append(app_name); 2355 window_pref.append(app_name);
2350 PrefService* prefs = g_browser_process->local_state(); 2356 PrefService* prefs = g_browser_process->local_state();
2351 DCHECK(prefs); 2357 DCHECK(prefs);
2352 2358
2353 prefs->RegisterDictionaryPref(window_pref.c_str()); 2359 prefs->RegisterDictionaryPref(window_pref.c_str());
2354 } 2360 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data_remover.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698