| 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_BROWSER_LIST_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
| 13 | 13 |
| 14 class Browser; | 14 class Browser; |
| 15 class Profile; | 15 class Profile; |
| 16 | 16 |
| 17 namespace browser { | 17 namespace browser { |
| 18 class BrowserActivityObserver; | 18 class BrowserActivityObserver; |
| 19 #if defined(OS_MACOSX) | 19 #if defined(OS_MACOSX) |
| 20 Browser* GetLastActiveBrowser(); | 20 Browser* GetLastActiveBrowser(); |
| 21 #endif | 21 #endif |
| 22 #if defined(TOOLKIT_GTK) | 22 #if defined(TOOLKIT_GTK) |
| 23 class ExtensionInstallDialog; | 23 class ExtensionInstallDialog; |
| 24 #endif | 24 #endif |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace chrome { | 27 namespace chrome { |
| 28 class BrowserListObserver; |
| 28 namespace internal { | 29 namespace internal { |
| 29 void NotifyNotDefaultBrowserCallback(); | 30 void NotifyNotDefaultBrowserCallback(); |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 | 33 |
| 33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 34 namespace chromeos { | 35 namespace chromeos { |
| 35 class ScreenLocker; | 36 class ScreenLocker; |
| 36 } | 37 } |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 namespace content { | 40 namespace content { |
| 40 class WebContents; | 41 class WebContents; |
| 41 } | 42 } |
| 42 | 43 |
| 43 #if defined(USE_ASH) | 44 #if defined(USE_ASH) |
| 44 content::WebContents* GetActiveWebContents(); | 45 content::WebContents* GetActiveWebContents(); |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 // Stores a list of all Browser objects. | 48 // Stores a list of all Browser objects. |
| 48 class BrowserList { | 49 class BrowserList { |
| 49 public: | 50 public: |
| 50 typedef std::vector<Browser*> BrowserVector; | 51 typedef std::vector<Browser*> BrowserVector; |
| 51 typedef BrowserVector::iterator iterator; | 52 typedef BrowserVector::iterator iterator; |
| 52 typedef BrowserVector::const_iterator const_iterator; | 53 typedef BrowserVector::const_iterator const_iterator; |
| 53 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; | 54 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
| 54 | 55 |
| 55 // It is not allowed to change the global window list (add or remove any | |
| 56 // browser windows while handling observer callbacks. | |
| 57 class Observer { | |
| 58 public: | |
| 59 // Called immediately after a browser is added to the list | |
| 60 virtual void OnBrowserAdded(Browser* browser) {} | |
| 61 | |
| 62 // Called immediately after a browser is removed from the list | |
| 63 virtual void OnBrowserRemoved(Browser* browser) {} | |
| 64 | |
| 65 // Called immediately after a browser is set active (SetLastActive) | |
| 66 virtual void OnBrowserSetLastActive(Browser* browser) {} | |
| 67 | |
| 68 protected: | |
| 69 virtual ~Observer() {} | |
| 70 }; | |
| 71 | |
| 72 // Adds and removes browsers from the global list. The browser object should | 56 // Adds and removes browsers from the global list. The browser object should |
| 73 // be valid BEFORE these calls (for the benefit of observers), so notify and | 57 // be valid BEFORE these calls (for the benefit of observers), so notify and |
| 74 // THEN delete the object. | 58 // THEN delete the object. |
| 75 static void AddBrowser(Browser* browser); | 59 static void AddBrowser(Browser* browser); |
| 76 static void RemoveBrowser(Browser* browser); | 60 static void RemoveBrowser(Browser* browser); |
| 77 | 61 |
| 78 static void AddObserver(Observer* observer); | 62 static void AddObserver(chrome::BrowserListObserver* observer); |
| 79 static void RemoveObserver(Observer* observer); | 63 static void RemoveObserver(chrome::BrowserListObserver* observer); |
| 80 | 64 |
| 81 // Called by Browser objects when their window is activated (focused). This | 65 // Called by Browser objects when their window is activated (focused). This |
| 82 // allows us to determine what the last active Browser was. | 66 // allows us to determine what the last active Browser was. |
| 83 static void SetLastActive(Browser* browser); | 67 static void SetLastActive(Browser* browser); |
| 84 | 68 |
| 85 // Closes all browsers for |profile|. | 69 // Closes all browsers for |profile|. |
| 86 static void CloseAllBrowsersWithProfile(Profile* profile); | 70 static void CloseAllBrowsersWithProfile(Profile* profile); |
| 87 | 71 |
| 88 // Browsers are added to the list before they have constructed windows, | 72 // Browsers are added to the list before they have constructed windows, |
| 89 // so the |window()| member function may return NULL. | 73 // so the |window()| member function may return NULL. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // in the list. If no Browsers exist, returns NULL. | 120 // in the list. If no Browsers exist, returns NULL. |
| 137 // | 121 // |
| 138 // WARNING: this is NULL until a browser becomes active. If during startup | 122 // WARNING: this is NULL until a browser becomes active. If during startup |
| 139 // a browser does not become active (perhaps the user launches Chrome, then | 123 // a browser does not become active (perhaps the user launches Chrome, then |
| 140 // clicks on another app before the first browser window appears) then this | 124 // clicks on another app before the first browser window appears) then this |
| 141 // returns NULL. | 125 // returns NULL. |
| 142 // WARNING #2: this will always be NULL in unit tests run on the bots. | 126 // WARNING #2: this will always be NULL in unit tests run on the bots. |
| 143 // THIS FUNCTION IS PRIVATE AND NOT TO BE USED AS A REPLACEMENT FOR RELEVANT | 127 // THIS FUNCTION IS PRIVATE AND NOT TO BE USED AS A REPLACEMENT FOR RELEVANT |
| 144 // CONTEXT. | 128 // CONTEXT. |
| 145 static Browser* GetLastActive(); | 129 static Browser* GetLastActive(); |
| 146 | |
| 147 // Helper method to remove a browser instance from a list of browsers | |
| 148 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); | |
| 149 }; | 130 }; |
| 150 | 131 |
| 151 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ | 132 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| OLD | NEW |