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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 return false; | 610 return false; |
611 | 611 |
612 // Do not discard a recently used tab. | 612 // Do not discard a recently used tab. |
613 if (minimum_protection_time_.InSeconds() > 0) { | 613 if (minimum_protection_time_.InSeconds() > 0) { |
614 auto delta = | 614 auto delta = |
615 NowTicks() - GetWebContentsData(web_contents)->LastInactiveTime(); | 615 NowTicks() - GetWebContentsData(web_contents)->LastInactiveTime(); |
616 if (delta < minimum_protection_time_) | 616 if (delta < minimum_protection_time_) |
617 return false; | 617 return false; |
618 } | 618 } |
619 | 619 |
| 620 // Do not discard a tab that was explicitly disallowed to. |
| 621 if (!IsTabAutoDiscardable(web_contents)) |
| 622 return false; |
| 623 |
620 return true; | 624 return true; |
621 } | 625 } |
622 | 626 |
623 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { | 627 WebContents* TabManager::DiscardWebContentsAt(int index, TabStripModel* model) { |
624 // Can't discard active index. | 628 // Can't discard active index. |
625 if (model->active_index() == index) | 629 if (model->active_index() == index) |
626 return nullptr; | 630 return nullptr; |
627 | 631 |
628 WebContents* old_contents = model->GetWebContentsAt(index); | 632 WebContents* old_contents = model->GetWebContentsAt(index); |
629 | 633 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 web_contents_data->set_test_tick_clock(test_tick_clock_); | 725 web_contents_data->set_test_tick_clock(test_tick_clock_); |
722 return web_contents_data; | 726 return web_contents_data; |
723 } | 727 } |
724 | 728 |
725 // static | 729 // static |
726 bool TabManager::CompareTabStats(TabStats first, TabStats second) { | 730 bool TabManager::CompareTabStats(TabStats first, TabStats second) { |
727 // Being currently selected is most important to protect. | 731 // Being currently selected is most important to protect. |
728 if (first.is_selected != second.is_selected) | 732 if (first.is_selected != second.is_selected) |
729 return first.is_selected; | 733 return first.is_selected; |
730 | 734 |
| 735 // Non auto-discardable tabs are more important to protect. |
| 736 if (first.is_auto_discardable != second.is_auto_discardable) |
| 737 return !first.is_auto_discardable; |
| 738 |
731 // Protect tabs with pending form entries. | 739 // Protect tabs with pending form entries. |
732 if (first.has_form_entry != second.has_form_entry) | 740 if (first.has_form_entry != second.has_form_entry) |
733 return first.has_form_entry; | 741 return first.has_form_entry; |
734 | 742 |
735 // Protect streaming audio and video conferencing tabs as these are similar to | 743 // Protect streaming audio and video conferencing tabs as these are similar to |
736 // active tabs. | 744 // active tabs. |
737 if (first.is_media != second.is_media) | 745 if (first.is_media != second.is_media) |
738 return first.is_media; | 746 return first.is_media; |
739 | 747 |
740 // Tab with internal web UI like NTP or Settings are good choices to discard, | 748 // Tab with internal web UI like NTP or Settings are good choices to discard, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 void TabManager::RemoveObserver(TabManagerObserver* observer) { | 907 void TabManager::RemoveObserver(TabManagerObserver* observer) { |
900 observers_.RemoveObserver(observer); | 908 observers_.RemoveObserver(observer); |
901 } | 909 } |
902 | 910 |
903 void TabManager::OnDiscardedStateChange(content::WebContents* contents, | 911 void TabManager::OnDiscardedStateChange(content::WebContents* contents, |
904 bool is_discarded) { | 912 bool is_discarded) { |
905 FOR_EACH_OBSERVER(TabManagerObserver, observers_, | 913 FOR_EACH_OBSERVER(TabManagerObserver, observers_, |
906 OnDiscardedStateChange(contents, is_discarded)); | 914 OnDiscardedStateChange(contents, is_discarded)); |
907 } | 915 } |
908 | 916 |
| 917 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, |
| 918 bool is_auto_discardable) { |
| 919 FOR_EACH_OBSERVER( |
| 920 TabManagerObserver, observers_, |
| 921 OnAutoDiscardableStateChange(contents, is_auto_discardable)); |
| 922 } |
| 923 |
| 924 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const { |
| 925 return GetWebContentsData(contents)->IsAutoDiscardable(); |
| 926 } |
| 927 |
| 928 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents, |
| 929 bool state) { |
| 930 GetWebContentsData(contents)->SetAutoDiscardableState(state); |
| 931 } |
| 932 |
909 } // namespace memory | 933 } // namespace memory |
OLD | NEW |