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

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

Issue 10896: Re-do the way browser windows are shown:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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) 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 "chrome/browser/session_restore.h" 5 #include "chrome/browser/session_restore.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // SessionRestoreImpl --------------------------------------------------------- 175 // SessionRestoreImpl ---------------------------------------------------------
176 176
177 // SessionRestoreImpl is responsible for fetching the set of tabs to create 177 // SessionRestoreImpl is responsible for fetching the set of tabs to create
178 // from SessionService. SessionRestoreImpl deletes itself when done. 178 // from SessionService. SessionRestoreImpl deletes itself when done.
179 179
180 class SessionRestoreImpl : public NotificationObserver { 180 class SessionRestoreImpl : public NotificationObserver {
181 public: 181 public:
182 SessionRestoreImpl(Profile* profile, 182 SessionRestoreImpl(Profile* profile,
183 Browser* browser, 183 Browser* browser,
184 bool use_saved_session, 184 bool use_saved_session,
185 int show_command,
186 bool synchronous, 185 bool synchronous,
187 bool clobber_existing_window, 186 bool clobber_existing_window,
188 bool always_create_tabbed_browser, 187 bool always_create_tabbed_browser,
189 const std::vector<GURL>& urls_to_open) 188 const std::vector<GURL>& urls_to_open)
190 : profile_(profile), 189 : profile_(profile),
191 browser_(browser), 190 browser_(browser),
192 show_command_(show_command),
193 use_saved_session_(use_saved_session), 191 use_saved_session_(use_saved_session),
194 synchronous_(synchronous), 192 synchronous_(synchronous),
195 clobber_existing_window_(clobber_existing_window), 193 clobber_existing_window_(clobber_existing_window),
196 always_create_tabbed_browser_(always_create_tabbed_browser), 194 always_create_tabbed_browser_(always_create_tabbed_browser),
197 urls_to_open_(urls_to_open) { 195 urls_to_open_(urls_to_open) {
198 } 196 }
199 197
200 void SessionRestoreImpl::Restore() { 198 void SessionRestoreImpl::Restore() {
201 SessionService* session_service = profile_->GetSessionService(); 199 SessionService* session_service = profile_->GetSessionService();
202 DCHECK(session_service); 200 DCHECK(session_service);
(...skipping 30 matching lines...) Expand all
233 private: 231 private:
234 // Invoked when done with creating all the tabs/browsers. 232 // Invoked when done with creating all the tabs/browsers.
235 // 233 //
236 // |created_tabbed_browser| indicates whether a tabbed browser was created, 234 // |created_tabbed_browser| indicates whether a tabbed browser was created,
237 // or we used an existing tabbed browser. 235 // or we used an existing tabbed browser.
238 // 236 //
239 // If successful, this begins loading tabs and deletes itself when all tabs 237 // If successful, this begins loading tabs and deletes itself when all tabs
240 // have been loaded. 238 // have been loaded.
241 void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) { 239 void FinishedTabCreation(bool succeeded, bool created_tabbed_browser) {
242 if (!created_tabbed_browser && always_create_tabbed_browser_) { 240 if (!created_tabbed_browser && always_create_tabbed_browser_) {
243 Browser* browser = new Browser(gfx::Rect(), show_command_, profile_, 241 Browser* browser = Browser::Create(profile_);
244 BrowserType::TABBED_BROWSER,
245 std::wstring());
246 if (urls_to_open_.empty()) { 242 if (urls_to_open_.empty()) {
247 // No tab browsers were created and no URLs were supplied on the command 243 // No tab browsers were created and no URLs were supplied on the command
248 // line. Add an empty URL, which is treated as opening the users home 244 // line. Add an empty URL, which is treated as opening the users home
249 // page. 245 // page.
250 urls_to_open_.push_back(GURL()); 246 urls_to_open_.push_back(GURL());
251 } 247 }
252 AppendURLsToBrowser(browser, urls_to_open_); 248 AppendURLsToBrowser(browser, urls_to_open_);
253 browser->Show(); 249 browser->window()->Show();
254 } 250 }
255 251
256 if (synchronous_) 252 if (synchronous_)
257 MessageLoop::current()->Quit(); 253 MessageLoop::current()->Quit();
258 254
259 if (succeeded) { 255 if (succeeded) {
260 DCHECK(tab_loader_.get()); 256 DCHECK(tab_loader_.get());
261 // TabLoader delets itself when done loading. 257 // TabLoader delets itself when done loading.
262 tab_loader_.release()->LoadTabs(); 258 tab_loader_.release()->LoadTabs();
263 } 259 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 !clobber_existing_window_) { 292 !clobber_existing_window_) {
297 // If there is an open tabbed browser window, use it. Otherwise fall 293 // If there is an open tabbed browser window, use it. Otherwise fall
298 // through and create a new one. 294 // through and create a new one.
299 browser = current_browser; 295 browser = current_browser;
300 if (browser && (browser->type() != BrowserType::TABBED_BROWSER || 296 if (browser && (browser->type() != BrowserType::TABBED_BROWSER ||
301 browser->profile()->IsOffTheRecord())) { 297 browser->profile()->IsOffTheRecord())) {
302 browser = NULL; 298 browser = NULL;
303 } 299 }
304 } 300 }
305 if (!browser) { 301 if (!browser) {
306 const int show_command = 302 browser = new Browser((*i)->type, profile_);
307 (*i)->is_maximized ? SW_SHOWMAXIMIZED : show_command_; 303 browser->set_override_bounds((*i)->bounds);
308 browser = new Browser((*i)->bounds, show_command, profile_, (*i)->type, 304 browser->set_override_maximized((*i)->is_maximized);
309 std::wstring()); 305 browser->CreateBrowserWindow();
310 } 306 }
311 if ((*i)->type == BrowserType::TABBED_BROWSER) 307 if ((*i)->type == BrowserType::TABBED_BROWSER)
312 last_browser = browser; 308 last_browser = browser;
313 const int initial_tab_count = browser->tab_count(); 309 const int initial_tab_count = browser->tab_count();
314 RestoreTabsToBrowser(*(*i), browser); 310 RestoreTabsToBrowser(*(*i), browser);
315 ShowBrowser(browser, initial_tab_count, (*i)->selected_tab_index); 311 ShowBrowser(browser, initial_tab_count, (*i)->selected_tab_index);
316 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); 312 NotifySessionServiceOfRestoredTabs(browser, initial_tab_count);
317 } 313 }
318 314
319 // If we're restoring a session as the result of a crash and the session 315 // If we're restoring a session as the result of a crash and the session
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (browser_ == browser) { 352 if (browser_ == browser) {
357 browser->SelectTabContentsAt(browser->tab_count() - 1, true); 353 browser->SelectTabContentsAt(browser->tab_count() - 1, true);
358 return; 354 return;
359 } 355 }
360 356
361 DCHECK(browser); 357 DCHECK(browser);
362 DCHECK(browser->tab_count()); 358 DCHECK(browser->tab_count());
363 browser->SelectTabContentsAt( 359 browser->SelectTabContentsAt(
364 std::min(initial_tab_count + std::max(0, selected_session_index), 360 std::min(initial_tab_count + std::max(0, selected_session_index),
365 browser->tab_count() - 1), true); 361 browser->tab_count() - 1), true);
366 browser->Show(); 362 browser->window()->Show();
367 } 363 }
368 364
369 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) { 365 void AppendURLsToBrowser(Browser* browser, const std::vector<GURL>& urls) {
370 for (size_t i = 0; i < urls.size(); ++i) { 366 for (size_t i = 0; i < urls.size(); ++i) {
371 browser->AddTabWithURL(urls[i], GURL(), PageTransition::START_PAGE, 367 browser->AddTabWithURL(urls[i], GURL(), PageTransition::START_PAGE,
372 (i == 0), NULL); 368 (i == 0), NULL);
373 } 369 }
374 } 370 }
375 371
376 // Invokes TabRestored on the SessionService for all tabs in browser after 372 // Invokes TabRestored on the SessionService for all tabs in browser after
377 // initial_count. 373 // initial_count.
378 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) { 374 void NotifySessionServiceOfRestoredTabs(Browser* browser, int initial_count) {
379 SessionService* session_service = profile_->GetSessionService(); 375 SessionService* session_service = profile_->GetSessionService();
380 for (int i = initial_count; i < browser->tab_count(); ++i) 376 for (int i = initial_count; i < browser->tab_count(); ++i)
381 session_service->TabRestored(browser->GetTabContentsAt(i)->controller()); 377 session_service->TabRestored(browser->GetTabContentsAt(i)->controller());
382 } 378 }
383 379
384 // The profile to create the sessions for. 380 // The profile to create the sessions for.
385 Profile* profile_; 381 Profile* profile_;
386 382
387 // The first browser to restore to, may be null. 383 // The first browser to restore to, may be null.
388 Browser* browser_; 384 Browser* browser_;
389 385
390 // Used when creating windows. Passed to the window.
391 const int show_command_;
392
393 // Whether we're restoring the saved session (true) or the last session 386 // Whether we're restoring the saved session (true) or the last session
394 // (false). 387 // (false).
395 const bool use_saved_session_; 388 const bool use_saved_session_;
396 389
397 // Whether or not restore is synchronous. 390 // Whether or not restore is synchronous.
398 const bool synchronous_; 391 const bool synchronous_;
399 392
400 // See description in RestoreSession (in .h). 393 // See description in RestoreSession (in .h).
401 const bool clobber_existing_window_; 394 const bool clobber_existing_window_;
402 395
(...skipping 17 matching lines...) Expand all
420 } // namespace 413 } // namespace
421 414
422 // SessionRestore ------------------------------------------------------------- 415 // SessionRestore -------------------------------------------------------------
423 416
424 // static 417 // static
425 size_t SessionRestore::num_tabs_to_load_ = 0; 418 size_t SessionRestore::num_tabs_to_load_ = 0;
426 419
427 static void Restore(Profile* profile, 420 static void Restore(Profile* profile,
428 Browser* browser, 421 Browser* browser,
429 bool use_saved_session, 422 bool use_saved_session,
430 int show_command,
431 bool synchronous, 423 bool synchronous,
432 bool clobber_existing_window, 424 bool clobber_existing_window,
433 bool always_create_tabbed_browser, 425 bool always_create_tabbed_browser,
434 const std::vector<GURL>& urls_to_open) { 426 const std::vector<GURL>& urls_to_open) {
435 DCHECK(profile); 427 DCHECK(profile);
436 if (!profile->GetSessionService()) 428 if (!profile->GetSessionService())
437 return; 429 return;
438 // SessionRestoreImpl takes care of deleting itself when done. 430 // SessionRestoreImpl takes care of deleting itself when done.
439 SessionRestoreImpl* restorer = 431 SessionRestoreImpl* restorer =
440 new SessionRestoreImpl(profile, browser, use_saved_session, show_command, 432 new SessionRestoreImpl(profile, browser, use_saved_session,
441 synchronous, clobber_existing_window, 433 synchronous, clobber_existing_window,
442 always_create_tabbed_browser, 434 always_create_tabbed_browser,
443 urls_to_open); 435 urls_to_open);
444 restorer->Restore(); 436 restorer->Restore();
445 } 437 }
446 438
447 // static 439 // static
448 void SessionRestore::RestoreSession(Profile* profile, 440 void SessionRestore::RestoreSession(Profile* profile,
449 Browser* browser, 441 Browser* browser,
450 bool use_saved_session, 442 bool use_saved_session,
451 bool clobber_existing_window, 443 bool clobber_existing_window,
452 bool always_create_tabbed_browser, 444 bool always_create_tabbed_browser,
453 const std::vector<GURL>& urls_to_open) { 445 const std::vector<GURL>& urls_to_open) {
454 Restore(profile, browser, use_saved_session, SW_SHOW, false, 446 Restore(profile, browser, use_saved_session, false, clobber_existing_window,
455 clobber_existing_window, always_create_tabbed_browser, urls_to_open); 447 always_create_tabbed_browser, urls_to_open);
456 } 448 }
457 449
458 // static 450 // static
459 void SessionRestore::RestoreSessionSynchronously( 451 void SessionRestore::RestoreSessionSynchronously(
460 Profile* profile, 452 Profile* profile,
461 bool use_saved_session, 453 bool use_saved_session,
462 int show_command,
463 const std::vector<GURL>& urls_to_open) { 454 const std::vector<GURL>& urls_to_open) {
464 Restore(profile, NULL, use_saved_session, SW_SHOW, true, false, true, 455 Restore(profile, NULL, use_saved_session, true, false, true, urls_to_open);
465 urls_to_open);
466 } 456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698