| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
| 6 #define CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ | 6 #define CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/memory/memory_pressure_listener.h" | 11 #include "base/memory/memory_pressure_listener.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/sessions/session_restore_delegate.h" |
| 14 #include "chrome/browser/sessions/tab_loader_delegate.h" | 15 #include "chrome/browser/sessions/tab_loader_delegate.h" |
| 15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class NavigationController; | 20 class NavigationController; |
| 20 class RenderWidgetHost; | 21 class RenderWidgetHost; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // TabLoader is responsible for loading tabs after session restore has finished | 24 // TabLoader is responsible for loading tabs after session restore has finished |
| 24 // creating all the tabs. Tabs are loaded after a previously tab finishes | 25 // creating all the tabs. Tabs are loaded after a previously tab finishes |
| 25 // loading or a timeout is reached. If the timeout is reached before a tab | 26 // loading or a timeout is reached. If the timeout is reached before a tab |
| 26 // finishes loading the timeout delay is doubled. | 27 // finishes loading the timeout delay is doubled. |
| 27 // | 28 // |
| 28 // TabLoader keeps a reference to itself when it's loading. When it has finished | 29 // TabLoader keeps a reference to itself when it's loading. When it has finished |
| 29 // loading, it drops the reference. If another profile is restored while the | 30 // loading, it drops the reference. If another profile is restored while the |
| 30 // TabLoader is loading, it will schedule its tabs to get loaded by the same | 31 // TabLoader is loading, it will schedule its tabs to get loaded by the same |
| 31 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. | 32 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. |
| 32 // | 33 // |
| 33 // This is not part of SessionRestoreImpl so that synchronous destruction | 34 // This is not part of SessionRestoreImpl so that synchronous destruction |
| 34 // of SessionRestoreImpl doesn't have timing problems. | 35 // of SessionRestoreImpl doesn't have timing problems. |
| 35 class TabLoader : public content::NotificationObserver, | 36 class TabLoader : public content::NotificationObserver, |
| 36 public base::RefCounted<TabLoader>, | 37 public base::RefCounted<TabLoader>, |
| 38 public SessionRestoreDelegate, |
| 37 public TabLoaderCallback { | 39 public TabLoaderCallback { |
| 38 public: | 40 public: |
| 39 // Retrieves a pointer to the TabLoader instance shared between profiles, or | 41 // NotificationObserver method. Removes the specified tab and loads the next |
| 40 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its | 42 // tab. |
| 41 // starting timestamp is set to |restore_started|. | 43 void Observe(int type, |
| 42 static TabLoader* GetTabLoader(base::TimeTicks restore_started); | 44 const content::NotificationSource& source, |
| 43 | 45 const content::NotificationDetails& details) override; |
| 44 // Schedules a tab for loading. | |
| 45 void ScheduleLoad(content::NavigationController* controller); | |
| 46 | |
| 47 // Notifies the loader that a tab has been scheduled for loading through | |
| 48 // some other mechanism. | |
| 49 void TabIsLoading(content::NavigationController* controller); | |
| 50 | |
| 51 // Invokes |LoadNextTab| to load a tab. | |
| 52 // | |
| 53 // This must be invoked once to start loading. | |
| 54 void StartLoading(); | |
| 55 | 46 |
| 56 // TabLoaderCallback: | 47 // TabLoaderCallback: |
| 57 void SetTabLoadingEnabled(bool enable_tab_loading) override; | 48 void SetTabLoadingEnabled(bool enable_tab_loading) override; |
| 58 | 49 |
| 50 // Called to start restoring tabs. |
| 51 static void RestoreTabs(const std::vector<RestoredTab>& tabs_, |
| 52 const base::TimeTicks& restore_started); |
| 53 |
| 59 private: | 54 private: |
| 60 friend class base::RefCounted<TabLoader>; | 55 friend class base::RefCounted<TabLoader>; |
| 61 | 56 |
| 62 typedef std::set<content::NavigationController*> TabsLoading; | 57 typedef std::set<content::NavigationController*> TabsLoading; |
| 63 typedef std::list<content::NavigationController*> TabsToLoad; | 58 typedef std::list<content::NavigationController*> TabsToLoad; |
| 64 typedef std::set<content::RenderWidgetHost*> RenderWidgetHostSet; | 59 typedef std::set<content::RenderWidgetHost*> RenderWidgetHostSet; |
| 65 | 60 |
| 66 explicit TabLoader(base::TimeTicks restore_started); | 61 explicit TabLoader(base::TimeTicks restore_started); |
| 67 ~TabLoader() override; | 62 ~TabLoader() override; |
| 68 | 63 |
| 64 // This is invoked once by RestoreTabs to start loading. |
| 65 void StartLoading(const std::vector<RestoredTab>& tabs); |
| 66 |
| 67 // Schedules a tab for loading. |
| 68 void ScheduleLoad(content::NavigationController* controller); |
| 69 |
| 70 // Notifies the loader that a tab has been scheduled for loading through |
| 71 // some other mechanism. |
| 72 void TabIsLoading(content::NavigationController* controller); |
| 73 |
| 69 // Loads the next tab. If there are no more tabs to load this deletes itself, | 74 // Loads the next tab. If there are no more tabs to load this deletes itself, |
| 70 // otherwise |force_load_timer_| is restarted. | 75 // otherwise |force_load_timer_| is restarted. |
| 71 void LoadNextTab(); | 76 void LoadNextTab(); |
| 72 | 77 |
| 73 // Starts a timer to load load the next tab once expired before the current | 78 // Starts a timer to load load the next tab once expired before the current |
| 74 // tab loading is finished. | 79 // tab loading is finished. |
| 75 void StartTimer(); | 80 void StartTimer(); |
| 76 | 81 |
| 77 // NotificationObserver method. Removes the specified tab and loads the next | |
| 78 // tab. | |
| 79 void Observe(int type, | |
| 80 const content::NotificationSource& source, | |
| 81 const content::NotificationDetails& details) override; | |
| 82 | |
| 83 // Removes the listeners from the specified tab and removes the tab from | 82 // Removes the listeners from the specified tab and removes the tab from |
| 84 // the set of tabs to load and list of tabs we're waiting to get a load | 83 // the set of tabs to load and list of tabs we're waiting to get a load |
| 85 // from. | 84 // from. |
| 86 void RemoveTab(content::NavigationController* tab); | 85 void RemoveTab(content::NavigationController* tab); |
| 87 | 86 |
| 88 // Invoked from |force_load_timer_|. Doubles |force_load_delay_multiplier_| | 87 // Invoked from |force_load_timer_|. Doubles |force_load_delay_multiplier_| |
| 89 // and invokes |LoadNextTab| to load the next tab | 88 // and invokes |LoadNextTab| to load the next tab |
| 90 void ForceLoadTimerFired(); | 89 void ForceLoadTimerFired(); |
| 91 | 90 |
| 92 // Returns the RenderWidgetHost associated with a tab if there is one, | 91 // Returns the RenderWidgetHost associated with a tab if there is one, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // For keeping TabLoader alive while it's loading even if no | 153 // For keeping TabLoader alive while it's loading even if no |
| 155 // SessionRestoreImpls reference it. | 154 // SessionRestoreImpls reference it. |
| 156 scoped_refptr<TabLoader> this_retainer_; | 155 scoped_refptr<TabLoader> this_retainer_; |
| 157 | 156 |
| 158 static TabLoader* shared_tab_loader_; | 157 static TabLoader* shared_tab_loader_; |
| 159 | 158 |
| 160 DISALLOW_COPY_AND_ASSIGN(TabLoader); | 159 DISALLOW_COPY_AND_ASSIGN(TabLoader); |
| 161 }; | 160 }; |
| 162 | 161 |
| 163 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ | 162 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
| OLD | NEW |