Chromium Code Reviews| 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/sessions/session_restore.h" | 5 #include "chrome/browser/sessions/session_restore.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/debug/alias.h" | |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 20 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
| 21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 22 #include "base/task/cancelable_task_tracker.h" | 23 #include "base/task/cancelable_task_tracker.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/chrome_notification_types.h" | 25 #include "chrome/browser/chrome_notification_types.h" |
| 25 #include "chrome/browser/performance_monitor/startup_timer.h" | 26 #include "chrome/browser/performance_monitor/startup_timer.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 // Returns the RenderWidgetHost associated with a tab if there is one, | 146 // Returns the RenderWidgetHost associated with a tab if there is one, |
| 146 // NULL otherwise. | 147 // NULL otherwise. |
| 147 static RenderWidgetHost* GetRenderWidgetHost(NavigationController* tab); | 148 static RenderWidgetHost* GetRenderWidgetHost(NavigationController* tab); |
| 148 | 149 |
| 149 // Register for necessary notifications on a tab navigation controller. | 150 // Register for necessary notifications on a tab navigation controller. |
| 150 void RegisterForNotifications(NavigationController* controller); | 151 void RegisterForNotifications(NavigationController* controller); |
| 151 | 152 |
| 152 // Called when a tab goes away or a load completes. | 153 // Called when a tab goes away or a load completes. |
| 153 void HandleTabClosedOrLoaded(NavigationController* controller); | 154 void HandleTabClosedOrLoaded(NavigationController* controller); |
| 154 | 155 |
| 156 // TODO(sky): remove. For debugging 368236. | |
| 157 void CheckNotObserving(NavigationController* controller); | |
| 158 | |
| 155 content::NotificationRegistrar registrar_; | 159 content::NotificationRegistrar registrar_; |
| 156 | 160 |
| 157 // Current delay before a new tab is loaded. See class description for | 161 // Current delay before a new tab is loaded. See class description for |
| 158 // details. | 162 // details. |
| 159 int64 force_load_delay_; | 163 int64 force_load_delay_; |
| 160 | 164 |
| 161 // Has Load been invoked? | 165 // Has Load been invoked? |
| 162 bool loading_; | 166 bool loading_; |
| 163 | 167 |
| 164 // Have we recorded the times for a tab paint? | 168 // Have we recorded the times for a tab paint? |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 }; | 200 }; |
| 197 | 201 |
| 198 // static | 202 // static |
| 199 TabLoader* TabLoader::GetTabLoader(base::TimeTicks restore_started) { | 203 TabLoader* TabLoader::GetTabLoader(base::TimeTicks restore_started) { |
| 200 if (!shared_tab_loader) | 204 if (!shared_tab_loader) |
| 201 shared_tab_loader = new TabLoader(restore_started); | 205 shared_tab_loader = new TabLoader(restore_started); |
| 202 return shared_tab_loader; | 206 return shared_tab_loader; |
| 203 } | 207 } |
| 204 | 208 |
| 205 void TabLoader::ScheduleLoad(NavigationController* controller) { | 209 void TabLoader::ScheduleLoad(NavigationController* controller) { |
| 210 CheckNotObserving(controller); | |
| 206 DCHECK(controller); | 211 DCHECK(controller); |
| 207 DCHECK(find(tabs_to_load_.begin(), tabs_to_load_.end(), controller) == | 212 DCHECK(find(tabs_to_load_.begin(), tabs_to_load_.end(), controller) == |
| 208 tabs_to_load_.end()); | 213 tabs_to_load_.end()); |
| 209 tabs_to_load_.push_back(controller); | 214 tabs_to_load_.push_back(controller); |
| 210 RegisterForNotifications(controller); | 215 RegisterForNotifications(controller); |
| 211 } | 216 } |
| 212 | 217 |
| 213 void TabLoader::TabIsLoading(NavigationController* controller) { | 218 void TabLoader::TabIsLoading(NavigationController* controller) { |
| 219 CheckNotObserving(controller); | |
| 214 DCHECK(controller); | 220 DCHECK(controller); |
| 215 DCHECK(find(tabs_loading_.begin(), tabs_loading_.end(), controller) == | 221 DCHECK(find(tabs_loading_.begin(), tabs_loading_.end(), controller) == |
| 216 tabs_loading_.end()); | 222 tabs_loading_.end()); |
| 217 tabs_loading_.insert(controller); | 223 tabs_loading_.insert(controller); |
| 218 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(controller); | 224 RenderWidgetHost* render_widget_host = GetRenderWidgetHost(controller); |
| 219 DCHECK(render_widget_host); | 225 DCHECK(render_widget_host); |
| 220 render_widget_hosts_loading_.insert(render_widget_host); | 226 render_widget_hosts_loading_.insert(render_widget_host); |
| 221 RegisterForNotifications(controller); | 227 RegisterForNotifications(controller); |
| 222 } | 228 } |
| 223 | 229 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 base::TimeDelta::FromSeconds(100), | 479 base::TimeDelta::FromSeconds(100), |
| 474 100, | 480 100, |
| 475 base::Histogram::kUmaTargetedHistogramFlag); | 481 base::Histogram::kUmaTargetedHistogramFlag); |
| 476 counter_for_count->AddTime(time_to_load); | 482 counter_for_count->AddTime(time_to_load); |
| 477 | 483 |
| 478 UMA_HISTOGRAM_COUNTS_100("SessionRestore.ParallelTabLoads", | 484 UMA_HISTOGRAM_COUNTS_100("SessionRestore.ParallelTabLoads", |
| 479 max_parallel_tab_loads_); | 485 max_parallel_tab_loads_); |
| 480 } | 486 } |
| 481 } | 487 } |
| 482 | 488 |
| 489 void TabLoader::CheckNotObserving(NavigationController* controller) { | |
| 490 const bool in_tabs_to_load = | |
| 491 find(tabs_to_load_.begin(), tabs_to_load_.end(), controller) != | |
| 492 tabs_to_load_.end(); | |
|
marja
2014/05/23 08:30:43
Style nit, I find the shorter style more readable:
sky
2014/05/23 15:38:41
I agree with you, but find isn't on list, right?
marja
2014/05/27 07:54:55
Ahh, I see, I missed that it's a list.
| |
| 493 const bool in_tabs_loading = | |
| 494 find(tabs_loading_.begin(), tabs_loading_.end(), controller) != | |
| 495 tabs_loading_.end(); | |
| 496 const bool observing = | |
| 497 registrar_.IsRegistered( | |
| 498 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 499 content::Source<WebContents>(controller->GetWebContents())) || | |
| 500 registrar_.IsRegistered( | |
| 501 this, content::NOTIFICATION_LOAD_STOP, | |
| 502 content::Source<NavigationController>(controller)) || | |
| 503 registrar_.IsRegistered( | |
| 504 this, content::NOTIFICATION_LOAD_START, | |
| 505 content::Source<NavigationController>(controller)); | |
| 506 base::debug::Alias(&in_tabs_to_load); | |
|
marja
2014/05/23 08:30:43
Wouldn't it be simpler to CHECK(!foo) for all the
sky
2014/05/23 15:38:41
I was tempted to do as you suggest, but that would
| |
| 507 base::debug::Alias(&in_tabs_loading); | |
| 508 base::debug::Alias(&observing); | |
| 509 CHECK(!in_tabs_to_load && !in_tabs_loading && !observing); | |
| 510 } | |
| 511 | |
| 483 // SessionRestoreImpl --------------------------------------------------------- | 512 // SessionRestoreImpl --------------------------------------------------------- |
| 484 | 513 |
| 485 // SessionRestoreImpl is responsible for fetching the set of tabs to create | 514 // SessionRestoreImpl is responsible for fetching the set of tabs to create |
| 486 // from SessionService. SessionRestoreImpl deletes itself when done. | 515 // from SessionService. SessionRestoreImpl deletes itself when done. |
| 487 | 516 |
| 488 class SessionRestoreImpl : public content::NotificationObserver { | 517 class SessionRestoreImpl : public content::NotificationObserver { |
| 489 public: | 518 public: |
| 490 SessionRestoreImpl(Profile* profile, | 519 SessionRestoreImpl(Profile* profile, |
| 491 Browser* browser, | 520 Browser* browser, |
| 492 chrome::HostDesktopType host_desktop_type, | 521 chrome::HostDesktopType host_desktop_type, |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 if (!restored_tab) | 982 if (!restored_tab) |
| 954 continue; | 983 continue; |
| 955 | 984 |
| 956 // If this isn't the selected tab, there's nothing else to do. | 985 // If this isn't the selected tab, there's nothing else to do. |
| 957 if (is_not_selected_tab) | 986 if (is_not_selected_tab) |
| 958 continue; | 987 continue; |
| 959 | 988 |
| 960 ShowBrowser( | 989 ShowBrowser( |
| 961 browser, | 990 browser, |
| 962 browser->tab_strip_model()->GetIndexOfWebContents(restored_tab)); | 991 browser->tab_strip_model()->GetIndexOfWebContents(restored_tab)); |
| 992 // TODO(sky): remove. For debugging 368236. | |
| 993 CHECK_EQ(browser->tab_strip_model()->GetActiveWebContents(), | |
| 994 restored_tab); | |
| 963 tab_loader_->TabIsLoading(&browser->tab_strip_model() | 995 tab_loader_->TabIsLoading(&browser->tab_strip_model() |
| 964 ->GetActiveWebContents() | 996 ->GetActiveWebContents() |
| 965 ->GetController()); | 997 ->GetController()); |
| 966 } | 998 } |
| 967 } else { | 999 } else { |
| 968 // If the browser already has tabs, we want to restore the new ones after | 1000 // If the browser already has tabs, we want to restore the new ones after |
| 969 // the existing ones. E.g. this happens in Win8 Metro where we merge | 1001 // the existing ones. E.g. this happens in Win8 Metro where we merge |
| 970 // windows or when launching a hosted app from the app launcher. | 1002 // windows or when launching a hosted app from the app launcher. |
| 971 int tab_index_offset = initial_tab_count; | 1003 int tab_index_offset = initial_tab_count; |
| 972 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { | 1004 for (int i = 0; i < static_cast<int>(window.tabs.size()); ++i) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 if (!active_session_restorers) | 1293 if (!active_session_restorers) |
| 1262 return false; | 1294 return false; |
| 1263 for (std::set<SessionRestoreImpl*>::const_iterator it = | 1295 for (std::set<SessionRestoreImpl*>::const_iterator it = |
| 1264 active_session_restorers->begin(); | 1296 active_session_restorers->begin(); |
| 1265 it != active_session_restorers->end(); ++it) { | 1297 it != active_session_restorers->end(); ++it) { |
| 1266 if ((*it)->synchronous()) | 1298 if ((*it)->synchronous()) |
| 1267 return true; | 1299 return true; |
| 1268 } | 1300 } |
| 1269 return false; | 1301 return false; |
| 1270 } | 1302 } |
| OLD | NEW |