Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/sessions/tab_loader.h

Issue 1052733002: Decouple TabLoader from SessionRestore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky@ review. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>,
37 public TabLoaderCallback { 38 public TabLoaderCallback {
38 public: 39 public:
39 // Retrieves a pointer to the TabLoader instance shared between profiles, or 40 using RestoredTab = SessionRestoreDelegate::RestoredTab;
Georges Khalil 2015/04/01 23:30:21 Necessary up here because of RestoreTabs function.
40 // creates a new TabLoader if it doesn't exist. If a TabLoader is created, its 41
41 // starting timestamp is set to |restore_started|. 42 // NotificationObserver method. Removes the specified tab and loads the next
42 static TabLoader* GetTabLoader(base::TimeTicks restore_started); 43 // tab.
44 void Observe(int type,
45 const content::NotificationSource& source,
46 const content::NotificationDetails& details) override;
47
48 // TabLoaderCallback:
49 void SetTabLoadingEnabled(bool enable_tab_loading) override;
50
51 // Called to start restoring tabs.
52 static void RestoreTabs(const std::vector<RestoredTab>& tabs_,
53 const base::TimeTicks& restore_started);
54
55 private:
56 friend class base::RefCounted<TabLoader>;
57
58 using TabsLoading = std::set<content::NavigationController*>;
59 using TabsToLoad = std::list<content::NavigationController*>;
60 using RenderWidgetHostSet = std::set<content::RenderWidgetHost*>;
Georges Khalil 2015/04/01 23:30:21 Changed to new syntax to match RestoredTab.
61
62 explicit TabLoader(base::TimeTicks restore_started);
63 ~TabLoader() override;
64
65 // This is invoked once by RestoreTabs to start loading.
66 void StartLoading(const std::vector<RestoredTab>& tabs);
43 67
44 // Schedules a tab for loading. 68 // Schedules a tab for loading.
45 void ScheduleLoad(content::NavigationController* controller); 69 void ScheduleLoad(content::NavigationController* controller);
46 70
47 // Notifies the loader that a tab has been scheduled for loading through 71 // Notifies the loader that a tab has been scheduled for loading through
48 // some other mechanism. 72 // some other mechanism.
49 void TabIsLoading(content::NavigationController* controller); 73 void TabIsLoading(content::NavigationController* controller);
50 74
51 // Invokes |LoadNextTab| to load a tab.
52 //
53 // This must be invoked once to start loading.
54 void StartLoading();
55
56 // TabLoaderCallback:
57 void SetTabLoadingEnabled(bool enable_tab_loading) override;
58
59 private:
60 friend class base::RefCounted<TabLoader>;
61
62 typedef std::set<content::NavigationController*> TabsLoading;
63 typedef std::list<content::NavigationController*> TabsToLoad;
64 typedef std::set<content::RenderWidgetHost*> RenderWidgetHostSet;
65
66 explicit TabLoader(base::TimeTicks restore_started);
67 ~TabLoader() override;
68
69 // Loads the next tab. If there are no more tabs to load this deletes itself, 75 // Loads the next tab. If there are no more tabs to load this deletes itself,
70 // otherwise |force_load_timer_| is restarted. 76 // otherwise |force_load_timer_| is restarted.
71 void LoadNextTab(); 77 void LoadNextTab();
72 78
73 // Starts a timer to load load the next tab once expired before the current 79 // Starts a timer to load load the next tab once expired before the current
74 // tab loading is finished. 80 // tab loading is finished.
75 void StartTimer(); 81 void StartTimer();
76 82
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 83 // 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 84 // the set of tabs to load and list of tabs we're waiting to get a load
85 // from. 85 // from.
86 void RemoveTab(content::NavigationController* tab); 86 void RemoveTab(content::NavigationController* tab);
87 87
88 // Invoked from |force_load_timer_|. Doubles |force_load_delay_multiplier_| 88 // Invoked from |force_load_timer_|. Doubles |force_load_delay_multiplier_|
89 // and invokes |LoadNextTab| to load the next tab 89 // and invokes |LoadNextTab| to load the next tab
90 void ForceLoadTimerFired(); 90 void ForceLoadTimerFired();
91 91
92 // Returns the RenderWidgetHost associated with a tab if there is one, 92 // Returns the RenderWidgetHost associated with a tab if there is one,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // For keeping TabLoader alive while it's loading even if no 154 // For keeping TabLoader alive while it's loading even if no
155 // SessionRestoreImpls reference it. 155 // SessionRestoreImpls reference it.
156 scoped_refptr<TabLoader> this_retainer_; 156 scoped_refptr<TabLoader> this_retainer_;
157 157
158 static TabLoader* shared_tab_loader_; 158 static TabLoader* shared_tab_loader_;
159 159
160 DISALLOW_COPY_AND_ASSIGN(TabLoader); 160 DISALLOW_COPY_AND_ASSIGN(TabLoader);
161 }; 161 };
162 162
163 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ 163 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore_delegate.cc ('k') | chrome/browser/sessions/tab_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698