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 #ifndef CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 | 14 |
15 class Browser; | 15 class Browser; |
16 class TabContents; | 16 class TabContents; |
17 class TabStripModel; | 17 class TabStripModel; |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 class NotificationSource; | 20 class NotificationSource; |
21 class NotifictaionDetails; | 21 class NotifictaionDetails; |
22 class WebContents; | 22 class WebContents; |
23 } | 23 } |
24 | 24 |
25 namespace chrome { | 25 namespace chrome { |
26 class UnloadDetachedHandler; | |
26 | 27 |
27 class UnloadController : public content::NotificationObserver, | 28 class UnloadController : public content::NotificationObserver, |
Ben Goodger (Google)
2012/10/26 19:35:14
It would be good if you could codify your knowledg
slamm
2012/10/26 23:16:32
Done.
| |
28 public TabStripModelObserver { | 29 public TabStripModelObserver { |
29 public: | 30 public: |
30 explicit UnloadController(Browser* browser); | 31 explicit UnloadController(Browser* browser); |
31 virtual ~UnloadController(); | 32 virtual ~UnloadController(); |
32 | 33 |
33 // Returns true if |contents| can be cleanly closed. When |browser_| is being | 34 // Returns true if |contents| can be cleanly closed. When |browser_| is being |
34 // closed, this function will return false to indicate |contents| should not | 35 // closed, this function will return false to indicate |contents| should not |
35 // be cleanly closed, since the fast shutdown path will just kill its | 36 // be cleanly closed, since the fast shutdown path will just kill its |
36 // renderer. | 37 // renderer. |
37 bool CanCloseContents(content::WebContents* contents); | 38 bool CanCloseContents(content::WebContents* contents); |
(...skipping 17 matching lines...) Expand all Loading... | |
55 | 56 |
56 // Returns true if |browser_| has any tabs that have BeforeUnload handlers | 57 // Returns true if |browser_| has any tabs that have BeforeUnload handlers |
57 // that have not been fired. This method is non-const because it builds a list | 58 // that have not been fired. This method is non-const because it builds a list |
58 // of tabs that need their BeforeUnloadHandlers fired. | 59 // of tabs that need their BeforeUnloadHandlers fired. |
59 // TODO(beng): This seems like it could be private but it is used by | 60 // TODO(beng): This seems like it could be private but it is used by |
60 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems | 61 // AreAllBrowsersCloseable() in application_lifetime.cc. It seems |
61 // very similar to ShouldCloseWindow() and some consolidation | 62 // very similar to ShouldCloseWindow() and some consolidation |
62 // could be pursued. | 63 // could be pursued. |
63 bool TabsNeedBeforeUnloadFired(); | 64 bool TabsNeedBeforeUnloadFired(); |
64 | 65 |
66 // Called when detached tabs (if any) finish closing. | |
67 void DetachedTabsClosedCallback(); | |
68 | |
65 private: | 69 private: |
66 typedef std::set<content::WebContents*> UnloadListenerSet; | 70 typedef std::set<content::WebContents*> UnloadListenerSet; |
67 | 71 |
68 // Overridden from content::NotificationObserver: | 72 // Overridden from content::NotificationObserver: |
69 virtual void Observe(int type, | 73 virtual void Observe(int type, |
70 const content::NotificationSource& source, | 74 const content::NotificationSource& source, |
71 const content::NotificationDetails& details) OVERRIDE; | 75 const content::NotificationDetails& details) OVERRIDE; |
72 | 76 |
73 // Overridden from TabStripModelObserver: | 77 // Overridden from TabStripModelObserver: |
74 virtual void TabInsertedAt(TabContents* contents, | 78 virtual void TabInsertedAt(TabContents* contents, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 // | 111 // |
108 // Typically you'll want to pass in true for |process_now|. Passing in true | 112 // Typically you'll want to pass in true for |process_now|. Passing in true |
109 // may result in deleting |tab|. If you know that shouldn't happen (because of | 113 // may result in deleting |tab|. If you know that shouldn't happen (because of |
110 // the state of the stack), pass in false. | 114 // the state of the stack), pass in false. |
111 void ClearUnloadState(content::WebContents* web_contents, bool process_now); | 115 void ClearUnloadState(content::WebContents* web_contents, bool process_now); |
112 | 116 |
113 Browser* browser_; | 117 Browser* browser_; |
114 | 118 |
115 content::NotificationRegistrar registrar_; | 119 content::NotificationRegistrar registrar_; |
116 | 120 |
117 // Tracks tabs that need there beforeunload event fired before we can | 121 // Tracks tabs that need their beforeunload event fired before we can |
118 // close the browser. Only gets populated when we try to close the browser. | 122 // close the browser. Only gets populated when we try to close the browser. |
119 UnloadListenerSet tabs_needing_before_unload_fired_; | 123 UnloadListenerSet tabs_needing_before_unload_fired_; |
120 | 124 |
121 // Tracks tabs that need there unload event fired before we can | 125 // Tracks tabs that need their unload event fired before we can |
122 // close the browser. Only gets populated when we try to close the browser. | 126 // close the browser. Only gets populated when we try to close the browser. |
123 UnloadListenerSet tabs_needing_unload_fired_; | 127 UnloadListenerSet tabs_needing_unload_fired_; |
124 | 128 |
125 // Whether we are processing the beforeunload and unload events of each tab | 129 // Whether we are processing the beforeunload and unload events of each tab |
126 // in preparation for closing the browser. UnloadController owns this state | 130 // in preparation for closing the browser. UnloadController owns this state |
127 // rather than Browser because unload handlers are the only reason that a | 131 // rather than Browser because unload handlers are the only reason that a |
128 // Browser window isn't just immediately closed. | 132 // Browser window isn't just immediately closed. |
129 bool is_attempting_to_close_browser_; | 133 bool is_attempting_to_close_browser_; |
130 | 134 |
135 // Allow unload handlers to run without holding up the UI. | |
136 UnloadDetachedHandler* const unload_detached_handler_; | |
137 | |
131 base::WeakPtrFactory<UnloadController> weak_factory_; | 138 base::WeakPtrFactory<UnloadController> weak_factory_; |
132 | 139 |
133 DISALLOW_COPY_AND_ASSIGN(UnloadController); | 140 DISALLOW_COPY_AND_ASSIGN(UnloadController); |
134 }; | 141 }; |
135 | 142 |
136 } // namespace chrome | 143 } // namespace chrome |
137 | 144 |
138 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ | 145 #endif // CHROME_BROWSER_UI_UNLOAD_CONTROLLER_H_ |
OLD | NEW |