| 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/session_restore.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 SessionRestore::AddObserver(this); |
| 135 } |
| 136 |
| 137 ~TabManagerSessionRestoreObserver() { SessionRestore::RemoveObserver(this); } |
| 138 |
| 139 // SessionRestoreObserver implementation: |
| 140 void OnSessionRestoreStartedLoadingTabs() override { |
| 141 tab_manager_->OnSessionRestoreStartedLoadingTabs(); |
| 142 } |
| 143 |
| 144 void OnSessionRestoreFinishedLoadingTabs() override { |
| 145 tab_manager_->OnSessionRestoreFinishedLoadingTabs(); |
| 146 } |
| 147 |
| 148 private: |
| 149 TabManager* tab_manager_; |
| 150 }; |
| 151 |
| 128 constexpr base::TimeDelta TabManager::kDefaultMinTimeToPurge; | 152 constexpr base::TimeDelta TabManager::kDefaultMinTimeToPurge; |
| 129 | 153 |
| 130 TabManager::TabManager() | 154 TabManager::TabManager() |
| 131 : discard_count_(0), | 155 : discard_count_(0), |
| 132 recent_tab_discard_(false), | 156 recent_tab_discard_(false), |
| 133 discard_once_(false), | 157 discard_once_(false), |
| 134 #if !defined(OS_CHROMEOS) | 158 #if !defined(OS_CHROMEOS) |
| 135 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), | 159 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), |
| 136 #endif | 160 #endif |
| 137 browser_tab_strip_tracker_(this, nullptr, nullptr), | 161 browser_tab_strip_tracker_(this, nullptr, nullptr), |
| 138 test_tick_clock_(nullptr), | 162 test_tick_clock_(nullptr), |
| 163 is_in_session_restore_tab_loading_(false), |
| 139 weak_ptr_factory_(this) { | 164 weak_ptr_factory_(this) { |
| 140 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
| 141 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); | 166 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); |
| 142 #endif | 167 #endif |
| 143 browser_tab_strip_tracker_.Init(); | 168 browser_tab_strip_tracker_.Init(); |
| 169 session_restore_observer_.reset(new TabManagerSessionRestoreObserver(this)); |
| 144 } | 170 } |
| 145 | 171 |
| 146 TabManager::~TabManager() { | 172 TabManager::~TabManager() { |
| 147 Stop(); | 173 Stop(); |
| 148 } | 174 } |
| 149 | 175 |
| 150 void TabManager::Start() { | 176 void TabManager::Start() { |
| 151 #if defined(OS_WIN) || defined(OS_MACOSX) | 177 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 152 // Note that discarding is now enabled by default. This check is kept as a | 178 // Note that discarding is now enabled by default. This check is kept as a |
| 153 // kill switch. | 179 // kill switch. |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 494 |
| 469 // Being more recently active is more important. | 495 // Being more recently active is more important. |
| 470 return first.last_active > second.last_active; | 496 return first.last_active > second.last_active; |
| 471 } | 497 } |
| 472 | 498 |
| 473 // static | 499 // static |
| 474 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { | 500 int64_t TabManager::IdFromWebContents(WebContents* web_contents) { |
| 475 return reinterpret_cast<int64_t>(web_contents); | 501 return reinterpret_cast<int64_t>(web_contents); |
| 476 } | 502 } |
| 477 | 503 |
| 504 void TabManager::OnSessionRestoreStartedLoadingTabs() { |
| 505 DCHECK(!is_in_session_restore_tab_loading_); |
| 506 is_in_session_restore_tab_loading_ = true; |
| 507 } |
| 508 |
| 509 void TabManager::OnSessionRestoreFinishedLoadingTabs() { |
| 510 DCHECK(is_in_session_restore_tab_loading_); |
| 511 is_in_session_restore_tab_loading_ = false; |
| 512 } |
| 513 |
| 478 /////////////////////////////////////////////////////////////////////////////// | 514 /////////////////////////////////////////////////////////////////////////////// |
| 479 // TabManager, private: | 515 // TabManager, private: |
| 480 | 516 |
| 481 void TabManager::OnDiscardedStateChange(content::WebContents* contents, | 517 void TabManager::OnDiscardedStateChange(content::WebContents* contents, |
| 482 bool is_discarded) { | 518 bool is_discarded) { |
| 483 for (TabManagerObserver& observer : observers_) | 519 for (TabManagerObserver& observer : observers_) |
| 484 observer.OnDiscardedStateChange(contents, is_discarded); | 520 observer.OnDiscardedStateChange(contents, is_discarded); |
| 485 } | 521 } |
| 486 | 522 |
| 487 void TabManager::OnAutoDiscardableStateChange(content::WebContents* contents, | 523 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(); | 933 browser_info.window_is_minimized = browser->window()->IsMinimized(); |
| 898 browser_info.window_bounds = browser->window()->GetBounds(); | 934 browser_info.window_bounds = browser->window()->GetBounds(); |
| 899 browser_info.browser_is_app = browser->is_app(); | 935 browser_info.browser_is_app = browser->is_app(); |
| 900 browser_info_list.push_back(browser_info); | 936 browser_info_list.push_back(browser_info); |
| 901 } | 937 } |
| 902 | 938 |
| 903 return browser_info_list; | 939 return browser_info_list; |
| 904 } | 940 } |
| 905 | 941 |
| 906 } // namespace resource_coordinator | 942 } // namespace resource_coordinator |
| OLD | NEW |