| OLD | NEW |
| 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/sessions/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sessions/session_service.h" | 21 #include "chrome/browser/sessions/session_service.h" |
| 22 #include "chrome/browser/sessions/session_service_factory.h" | 22 #include "chrome/browser/sessions/session_service_factory.h" |
| 23 #include "chrome/browser/sessions/session_types.h" | 23 #include "chrome/browser/sessions/session_types.h" |
| 24 #include "chrome/browser/tabs/tab_strip_model.h" | 24 #include "chrome/browser/tabs/tab_strip_model.h" |
| 25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/browser_navigator.h" | 27 #include "chrome/browser/ui/browser_navigator.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "content/browser/renderer_host/render_widget_host.h" | 30 #include "content/browser/renderer_host/render_widget_host.h" |
| 30 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 31 #include "content/browser/tab_contents/navigation_controller.h" | 32 #include "content/browser/tab_contents/navigation_controller.h" |
| 32 #include "content/browser/tab_contents/tab_contents.h" | 33 #include "content/browser/tab_contents/tab_contents.h" |
| 33 #include "content/browser/tab_contents/tab_contents_view.h" | 34 #include "content/browser/tab_contents/tab_contents_view.h" |
| 34 #include "content/common/notification_registrar.h" | 35 #include "content/common/notification_registrar.h" |
| 35 #include "content/common/notification_service.h" | 36 #include "content/common/notification_service.h" |
| 36 | 37 |
| 37 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 38 #include "chrome/browser/chromeos/boot_times_loader.h" | 39 #include "chrome/browser/chromeos/boot_times_loader.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 void TabLoader::StartLoading() { | 180 void TabLoader::StartLoading() { |
| 180 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, | 181 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DID_PAINT, |
| 181 NotificationService::AllSources()); | 182 NotificationService::AllSources()); |
| 182 #if defined(OS_CHROMEOS) | 183 #if defined(OS_CHROMEOS) |
| 183 if (chromeos::NetworkStateNotifier::is_connected()) { | 184 if (chromeos::NetworkStateNotifier::is_connected()) { |
| 184 loading_ = true; | 185 loading_ = true; |
| 185 LoadNextTab(); | 186 LoadNextTab(); |
| 186 } else { | 187 } else { |
| 187 // Start listening to network state notification now. | 188 // Start listening to network state notification now. |
| 188 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, | 189 registrar_.Add(this, chrome::NETWORK_STATE_CHANGED, |
| 189 NotificationService::AllSources()); | 190 NotificationService::AllSources()); |
| 190 } | 191 } |
| 191 #else | 192 #else |
| 192 loading_ = true; | 193 loading_ = true; |
| 193 LoadNextTab(); | 194 LoadNextTab(); |
| 194 #endif | 195 #endif |
| 195 } | 196 } |
| 196 | 197 |
| 197 void TabLoader::LoadNextTab() { | 198 void TabLoader::LoadNextTab() { |
| 198 if (!tabs_to_load_.empty()) { | 199 if (!tabs_to_load_.empty()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 225 base::TimeDelta::FromMilliseconds(force_load_delay_), | 226 base::TimeDelta::FromMilliseconds(force_load_delay_), |
| 226 this, &TabLoader::ForceLoadTimerFired); | 227 this, &TabLoader::ForceLoadTimerFired); |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 void TabLoader::Observe(NotificationType type, | 231 void TabLoader::Observe(NotificationType type, |
| 231 const NotificationSource& source, | 232 const NotificationSource& source, |
| 232 const NotificationDetails& details) { | 233 const NotificationDetails& details) { |
| 233 switch (type.value) { | 234 switch (type.value) { |
| 234 #if defined(OS_CHROMEOS) | 235 #if defined(OS_CHROMEOS) |
| 235 case NotificationType::NETWORK_STATE_CHANGED: { | 236 case chrome::NETWORK_STATE_CHANGED: { |
| 236 chromeos::NetworkStateDetails* state_details = | 237 chromeos::NetworkStateDetails* state_details = |
| 237 Details<chromeos::NetworkStateDetails>(details).ptr(); | 238 Details<chromeos::NetworkStateDetails>(details).ptr(); |
| 238 switch (state_details->state()) { | 239 switch (state_details->state()) { |
| 239 case chromeos::NetworkStateDetails::CONNECTED: | 240 case chromeos::NetworkStateDetails::CONNECTED: |
| 240 if (!loading_) { | 241 if (!loading_) { |
| 241 loading_ = true; | 242 loading_ = true; |
| 242 LoadNextTab(); | 243 LoadNextTab(); |
| 243 } | 244 } |
| 244 // Start loading | 245 // Start loading |
| 245 break; | 246 break; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 441 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
| 441 MessageLoop::current()->SetNestableTasksAllowed(true); | 442 MessageLoop::current()->SetNestableTasksAllowed(true); |
| 442 MessageLoop::current()->Run(); | 443 MessageLoop::current()->Run(); |
| 443 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 444 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
| 444 Browser* browser = ProcessSessionWindows(&windows_); | 445 Browser* browser = ProcessSessionWindows(&windows_); |
| 445 delete this; | 446 delete this; |
| 446 return browser; | 447 return browser; |
| 447 } | 448 } |
| 448 | 449 |
| 449 if (browser_) { | 450 if (browser_) { |
| 450 registrar_.Add(this, NotificationType::BROWSER_CLOSED, | 451 registrar_.Add(this, chrome::BROWSER_CLOSED, |
| 451 Source<Browser>(browser_)); | 452 Source<Browser>(browser_)); |
| 452 } | 453 } |
| 453 | 454 |
| 454 return browser_; | 455 return browser_; |
| 455 } | 456 } |
| 456 | 457 |
| 457 // Restore window(s) from a foreign session. | 458 // Restore window(s) from a foreign session. |
| 458 void RestoreForeignSession( | 459 void RestoreForeignSession( |
| 459 std::vector<SessionWindow*>::const_iterator begin, | 460 std::vector<SessionWindow*>::const_iterator begin, |
| 460 std::vector<SessionWindow*>::const_iterator end) { | 461 std::vector<SessionWindow*>::const_iterator end) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 ~SessionRestoreImpl() { | 497 ~SessionRestoreImpl() { |
| 497 STLDeleteElements(&windows_); | 498 STLDeleteElements(&windows_); |
| 498 restoring = false; | 499 restoring = false; |
| 499 g_browser_process->ReleaseModule(); | 500 g_browser_process->ReleaseModule(); |
| 500 } | 501 } |
| 501 | 502 |
| 502 virtual void Observe(NotificationType type, | 503 virtual void Observe(NotificationType type, |
| 503 const NotificationSource& source, | 504 const NotificationSource& source, |
| 504 const NotificationDetails& details) { | 505 const NotificationDetails& details) { |
| 505 switch (type.value) { | 506 switch (type.value) { |
| 506 case NotificationType::BROWSER_CLOSED: | 507 case chrome::BROWSER_CLOSED: |
| 507 delete this; | 508 delete this; |
| 508 return; | 509 return; |
| 509 | 510 |
| 510 default: | 511 default: |
| 511 NOTREACHED(); | 512 NOTREACHED(); |
| 512 break; | 513 break; |
| 513 } | 514 } |
| 514 } | 515 } |
| 515 | 516 |
| 516 private: | 517 private: |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 std::vector<GURL> gurls; | 830 std::vector<GURL> gurls; |
| 830 SessionRestoreImpl restorer(profile, | 831 SessionRestoreImpl restorer(profile, |
| 831 static_cast<Browser*>(NULL), true, false, true, gurls); | 832 static_cast<Browser*>(NULL), true, false, true, gurls); |
| 832 restorer.RestoreForeignTab(tab); | 833 restorer.RestoreForeignTab(tab); |
| 833 } | 834 } |
| 834 | 835 |
| 835 // static | 836 // static |
| 836 bool SessionRestore::IsRestoring() { | 837 bool SessionRestore::IsRestoring() { |
| 837 return restoring; | 838 return restoring; |
| 838 } | 839 } |
| OLD | NEW |