diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_init.cc | 10 | ||||
-rw-r--r-- | chrome/browser/sessions/session_restore.cc | 75 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 |
4 files changed, 53 insertions, 38 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 9213502..605099f 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -908,16 +908,6 @@ bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) NavigationController::DisablePromptOnRepost(); - const std::string tab_count_string = command_line.GetSwitchValueASCII( - switches::kTabCountToLoadOnSessionRestore); - if (!tab_count_string.empty()) { - int count = 0; - if (StringToInt(tab_count_string, &count)) { - const int tab_count = std::max(0, count); - SessionRestore::num_tabs_to_load_ = static_cast<size_t>(tab_count); - } - } - // Look for the testing channel ID ONLY during process startup if (command_line.HasSwitch(switches::kTestingChannelID)) { std::string testing_channel_id = command_line.GetSwitchValueASCII( diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 0d60867..2537411 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -33,13 +33,17 @@ namespace { // TabLoader ------------------------------------------------------------------ -// TabLoader is responsible for ensuring after session restore we have -// at least SessionRestore::num_tabs_to_load_ loading. As tabs finish loading -// new tabs are loaded. When all tabs are loading TabLoader deletes itself. +// Initial delay (see class decription for details). +static const int kInitialDelayTimerMS = 100; + +// TabLoader is responsible for loading tabs after session restore creates +// tabs. New tabs are loaded after the current tab finishes loading, or a delay +// is reached (initially kInitialDelayTimerMS). If the delay is reached before +// a tab finishes loading a new tab is loaded and the time of the delay +// doubled. When all tabs are loading TabLoader deletes itself. // // This is not part of SessionRestoreImpl so that synchronous destruction // of SessionRestoreImpl doesn't have timing problems. - class TabLoader : public NotificationObserver { public: typedef std::list<NavigationController*> TabsToLoad; @@ -47,19 +51,21 @@ class TabLoader : public NotificationObserver { TabLoader(); ~TabLoader(); - // Adds a tab to load. - void AddTab(NavigationController* controller); + // Schedules a tab for loading. + void ScheduleLoad(NavigationController* controller); - // Loads the next batch of tabs until SessionRestore::num_tabs_to_load_ tabs - // are loading, or all tabs are loading. If there are no more tabs to load, - // this deletes the TabLoader. + // Invokes |LoadNextTab| to load a tab. // // This must be invoked once to start loading. - void LoadTabs(); + void StartLoading(); private: typedef std::set<NavigationController*> TabsLoading; + // Loads the next tab. If there are no more tabs to load this deletes itself, + // otherwise |force_load_timer_| is restarted. + void LoadNextTab(); + // NotificationObserver method. Removes the specified tab and loads the next // tab. virtual void Observe(NotificationType type, @@ -71,8 +77,16 @@ class TabLoader : public NotificationObserver { // from. void RemoveTab(NavigationController* tab); + // Invoked from |force_load_timer_|. Doubles |force_load_delay_| and invokes + // |LoadNextTab| to load the next tab + void ForceLoadTimerFired(); + NotificationRegistrar registrar_; + // Current delay before a new tab is loaded. See class description for + // details. + int64 force_load_delay_; + // Has Load been invoked? bool loading_; @@ -82,17 +96,22 @@ class TabLoader : public NotificationObserver { // The tabs we need to load. TabsToLoad tabs_to_load_; + + base::OneShotTimer<TabLoader> force_load_timer_; + + DISALLOW_COPY_AND_ASSIGN(TabLoader); }; TabLoader::TabLoader() - : loading_(false) { + : force_load_delay_(kInitialDelayTimerMS), + loading_(false) { } TabLoader::~TabLoader() { DCHECK(tabs_to_load_.empty() && tabs_loading_.empty()); } -void TabLoader::AddTab(NavigationController* controller) { +void TabLoader::ScheduleLoad(NavigationController* controller) { if (controller) { DCHECK(find(tabs_to_load_.begin(), tabs_to_load_.end(), controller) == tabs_to_load_.end()); @@ -107,11 +126,13 @@ void TabLoader::AddTab(NavigationController* controller) { } } -void TabLoader::LoadTabs() { +void TabLoader::StartLoading() { loading_ = true; - while (!tabs_to_load_.empty() && - (SessionRestore::num_tabs_to_load_ == 0 || - tabs_loading_.size() < SessionRestore::num_tabs_to_load_)) { + LoadNextTab(); +} + +void TabLoader::LoadNextTab() { + if (!tabs_to_load_.empty()) { NavigationController* tab = tabs_to_load_.front(); tabs_loading_.insert(tab); tabs_to_load_.pop_front(); @@ -135,7 +156,14 @@ void TabLoader::LoadTabs() { if (tabs_to_load_.empty()) { tabs_loading_.clear(); delete this; + return; } + + if (force_load_timer_.IsRunning()) + force_load_timer_.Stop(); + force_load_timer_.Start( + base::TimeDelta::FromMilliseconds(force_load_delay_), + this, &TabLoader::ForceLoadTimerFired); } void TabLoader::Observe(NotificationType type, @@ -146,7 +174,7 @@ void TabLoader::Observe(NotificationType type, NavigationController* tab = Source<NavigationController>(source).ptr(); RemoveTab(tab); if (loading_) { - LoadTabs(); + LoadNextTab(); // WARNING: if there are no more tabs to load, we have been deleted. } } @@ -167,6 +195,11 @@ void TabLoader::RemoveTab(NavigationController* tab) { tabs_to_load_.erase(j); } +void TabLoader::ForceLoadTimerFired() { + force_load_delay_ *= 2; + LoadNextTab(); +} + // SessionRestoreImpl --------------------------------------------------------- // SessionRestoreImpl is responsible for fetching the set of tabs to create @@ -268,7 +301,7 @@ class SessionRestoreImpl : public NotificationObserver { if (succeeded) { DCHECK(tab_loader_.get()); // TabLoader delets itself when done loading. - tab_loader_.release()->LoadTabs(); + tab_loader_.release()->StartLoading(); } if (!synchronous_) { @@ -398,7 +431,8 @@ class SessionRestoreImpl : public NotificationObserver { 0, std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); - tab_loader_->AddTab(&browser->AddRestoredTab(tab.navigations, + tab_loader_->ScheduleLoad( + &browser->AddRestoredTab(tab.navigations, static_cast<int>(i - window.tabs.begin()), selected_index, tab.extension_app_id, @@ -492,9 +526,6 @@ class SessionRestoreImpl : public NotificationObserver { // SessionRestore ------------------------------------------------------------- -// static -size_t SessionRestore::num_tabs_to_load_ = 0; - static void Restore(Profile* profile, Browser* browser, bool synchronous, diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 04de5ab..42dc6fc 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -760,11 +760,6 @@ const char kSyncNotificationMethod[] = "sync-notification-method"; // Stop(). Should only use if you experience problems with the default. const char kSyncerThreadTimedStop[] = "syncer-thread-timed-stop"; -// Used to set the value of SessionRestore::num_tabs_to_load_. See -// session_restore.h for details. -const char kTabCountToLoadOnSessionRestore[]= - "tab-count-to-load-on-session-restore"; - // Pass the name of the current running automated test to Chrome. const char kTestName[] = "test-name"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index d21d221..a68f61c 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -213,7 +213,6 @@ extern const char kStartMaximized[]; extern const char kSyncServiceURL[]; extern const char kSyncNotificationMethod[]; extern const char kSyncerThreadTimedStop[]; -extern const char kTabCountToLoadOnSessionRestore[]; extern const char kTestName[]; extern const char kTestSandbox[]; extern const char kTestType[]; |