| 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 17 matching lines...) Expand all Loading... |
| 28 #include "base/threading/thread.h" | 28 #include "base/threading/thread.h" |
| 29 #include "base/time/tick_clock.h" | 29 #include "base/time/tick_clock.h" |
| 30 #include "build/build_config.h" | 30 #include "build/build_config.h" |
| 31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 32 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 32 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 33 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 33 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 34 #include "chrome/browser/memory/oom_memory_details.h" | 34 #include "chrome/browser/memory/oom_memory_details.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/resource_coordinator/tab_manager_observer.h" | 36 #include "chrome/browser/resource_coordinator/tab_manager_observer.h" |
| 37 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" | 37 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" |
| 38 #include "chrome/browser/sessions/tab_loader.h" |
| 38 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/browser_window.h" | 41 #include "chrome/browser/ui/browser_window.h" |
| 41 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 42 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
| 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 43 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 43 #include "chrome/browser/ui/tabs/tab_utils.h" | 44 #include "chrome/browser/ui/tabs/tab_utils.h" |
| 44 #include "chrome/common/chrome_constants.h" | 45 #include "chrome/common/chrome_constants.h" |
| 45 #include "chrome/common/chrome_features.h" | 46 #include "chrome/common/chrome_features.h" |
| 46 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 std::vector<gfx::Rect> bounds_list_; | 119 std::vector<gfx::Rect> bounds_list_; |
| 119 | 120 |
| 120 DISALLOW_COPY_AND_ASSIGN(BoundsList); | 121 DISALLOW_COPY_AND_ASSIGN(BoundsList); |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 } // namespace | 124 } // namespace |
| 124 | 125 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 126 //////////////////////////////////////////////////////////////////////////////// |
| 126 // TabManager | 127 // TabManager |
| 127 | 128 |
| 129 class TabManager::TabManagerSessionRestoreObserver |
| 130 : public SessionRestoreObserver { |
| 131 public: |
| 132 explicit TabManagerSessionRestoreObserver(TabManager* tab_manager) |
| 133 : tab_manager_(tab_manager) { |
| 134 SessionRestoreObserver::AddObserver(this); |
| 135 } |
| 136 |
| 137 ~TabManagerSessionRestoreObserver() { |
| 138 SessionRestoreObserver::RemoveObserver(this); |
| 139 } |
| 140 |
| 141 // SessionRestoreObserver implementation: |
| 142 void OnTabLoadingStarted() override { |
| 143 tab_manager_->OnSessionRestoreTabLoadingStarted(); |
| 144 } |
| 145 |
| 146 void OnTabLoadingEnded() override { |
| 147 tab_manager_->OnSessionRestoreTabLoadingEnded(); |
| 148 } |
| 149 |
| 150 private: |
| 151 TabManager* tab_manager_; |
| 152 }; |
| 153 |
| 128 constexpr base::TimeDelta TabManager::kDefaultMinTimeToPurge; | 154 constexpr base::TimeDelta TabManager::kDefaultMinTimeToPurge; |
| 129 | 155 |
| 130 TabManager::TabManager() | 156 TabManager::TabManager() |
| 131 : discard_count_(0), | 157 : discard_count_(0), |
| 132 recent_tab_discard_(false), | 158 recent_tab_discard_(false), |
| 133 discard_once_(false), | 159 discard_once_(false), |
| 134 #if !defined(OS_CHROMEOS) | 160 #if !defined(OS_CHROMEOS) |
| 135 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), | 161 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), |
| 136 #endif | 162 #endif |
| 137 browser_tab_strip_tracker_(this, nullptr, nullptr), | 163 browser_tab_strip_tracker_(this, nullptr, nullptr), |
| 138 test_tick_clock_(nullptr), | 164 test_tick_clock_(nullptr), |
| 165 is_in_session_restore_tab_loading_(false), |
| 139 weak_ptr_factory_(this) { | 166 weak_ptr_factory_(this) { |
| 140 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
| 141 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); | 168 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); |
| 142 #endif | 169 #endif |
| 143 browser_tab_strip_tracker_.Init(); | 170 browser_tab_strip_tracker_.Init(); |
| 171 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); |
| 144 } | 172 } |
| 145 | 173 |
| 146 TabManager::~TabManager() { | 174 TabManager::~TabManager() { |
| 147 Stop(); | 175 Stop(); |
| 148 } | 176 } |
| 149 | 177 |
| 150 void TabManager::Start() { | 178 void TabManager::Start() { |
| 151 #if defined(OS_WIN) || defined(OS_MACOSX) | 179 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 152 // Note that discarding is now enabled by default. This check is kept as a | 180 // Note that discarding is now enabled by default. This check is kept as a |
| 153 // kill switch. | 181 // kill switch. |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 496 |
| 469 // Being more recently active is more important. | 497 // Being more recently active is more important. |
| 470 return first.last_active > second.last_active; | 498 return first.last_active > second.last_active; |
| 471 } | 499 } |
| 472 | 500 |
| 473 // static | 501 // static |
| 474 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { | 502 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { |
| 475 return reinterpret_cast<int64_t>(web_contents); | 503 return reinterpret_cast<int64_t>(web_contents); |
| 476 } | 504 } |
| 477 | 505 |
| 506 void TabManager::OnSessionRestoreTabLoadingStarted() { |
| 507 DCHECK(!is_in_session_restore_tab_loading_); |
| 508 is_in_session_restore_tab_loading_ = true; |
| 509 } |
| 510 |
| 511 void TabManager::OnSessionRestoreTabLoadingEnded() { |
| 512 DCHECK(is_in_session_restore_tab_loading_); |
| 513 is_in_session_restore_tab_loading_ = false; |
| 514 } |
| 515 |
| 478 /////////////////////////////////////////////////////////////////////////////// | 516 /////////////////////////////////////////////////////////////////////////////// |
| 479 // TabManager, private: | 517 // TabManager, private: |
| 480 | 518 |
| 481 void TabManager::OnDiscardedStateChange(content::WebContents* contents, | 519 void TabManager::OnDiscardedStateChange(content::WebContents* contents, |
| 482 bool is_discarded) { | 520 bool is_discarded) { |
| 483 for (TabManagerObserver& observer : observers_) | 521 for (TabManagerObserver& observer : observers_) |
| 484 observer.OnDiscardedStateChange(contents, is_discarded); | 522 observer.OnDiscardedStateChange(contents, is_discarded); |
| 485 } | 523 } |
| 486 | 524 |
| 487 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, | 525 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 browser_info.window_is_minimized = browser->window()->IsMinimized(); | 935 browser_info.window_is_minimized = browser->window()->IsMinimized(); |
| 898 browser_info.window_bounds = browser->window()->GetBounds(); | 936 browser_info.window_bounds = browser->window()->GetBounds(); |
| 899 browser_info.browser_is_app = browser->is_app(); | 937 browser_info.browser_is_app = browser->is_app(); |
| 900 browser_info_list.push_back(browser_info); | 938 browser_info_list.push_back(browser_info); |
| 901 } | 939 } |
| 902 | 940 |
| 903 return browser_info_list; | 941 return browser_info_list; |
| 904 } | 942 } |
| 905 | 943 |
| 906 } // namespace resource_coordinator | 944 } // namespace resource_coordinator |
| OLD | NEW |