| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/tab_manager.h" | 5 #include "chrome/browser/memory/tab_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 35 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/browser/ui/tabs/tab_utils.h" | 37 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 38 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
| 39 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 40 #include "components/metrics/system_memory_stats_recorder.h" | 40 #include "components/metrics/system_memory_stats_recorder.h" |
| 41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 42 #include "content/public/browser/navigation_controller.h" | 42 #include "content/public/browser/navigation_controller.h" |
| 43 #include "content/public/browser/render_process_host.h" | 43 #include "content/public/browser/render_process_host.h" |
| 44 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/browser/web_contents_source.h" |
| 45 #include "content/public/common/page_importance_signals.h" | 46 #include "content/public/common/page_importance_signals.h" |
| 46 | 47 |
| 47 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 48 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" | 49 #include "chrome/browser/memory/tab_manager_delegate_chromeos.h" |
| 49 #endif | 50 #endif |
| 50 | 51 |
| 51 using base::TimeDelta; | 52 using base::TimeDelta; |
| 52 using base::TimeTicks; | 53 using base::TimeTicks; |
| 53 using content::BrowserThread; | 54 using content::BrowserThread; |
| 54 using content::WebContents; | 55 using content::WebContents; |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 // Can't discard tabs that are already discarded. | 478 // Can't discard tabs that are already discarded. |
| 478 if (GetWebContentsData(old_contents)->IsDiscarded()) | 479 if (GetWebContentsData(old_contents)->IsDiscarded()) |
| 479 return nullptr; | 480 return nullptr; |
| 480 | 481 |
| 481 // Record statistics before discarding to capture the memory state that leads | 482 // Record statistics before discarding to capture the memory state that leads |
| 482 // to the discard. | 483 // to the discard. |
| 483 RecordDiscardStatistics(); | 484 RecordDiscardStatistics(); |
| 484 | 485 |
| 485 WebContents* null_contents = | 486 WebContents* null_contents = |
| 486 WebContents::Create(WebContents::CreateParams(model->profile())); | 487 WebContents::Create(WebContents::CreateParams(model->profile())); |
| 488 WebContentsSource::CreateForWebContentsAndLocation(null_contents, FROM_HERE); |
| 487 // Copy over the state from the navigation controller to preserve the | 489 // Copy over the state from the navigation controller to preserve the |
| 488 // back/forward history and to continue to display the correct title/favicon. | 490 // back/forward history and to continue to display the correct title/favicon. |
| 489 null_contents->GetController().CopyStateFrom(old_contents->GetController()); | 491 null_contents->GetController().CopyStateFrom(old_contents->GetController()); |
| 490 | 492 |
| 491 // Make sure to persist the last active time property. | 493 // Make sure to persist the last active time property. |
| 492 null_contents->SetLastActiveTime(old_contents->GetLastActiveTime()); | 494 null_contents->SetLastActiveTime(old_contents->GetLastActiveTime()); |
| 493 // Copy over the discard count. | 495 // Copy over the discard count. |
| 494 WebContentsData::CopyState(old_contents, null_contents); | 496 WebContentsData::CopyState(old_contents, null_contents); |
| 495 | 497 |
| 496 // Replace the discarded tab with the null version. | 498 // Replace the discarded tab with the null version. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // sudden_termination_allowed false, and that covers too many common pages | 574 // sudden_termination_allowed false, and that covers too many common pages |
| 573 // with ad networks and statistics scripts. Ideally check for beforeUnload | 575 // with ad networks and statistics scripts. Ideally check for beforeUnload |
| 574 // handlers, which are likely to present a dialog asking if the user wants to | 576 // handlers, which are likely to present a dialog asking if the user wants to |
| 575 // discard state. crbug.com/123049. | 577 // discard state. crbug.com/123049. |
| 576 | 578 |
| 577 // Being more recently active is more important. | 579 // Being more recently active is more important. |
| 578 return first.last_active > second.last_active; | 580 return first.last_active > second.last_active; |
| 579 } | 581 } |
| 580 | 582 |
| 581 } // namespace memory | 583 } // namespace memory |
| OLD | NEW |