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/resource_coordinator/tab_manager.h" | 5 #include "chrome/browser/resource_coordinator/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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 TabManager::TabManager() | 128 TabManager::TabManager() |
129 : discard_count_(0), | 129 : discard_count_(0), |
130 recent_tab_discard_(false), | 130 recent_tab_discard_(false), |
131 discard_once_(false), | 131 discard_once_(false), |
132 #if !defined(OS_CHROMEOS) | 132 #if !defined(OS_CHROMEOS) |
133 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), | 133 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), |
134 #endif | 134 #endif |
135 browser_tab_strip_tracker_(this, nullptr, nullptr), | 135 browser_tab_strip_tracker_(this, nullptr, nullptr), |
136 test_tick_clock_(nullptr), | 136 test_tick_clock_(nullptr), |
137 is_session_restore_loading_tabs_(false), | 137 is_session_restore_loading_tabs_(false), |
| 138 initial_session_restore_foreground_tab_changed_(false), |
138 weak_ptr_factory_(this) { | 139 weak_ptr_factory_(this) { |
139 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
140 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); | 141 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); |
141 #endif | 142 #endif |
142 browser_tab_strip_tracker_.Init(); | 143 browser_tab_strip_tracker_.Init(); |
143 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); | 144 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); |
144 } | 145 } |
145 | 146 |
146 TabManager::~TabManager() { | 147 TabManager::~TabManager() { |
147 Stop(); | 148 Stop(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 463 } |
463 | 464 |
464 // static | 465 // static |
465 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { | 466 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { |
466 return reinterpret_cast<int64_t>(web_contents); | 467 return reinterpret_cast<int64_t>(web_contents); |
467 } | 468 } |
468 | 469 |
469 void TabManager::OnSessionRestoreStartedLoadingTabs() { | 470 void TabManager::OnSessionRestoreStartedLoadingTabs() { |
470 DCHECK(!is_session_restore_loading_tabs_); | 471 DCHECK(!is_session_restore_loading_tabs_); |
471 is_session_restore_loading_tabs_ = true; | 472 is_session_restore_loading_tabs_ = true; |
| 473 |
| 474 // Needs to reset this flag for each session restore. |
| 475 initial_session_restore_foreground_tab_changed_ = false; |
472 } | 476 } |
473 | 477 |
474 void TabManager::OnSessionRestoreFinishedLoadingTabs() { | 478 void TabManager::OnSessionRestoreFinishedLoadingTabs() { |
475 DCHECK(is_session_restore_loading_tabs_); | 479 DCHECK(is_session_restore_loading_tabs_); |
476 is_session_restore_loading_tabs_ = false; | 480 is_session_restore_loading_tabs_ = false; |
477 } | 481 } |
478 | 482 |
479 /////////////////////////////////////////////////////////////////////////////// | 483 /////////////////////////////////////////////////////////////////////////////// |
480 // TabManager, private: | 484 // TabManager, private: |
481 | 485 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 // When ActiveTabChanged, |new_contents| purged state changes to be false. | 791 // When ActiveTabChanged, |new_contents| purged state changes to be false. |
788 GetWebContentsData(new_contents)->set_is_purged(false); | 792 GetWebContentsData(new_contents)->set_is_purged(false); |
789 // If |old_contents| is set, that tab has switched from being active to | 793 // If |old_contents| is set, that tab has switched from being active to |
790 // inactive, so record the time of that transition. | 794 // inactive, so record the time of that transition. |
791 if (old_contents) { | 795 if (old_contents) { |
792 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks()); | 796 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks()); |
793 // Re-setting time-to-purge every time a tab becomes inactive. | 797 // Re-setting time-to-purge every time a tab becomes inactive. |
794 GetWebContentsData(old_contents) | 798 GetWebContentsData(old_contents) |
795 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_)); | 799 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_)); |
796 } | 800 } |
| 801 |
| 802 if (old_contents && !initial_session_restore_foreground_tab_changed_) { |
| 803 initial_session_restore_foreground_tab_changed_ = true; |
| 804 } |
797 } | 805 } |
798 | 806 |
799 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model, | 807 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model, |
800 content::WebContents* contents, | 808 content::WebContents* contents, |
801 int index, | 809 int index, |
802 bool foreground) { | 810 bool foreground) { |
803 // Only interested in background tabs, as foreground tabs get taken care of by | 811 // Only interested in background tabs, as foreground tabs get taken care of by |
804 // ActiveTabChanged. | 812 // ActiveTabChanged. |
805 if (foreground) | 813 if (foreground) |
806 return; | 814 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 browser_info.window_is_active = browser->window()->IsActive(); | 908 browser_info.window_is_active = browser->window()->IsActive(); |
901 browser_info.window_is_minimized = browser->window()->IsMinimized(); | 909 browser_info.window_is_minimized = browser->window()->IsMinimized(); |
902 browser_info.browser_is_app = browser->is_app(); | 910 browser_info.browser_is_app = browser->is_app(); |
903 browser_info_list.push_back(browser_info); | 911 browser_info_list.push_back(browser_info); |
904 } | 912 } |
905 | 913 |
906 return browser_info_list; | 914 return browser_info_list; |
907 } | 915 } |
908 | 916 |
909 } // namespace resource_coordinator | 917 } // namespace resource_coordinator |
OLD | NEW |