OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/tab_loader.h" | 5 #include "chrome/browser/sessions/tab_loader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "components/favicon/content/content_favicon_driver.h" | 15 #include "components/favicon/content/content_favicon_driver.h" |
| 16 #include "components/variations/variations_associated_data.h" |
16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/render_widget_host.h" | 20 #include "content/public/browser/render_widget_host.h" |
20 #include "content/public/browser/render_widget_host_view.h" | 21 #include "content/public/browser/render_widget_host_view.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 | 23 |
23 using content::NavigationController; | 24 using content::NavigationController; |
24 using content::RenderWidgetHost; | 25 using content::RenderWidgetHost; |
25 using content::WebContents; | 26 using content::WebContents; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 189 } |
189 | 190 |
190 void TabLoader::HandleTabClosedOrLoaded(NavigationController* controller) { | 191 void TabLoader::HandleTabClosedOrLoaded(NavigationController* controller) { |
191 RemoveTab(controller); | 192 RemoveTab(controller); |
192 if (delegate_ && loading_enabled_) | 193 if (delegate_ && loading_enabled_) |
193 LoadNextTab(); | 194 LoadNextTab(); |
194 } | 195 } |
195 | 196 |
196 void TabLoader::OnMemoryPressure( | 197 void TabLoader::OnMemoryPressure( |
197 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 198 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 199 // On Windows and Mac this mechanism is only experimentally enabled. |
| 200 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 201 // If memory pressure integration isn't explicitly enabled then ignore these |
| 202 // calls. |
| 203 std::string react_to_memory_pressure = variations::GetVariationParamValue( |
| 204 "IntelligentSessionRestore", "ReactToMemoryPressure"); |
| 205 if (react_to_memory_pressure != "true") |
| 206 return; |
| 207 #endif |
| 208 |
198 // When receiving a resource pressure level warning, we stop pre-loading more | 209 // When receiving a resource pressure level warning, we stop pre-loading more |
199 // tabs since we are running in danger of loading more tabs by throwing out | 210 // tabs since we are running in danger of loading more tabs by throwing out |
200 // old ones. | 211 // old ones. |
201 if (tabs_to_load_.empty()) | 212 if (tabs_to_load_.empty()) |
202 return; | 213 return; |
203 // Stop the timer and suppress any tab loads while we clean the list. | 214 // Stop the timer and suppress any tab loads while we clean the list. |
204 SetTabLoadingEnabled(false); | 215 SetTabLoadingEnabled(false); |
205 while (!tabs_to_load_.empty()) { | 216 while (!tabs_to_load_.empty()) { |
206 NavigationController* controller = tabs_to_load_.front(); | 217 NavigationController* controller = tabs_to_load_.front(); |
207 tabs_to_load_.pop_front(); | 218 tabs_to_load_.pop_front(); |
208 RemoveTab(controller); | 219 RemoveTab(controller); |
209 } | 220 } |
210 // By calling |LoadNextTab| explicitly, we make sure that the | 221 // By calling |LoadNextTab| explicitly, we make sure that the |
211 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. | 222 // |NOTIFICATION_SESSION_RESTORE_DONE| event gets sent. |
212 LoadNextTab(); | 223 LoadNextTab(); |
213 } | 224 } |
214 | 225 |
215 // static | 226 // static |
216 TabLoader* TabLoader::shared_tab_loader_ = nullptr; | 227 TabLoader* TabLoader::shared_tab_loader_ = nullptr; |
OLD | NEW |