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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 void TabManager::RemoveObserver(TabManagerObserver* observer) { | 903 void TabManager::RemoveObserver(TabManagerObserver* observer) { |
900 observers_.RemoveObserver(observer); | 904 observers_.RemoveObserver(observer); |
901 } | 905 } |
902 | 906 |
903 void TabManager::OnDiscardedStateChange(content::WebContents* contents, | 907 void TabManager::OnDiscardedStateChange(content::WebContents* contents, |
904 bool is_discarded) { | 908 bool is_discarded) { |
905 FOR_EACH_OBSERVER(TabManagerObserver, observers_, | 909 FOR_EACH_OBSERVER(TabManagerObserver, observers_, |
906 OnDiscardedStateChange(contents, is_discarded)); | 910 OnDiscardedStateChange(contents, is_discarded)); |
907 } | 911 } |
908 | 912 |
| 913 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, |
| 914 bool is_auto_discardable) { |
| 915 FOR_EACH_OBSERVER( |
| 916 TabManagerObserver, observers_, |
| 917 OnAutoDiscardableStateChange(contents, is_auto_discardable)); |
| 918 } |
| 919 |
| 920 bool TabManager::IsTabAutoDiscardable(content::WebContents* contents) const { |
| 921 return GetWebContentsData(contents)->IsAutoDiscardable(); |
| 922 } |
| 923 |
| 924 void TabManager::SetTabAutoDiscardableState(content::WebContents* contents, |
| 925 bool state) { |
| 926 GetWebContentsData(contents)->SetAutoDiscardableState(state); |
| 927 } |
| 928 |
909 } // namespace memory | 929 } // namespace memory |
OLD | NEW |