| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
| 15 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_window.h" | 17 #include "chrome/browser/browser_window.h" |
| 18 #include "chrome/browser/extensions/extensions_service.h" | 18 #include "chrome/browser/extensions/extensions_service.h" |
| 19 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/sessions/session_service.h" | 20 #include "chrome/browser/sessions/session_service.h" |
| 21 #include "chrome/browser/sessions/session_types.h" | 21 #include "chrome/browser/sessions/session_types.h" |
| 22 #include "chrome/browser/tab_contents/navigation_controller.h" | 22 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/tab_contents/tab_contents_view.h" | 24 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/notification_registrar.h" | 26 #include "chrome/common/notification_registrar.h" |
| 27 #include "chrome/common/notification_service.h" | 27 #include "chrome/common/notification_service.h" |
| 28 | 28 |
| 29 #if defined(OS_CHROMEOS) |
| 30 #include "chrome/browser/chromeos/network_state_notifier.h" |
| 31 #endif |
| 32 |
| 29 // Are we in the process of restoring? | 33 // Are we in the process of restoring? |
| 30 static bool restoring = false; | 34 static bool restoring = false; |
| 31 | 35 |
| 32 namespace { | 36 namespace { |
| 33 | 37 |
| 34 // TabLoader ------------------------------------------------------------------ | 38 // TabLoader ------------------------------------------------------------------ |
| 35 | 39 |
| 36 // Initial delay (see class decription for details). | 40 // Initial delay (see class decription for details). |
| 37 static const int kInitialDelayTimerMS = 100; | 41 static const int kInitialDelayTimerMS = 100; |
| 38 | 42 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 Source<NavigationController>(controller)); | 124 Source<NavigationController>(controller)); |
| 121 registrar_.Add(this, NotificationType::LOAD_STOP, | 125 registrar_.Add(this, NotificationType::LOAD_STOP, |
| 122 Source<NavigationController>(controller)); | 126 Source<NavigationController>(controller)); |
| 123 } else { | 127 } else { |
| 124 // Should never get a NULL tab. | 128 // Should never get a NULL tab. |
| 125 NOTREACHED(); | 129 NOTREACHED(); |
| 126 } | 130 } |
| 127 } | 131 } |
| 128 | 132 |
| 129 void TabLoader::StartLoading() { | 133 void TabLoader::StartLoading() { |
| 134 #if defined(OS_CHROMEOS) |
| 135 if (chromeos::NetworkStateNotifier::is_connected()) { |
| 136 loading_ = true; |
| 137 LoadNextTab(); |
| 138 } else { |
| 139 // Start listening to network state notification now. |
| 140 registrar_.Add(this, NotificationType::NETWORK_STATE_CHANGED, |
| 141 NotificationService::AllSources()); |
| 142 } |
| 143 #else |
| 130 loading_ = true; | 144 loading_ = true; |
| 131 LoadNextTab(); | 145 LoadNextTab(); |
| 146 #endif |
| 132 } | 147 } |
| 133 | 148 |
| 134 void TabLoader::LoadNextTab() { | 149 void TabLoader::LoadNextTab() { |
| 135 if (!tabs_to_load_.empty()) { | 150 if (!tabs_to_load_.empty()) { |
| 136 NavigationController* tab = tabs_to_load_.front(); | 151 NavigationController* tab = tabs_to_load_.front(); |
| 152 DCHECK(tab); |
| 137 tabs_loading_.insert(tab); | 153 tabs_loading_.insert(tab); |
| 138 tabs_to_load_.pop_front(); | 154 tabs_to_load_.pop_front(); |
| 139 tab->LoadIfNecessary(); | 155 tab->LoadIfNecessary(); |
| 140 if (tab && tab->tab_contents()) { | 156 if (tab->tab_contents()) { |
| 141 int tab_index; | 157 int tab_index; |
| 142 Browser* browser = Browser::GetBrowserForController(tab, &tab_index); | 158 Browser* browser = Browser::GetBrowserForController(tab, &tab_index); |
| 143 if (browser && browser->selected_index() != tab_index) { | 159 if (browser && browser->selected_index() != tab_index) { |
| 144 // By default tabs are marked as visible. As only the selected tab is | 160 // By default tabs are marked as visible. As only the selected tab is |
| 145 // visible we need to explicitly tell non-selected tabs they are hidden. | 161 // visible we need to explicitly tell non-selected tabs they are hidden. |
| 146 // Without this call non-selected tabs are not marked as backgrounded. | 162 // Without this call non-selected tabs are not marked as backgrounded. |
| 147 // | 163 // |
| 148 // NOTE: We need to do this here rather than when the tab is added to | 164 // NOTE: We need to do this here rather than when the tab is added to |
| 149 // the Browser as at that time not everything has been created, so that | 165 // the Browser as at that time not everything has been created, so that |
| 150 // the call would do nothing. | 166 // the call would do nothing. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 if (force_load_timer_.IsRunning()) | 178 if (force_load_timer_.IsRunning()) |
| 163 force_load_timer_.Stop(); | 179 force_load_timer_.Stop(); |
| 164 force_load_timer_.Start( | 180 force_load_timer_.Start( |
| 165 base::TimeDelta::FromMilliseconds(force_load_delay_), | 181 base::TimeDelta::FromMilliseconds(force_load_delay_), |
| 166 this, &TabLoader::ForceLoadTimerFired); | 182 this, &TabLoader::ForceLoadTimerFired); |
| 167 } | 183 } |
| 168 | 184 |
| 169 void TabLoader::Observe(NotificationType type, | 185 void TabLoader::Observe(NotificationType type, |
| 170 const NotificationSource& source, | 186 const NotificationSource& source, |
| 171 const NotificationDetails& details) { | 187 const NotificationDetails& details) { |
| 172 DCHECK(type == NotificationType::TAB_CLOSED || | 188 switch (type.value) { |
| 173 type == NotificationType::LOAD_STOP); | 189 #if defined(OS_CHROMEOS) |
| 174 NavigationController* tab = Source<NavigationController>(source).ptr(); | 190 case NotificationType::NETWORK_STATE_CHANGED: { |
| 175 RemoveTab(tab); | 191 chromeos::NetworkStateDetails* state_details = |
| 176 if (loading_) { | 192 Details<chromeos::NetworkStateDetails>(details).ptr(); |
| 177 LoadNextTab(); | 193 switch (state_details->state()) { |
| 178 // WARNING: if there are no more tabs to load, we have been deleted. | 194 case chromeos::NetworkStateDetails::CONNECTED: |
| 195 if (!loading_) { |
| 196 loading_ = true; |
| 197 LoadNextTab(); |
| 198 } |
| 199 // start loading |
| 200 break; |
| 201 case chromeos::NetworkStateDetails::CONNECTING: |
| 202 // keep it going |
| 203 break; |
| 204 case chromeos::NetworkStateDetails::DISCONNECTED: |
| 205 // disconnected while loading. set loaing_ false so |
| 206 // that it stops trying to load next tab. |
| 207 loading_ = false; |
| 208 break; |
| 209 default: |
| 210 NOTREACHED() << "Unknown nework state notification:" |
| 211 << state_details->state(); |
| 212 } |
| 213 break; |
| 214 } |
| 215 #endif |
| 216 case NotificationType::TAB_CLOSED: |
| 217 case NotificationType::LOAD_STOP: { |
| 218 NavigationController* tab = Source<NavigationController>(source).ptr(); |
| 219 RemoveTab(tab); |
| 220 if (loading_) { |
| 221 LoadNextTab(); |
| 222 // WARNING: if there are no more tabs to load, we have been deleted. |
| 223 } else if (tabs_to_load_.empty()) { |
| 224 tabs_loading_.clear(); |
| 225 delete this; |
| 226 return; |
| 227 } |
| 228 break; |
| 229 } |
| 230 default: |
| 231 NOTREACHED() << "Unknown notification received:" << type.value; |
| 179 } | 232 } |
| 180 } | 233 } |
| 181 | 234 |
| 182 void TabLoader::RemoveTab(NavigationController* tab) { | 235 void TabLoader::RemoveTab(NavigationController* tab) { |
| 183 registrar_.Remove(this, NotificationType::TAB_CLOSED, | 236 registrar_.Remove(this, NotificationType::TAB_CLOSED, |
| 184 Source<NavigationController>(tab)); | 237 Source<NavigationController>(tab)); |
| 185 registrar_.Remove(this, NotificationType::LOAD_STOP, | 238 registrar_.Remove(this, NotificationType::LOAD_STOP, |
| 186 Source<NavigationController>(tab)); | 239 Source<NavigationController>(tab)); |
| 187 | 240 |
| 188 TabsLoading::iterator i = tabs_loading_.find(tab); | 241 TabsLoading::iterator i = tabs_loading_.find(tab); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 void SessionRestore::RestoreSessionSynchronously( | 617 void SessionRestore::RestoreSessionSynchronously( |
| 565 Profile* profile, | 618 Profile* profile, |
| 566 const std::vector<GURL>& urls_to_open) { | 619 const std::vector<GURL>& urls_to_open) { |
| 567 Restore(profile, NULL, true, false, true, urls_to_open); | 620 Restore(profile, NULL, true, false, true, urls_to_open); |
| 568 } | 621 } |
| 569 | 622 |
| 570 // static | 623 // static |
| 571 bool SessionRestore::IsRestoring() { | 624 bool SessionRestore::IsRestoring() { |
| 572 return restoring; | 625 return restoring; |
| 573 } | 626 } |
| OLD | NEW |