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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 TabManager::TabManager() | 155 TabManager::TabManager() |
156 : discard_count_(0), | 156 : discard_count_(0), |
157 recent_tab_discard_(false), | 157 recent_tab_discard_(false), |
158 discard_once_(false), | 158 discard_once_(false), |
159 #if !defined(OS_CHROMEOS) | 159 #if !defined(OS_CHROMEOS) |
160 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), | 160 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), |
161 #endif | 161 #endif |
162 browser_tab_strip_tracker_(this, nullptr, nullptr), | 162 browser_tab_strip_tracker_(this, nullptr, nullptr), |
163 test_tick_clock_(nullptr), | 163 test_tick_clock_(nullptr), |
164 is_session_restore_loading_tabs_(false), | 164 is_session_restore_loading_tabs_(false), |
| 165 initial_session_restore_foreground_tab_changed_(false), |
165 weak_ptr_factory_(this) { | 166 weak_ptr_factory_(this) { |
166 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
167 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); | 168 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); |
168 #endif | 169 #endif |
169 browser_tab_strip_tracker_.Init(); | 170 browser_tab_strip_tracker_.Init(); |
170 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); | 171 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); |
171 } | 172 } |
172 | 173 |
173 TabManager::~TabManager() { | 174 TabManager::~TabManager() { |
174 Stop(); | 175 Stop(); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 501 } |
501 | 502 |
502 // static | 503 // static |
503 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { | 504 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { |
504 return reinterpret_cast<int64_t>(web_contents); | 505 return reinterpret_cast<int64_t>(web_contents); |
505 } | 506 } |
506 | 507 |
507 void TabManager::OnSessionRestoreStartedLoadingTabs() { | 508 void TabManager::OnSessionRestoreStartedLoadingTabs() { |
508 DCHECK(!is_session_restore_loading_tabs_); | 509 DCHECK(!is_session_restore_loading_tabs_); |
509 is_session_restore_loading_tabs_ = true; | 510 is_session_restore_loading_tabs_ = true; |
| 511 |
| 512 // Needs to reset this flag for each session restore. |
| 513 initial_session_restore_foreground_tab_changed_ = false; |
510 } | 514 } |
511 | 515 |
512 void TabManager::OnSessionRestoreFinishedLoadingTabs() { | 516 void TabManager::OnSessionRestoreFinishedLoadingTabs() { |
513 DCHECK(is_session_restore_loading_tabs_); | 517 DCHECK(is_session_restore_loading_tabs_); |
514 is_session_restore_loading_tabs_ = false; | 518 is_session_restore_loading_tabs_ = false; |
515 } | 519 } |
516 | 520 |
517 /////////////////////////////////////////////////////////////////////////////// | 521 /////////////////////////////////////////////////////////////////////////////// |
518 // TabManager, private: | 522 // TabManager, private: |
519 | 523 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 // When ActiveTabChanged, |new_contents| purged state changes to be false. | 827 // When ActiveTabChanged, |new_contents| purged state changes to be false. |
824 GetWebContentsData(new_contents)->set_is_purged(false); | 828 GetWebContentsData(new_contents)->set_is_purged(false); |
825 // If |old_contents| is set, that tab has switched from being active to | 829 // If |old_contents| is set, that tab has switched from being active to |
826 // inactive, so record the time of that transition. | 830 // inactive, so record the time of that transition. |
827 if (old_contents) { | 831 if (old_contents) { |
828 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks()); | 832 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks()); |
829 // Re-setting time-to-purge every time a tab becomes inactive. | 833 // Re-setting time-to-purge every time a tab becomes inactive. |
830 GetWebContentsData(old_contents) | 834 GetWebContentsData(old_contents) |
831 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_)); | 835 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_)); |
832 } | 836 } |
| 837 |
| 838 if (old_contents && !initial_session_restore_foreground_tab_changed_) { |
| 839 initial_session_restore_foreground_tab_changed_ = true; |
| 840 } |
833 } | 841 } |
834 | 842 |
835 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model, | 843 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model, |
836 content::WebContents* contents, | 844 content::WebContents* contents, |
837 int index, | 845 int index, |
838 bool foreground) { | 846 bool foreground) { |
839 // Only interested in background tabs, as foreground tabs get taken care of by | 847 // Only interested in background tabs, as foreground tabs get taken care of by |
840 // ActiveTabChanged. | 848 // ActiveTabChanged. |
841 if (foreground) | 849 if (foreground) |
842 return; | 850 return; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 browser_info.window_is_minimized = browser->window()->IsMinimized(); | 945 browser_info.window_is_minimized = browser->window()->IsMinimized(); |
938 browser_info.window_bounds = browser->window()->GetBounds(); | 946 browser_info.window_bounds = browser->window()->GetBounds(); |
939 browser_info.browser_is_app = browser->is_app(); | 947 browser_info.browser_is_app = browser->is_app(); |
940 browser_info_list.push_back(browser_info); | 948 browser_info_list.push_back(browser_info); |
941 } | 949 } |
942 | 950 |
943 return browser_info_list; | 951 return browser_info_list; |
944 } | 952 } |
945 | 953 |
946 } // namespace resource_coordinator | 954 } // namespace resource_coordinator |
OLD | NEW |