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

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

Issue 519090: Changes synchronous session restore to create windows after nested... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 11 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 | « no previous file | no next file » | 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 "chrome/browser/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/stl_util-inl.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
13 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
14 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/browser_window.h" 16 #include "chrome/browser/browser_window.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/browser/sessions/session_service.h" 18 #include "chrome/browser/sessions/session_service.h"
18 #include "chrome/browser/sessions/session_types.h" 19 #include "chrome/browser/sessions/session_types.h"
19 #include "chrome/browser/tab_contents/navigation_controller.h" 20 #include "chrome/browser/tab_contents/navigation_controller.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 185
185 void Restore() { 186 void Restore() {
186 SessionService* session_service = profile_->GetSessionService(); 187 SessionService* session_service = profile_->GetSessionService();
187 DCHECK(session_service); 188 DCHECK(session_service);
188 SessionService::LastSessionCallback* callback = 189 SessionService::LastSessionCallback* callback =
189 NewCallback(this, &SessionRestoreImpl::OnGotSession); 190 NewCallback(this, &SessionRestoreImpl::OnGotSession);
190 session_service->GetLastSession(&request_consumer_, callback); 191 session_service->GetLastSession(&request_consumer_, callback);
191 192
192 if (synchronous_) { 193 if (synchronous_) {
193 MessageLoop::current()->Run(); 194 MessageLoop::current()->Run();
195 ProcessSessionWindows(&windows_);
194 delete this; 196 delete this;
195 return; 197 return;
196 } 198 }
197 199
198 if (browser_) { 200 if (browser_) {
199 registrar_.Add(this, NotificationType::BROWSER_CLOSED, 201 registrar_.Add(this, NotificationType::BROWSER_CLOSED,
200 Source<Browser>(browser_)); 202 Source<Browser>(browser_));
201 } 203 }
202 } 204 }
203 205
204 ~SessionRestoreImpl() { 206 ~SessionRestoreImpl() {
207 STLDeleteElements(&windows_);
205 } 208 }
206 209
207 virtual void Observe(NotificationType type, 210 virtual void Observe(NotificationType type,
208 const NotificationSource& source, 211 const NotificationSource& source,
209 const NotificationDetails& details) { 212 const NotificationDetails& details) {
210 if (type != NotificationType::BROWSER_CLOSED) { 213 if (type != NotificationType::BROWSER_CLOSED) {
211 NOTREACHED(); 214 NOTREACHED();
212 return; 215 return;
213 } 216 }
214 delete this; 217 delete this;
(...skipping 16 matching lines...) Expand all
231 if (urls_to_open_.empty()) { 234 if (urls_to_open_.empty()) {
232 // No tab browsers were created and no URLs were supplied on the command 235 // No tab browsers were created and no URLs were supplied on the command
233 // line. Add an empty URL, which is treated as opening the users home 236 // line. Add an empty URL, which is treated as opening the users home
234 // page. 237 // page.
235 urls_to_open_.push_back(GURL()); 238 urls_to_open_.push_back(GURL());
236 } 239 }
237 AppendURLsToBrowser(browser, urls_to_open_, honor_pin_tabs); 240 AppendURLsToBrowser(browser, urls_to_open_, honor_pin_tabs);
238 browser->window()->Show(); 241 browser->window()->Show();
239 } 242 }
240 243
241 if (synchronous_)
242 MessageLoop::current()->Quit();
243
244 if (succeeded) { 244 if (succeeded) {
245 DCHECK(tab_loader_.get()); 245 DCHECK(tab_loader_.get());
246 // TabLoader delets itself when done loading. 246 // TabLoader delets itself when done loading.
247 tab_loader_.release()->LoadTabs(); 247 tab_loader_.release()->LoadTabs();
248 } 248 }
249 249
250 if (!synchronous_) { 250 if (!synchronous_) {
251 // If we're not synchronous we need to delete ourself. 251 // If we're not synchronous we need to delete ourself.
252 // NOTE: we must use DeleteLater here as most likely we're in a callback 252 // NOTE: we must use DeleteLater here as most likely we're in a callback
253 // from the history service which doesn't deal well with deleting the 253 // from the history service which doesn't deal well with deleting the
254 // object it is notifying. 254 // object it is notifying.
255 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 255 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
256 } 256 }
257 } 257 }
258 258
259 void OnGotSession(SessionService::Handle handle, 259 void OnGotSession(SessionService::Handle handle,
260 std::vector<SessionWindow*>* windows) { 260 std::vector<SessionWindow*>* windows) {
261 if (synchronous_) {
262 // See comment above windows_ as to why we don't process immediately.
263 windows_.swap(*windows);
264 MessageLoop::current()->Quit();
265 return;
266 }
267 ProcessSessionWindows(windows);
268 }
269
270 void ProcessSessionWindows(std::vector<SessionWindow*>* windows) {
261 if (windows->empty()) { 271 if (windows->empty()) {
262 // Restore was unsuccessful. 272 // Restore was unsuccessful.
263 FinishedTabCreation(false, false); 273 FinishedTabCreation(false, false);
264 return; 274 return;
265 } 275 }
266 276
267 tab_loader_.reset(new TabLoader()); 277 tab_loader_.reset(new TabLoader());
268 278
269 Browser* current_browser = 279 Browser* current_browser =
270 browser_ ? browser_ : BrowserList::GetLastActive(); 280 browser_ ? browser_ : BrowserList::GetLastActive();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 420
411 // Set of URLs to open in addition to those restored from the session. 421 // Set of URLs to open in addition to those restored from the session.
412 std::vector<GURL> urls_to_open_; 422 std::vector<GURL> urls_to_open_;
413 423
414 // Used to get the session. 424 // Used to get the session.
415 CancelableRequestConsumer request_consumer_; 425 CancelableRequestConsumer request_consumer_;
416 426
417 // Responsible for loading the tabs. 427 // Responsible for loading the tabs.
418 scoped_ptr<TabLoader> tab_loader_; 428 scoped_ptr<TabLoader> tab_loader_;
419 429
430 // When synchronous we run a nested message loop. To avoid creating windows
431 // from the nested message loop (which can make exiting the nested message
432 // loop take a while) we cache the SessionWindows here and create the actual
433 // windows when the nested message loop exits.
434 std::vector<SessionWindow*> windows_;
435
420 NotificationRegistrar registrar_; 436 NotificationRegistrar registrar_;
421 }; 437 };
422 438
423 } // namespace 439 } // namespace
424 440
425 // SessionRestore ------------------------------------------------------------- 441 // SessionRestore -------------------------------------------------------------
426 442
427 // static 443 // static
428 size_t SessionRestore::num_tabs_to_load_ = 0; 444 size_t SessionRestore::num_tabs_to_load_ = 0;
429 445
(...skipping 29 matching lines...) Expand all
459 Restore(profile, browser, false, clobber_existing_window, 475 Restore(profile, browser, false, clobber_existing_window,
460 always_create_tabbed_browser, urls_to_open); 476 always_create_tabbed_browser, urls_to_open);
461 } 477 }
462 478
463 // static 479 // static
464 void SessionRestore::RestoreSessionSynchronously( 480 void SessionRestore::RestoreSessionSynchronously(
465 Profile* profile, 481 Profile* profile,
466 const std::vector<GURL>& urls_to_open) { 482 const std::vector<GURL>& urls_to_open) {
467 Restore(profile, NULL, true, false, true, urls_to_open); 483 Restore(profile, NULL, true, false, true, urls_to_open);
468 } 484 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698