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_FINDER_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_FINDER_H_ |
6 #define CHROME_BROWSER_UI_BROWSER_FINDER_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_FINDER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/host_desktop.h" | |
12 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
13 | 12 |
14 class Profile; | 13 class Profile; |
15 | 14 |
16 namespace contents { | 15 namespace contents { |
17 class WebContents; | 16 class WebContents; |
18 } | 17 } |
19 | 18 |
20 // Collection of functions to find Browsers based on various criteria. | 19 // Collection of functions to find Browsers based on various criteria. |
21 | 20 |
22 namespace chrome { | 21 namespace chrome { |
23 | 22 |
24 // If you want to find the last active tabbed browser and create a new browser | 23 // If you want to find the last active tabbed browser and create a new browser |
25 // if there are no tabbed browsers, use ScopedTabbedBrowserDisplayer. | 24 // if there are no tabbed browsers, use ScopedTabbedBrowserDisplayer. |
26 | 25 |
27 // Retrieve the last active tabbed browser with a profile matching |profile|. | 26 // Retrieve the last active tabbed browser with a profile matching |profile|. |
28 // If |match_original_profiles| is true, matching is done based on the | 27 // If |match_original_profiles| is true, matching is done based on the |
29 // original profile, eg profile->GetOriginalProfile() == | 28 // original profile, eg profile->GetOriginalProfile() == |
30 // browser->profile()->GetOriginalProfile(). This has the effect of matching | 29 // browser->profile()->GetOriginalProfile(). This has the effect of matching |
31 // against both non-incognito and incognito profiles. If | 30 // against both non-incognito and incognito profiles. If |
32 // |match_original_profiles| is false, only an exact match may be returned. | 31 // |match_original_profiles| is false, only an exact match may be returned. |
33 // |type| refers to the host desktop the returned browser should belong to. | 32 Browser* FindTabbedBrowser(Profile* profile, bool match_original_profiles); |
34 Browser* FindTabbedBrowser(Profile* profile, | |
35 bool match_original_profiles, | |
36 HostDesktopType type); | |
37 | 33 |
38 // Finds an existing browser window of any kind. | 34 // Finds an existing browser window of any kind. |
39 // |type| refers to the host desktop the returned browser should belong to. | |
40 Browser* FindAnyBrowser(Profile* profile, | 35 Browser* FindAnyBrowser(Profile* profile, |
41 bool match_original_profiles, | 36 bool match_original_profiles); |
42 HostDesktopType type); | |
43 | 37 |
44 // Find an existing browser window with the provided profile and hosted in the | 38 // Find an existing browser window with the provided profile. Searches in the |
45 // given desktop. Searches in the order of last activation. Only browsers that | 39 // order of last activation. Only browsers that have been active can be |
46 // have been active can be returned. Returns NULL if no such browser currently | 40 // returned. Returns NULL if no such browser currently exists. |
47 // exists. | 41 Browser* FindBrowserWithProfile(Profile* profile); |
48 Browser* FindBrowserWithProfile(Profile* profile, HostDesktopType type); | |
49 | 42 |
50 // Find an existing browser with the provided ID. Returns NULL if no such | 43 // Find an existing browser with the provided ID. Returns NULL if no such |
51 // browser currently exists. | 44 // browser currently exists. |
52 Browser* FindBrowserWithID(SessionID::id_type desired_id); | 45 Browser* FindBrowserWithID(SessionID::id_type desired_id); |
53 | 46 |
54 // Find the browser represented by |window| or NULL if not found. | 47 // Find the browser represented by |window| or NULL if not found. |
55 Browser* FindBrowserWithWindow(gfx::NativeWindow window); | 48 Browser* FindBrowserWithWindow(gfx::NativeWindow window); |
56 | 49 |
57 // Find the browser containing |web_contents| or NULL if none is found. | 50 // Find the browser containing |web_contents| or NULL if none is found. |
58 // |web_contents| must not be NULL. | 51 // |web_contents| must not be NULL. |
59 Browser* FindBrowserWithWebContents(const content::WebContents* web_contents); | 52 Browser* FindBrowserWithWebContents(const content::WebContents* web_contents); |
60 | 53 |
61 // Returns the Browser object owned by |profile| on the given desktop type | 54 // Returns the Browser object owned by |profile| whose window was most recently |
62 // whose window was most recently active. If no such Browsers exist, returns | 55 // active. If no such Browsers exist, returns NULL. |
63 // NULL. | |
64 // | 56 // |
65 // WARNING: this is NULL until a browser becomes active. If during startup | 57 // WARNING: this is NULL until a browser becomes active. If during startup |
66 // a browser does not become active (perhaps the user launches Chrome, then | 58 // a browser does not become active (perhaps the user launches Chrome, then |
67 // clicks on another app before the first browser window appears) then this | 59 // clicks on another app before the first browser window appears) then this |
68 // returns NULL. | 60 // returns NULL. |
69 // WARNING #2: this will always be NULL in unit tests run on the bots. | 61 // WARNING #2: this will always be NULL in unit tests run on the bots. |
70 Browser* FindLastActiveWithProfile(Profile* profile); | 62 Browser* FindLastActiveWithProfile(Profile* profile); |
71 | 63 |
72 // Returns the Browser object on the given desktop type whose window was most | 64 // Returns the Browser object whose window was most recently active. If no such |
73 // recently active. If no such Browsers exist, returns NULL. | 65 // Browsers exist, returns NULL. |
74 // | 66 // |
75 // WARNING: this is NULL until a browser becomes active. If during startup | 67 // WARNING: this is NULL until a browser becomes active. If during startup |
76 // a browser does not become active (perhaps the user launches Chrome, then | 68 // a browser does not become active (perhaps the user launches Chrome, then |
77 // clicks on another app before the first browser window appears) then this | 69 // clicks on another app before the first browser window appears) then this |
78 // returns NULL. | 70 // returns NULL. |
79 // WARNING #2: this will always be NULL in unit tests run on the bots. | 71 // WARNING #2: this will always be NULL in unit tests run on the bots. |
80 Browser* FindLastActive(); | 72 Browser* FindLastActive(); |
81 | 73 |
82 // Returns the number of browsers across all profiles and desktops. | 74 // Returns the number of browsers across all profiles. |
83 size_t GetTotalBrowserCount(); | 75 size_t GetTotalBrowserCount(); |
84 | 76 |
85 // Returns the number of browsers with the Profile |profile| accross all | 77 // Returns the number of browsers with the Profile |profile|. |
86 // desktops. | 78 size_t GetBrowserCount(Profile* profile); |
87 size_t GetTotalBrowserCountForProfile(Profile* profile); | |
88 | 79 |
89 // Returns the number of browsers with the Profile |profile| on the desktop | 80 // Returns the number of tabbed browsers with the Profile |profile|. |
90 // defined by |type|. | 81 size_t GetTabbedBrowserCount(Profile* profile); |
91 size_t GetBrowserCount(Profile* profile, HostDesktopType type); | |
92 | |
93 // Returns the number of tabbed browsers with the Profile |profile| on the | |
94 // desktop defined by |type|. | |
95 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type); | |
96 | 82 |
97 } // namespace chrome | 83 } // namespace chrome |
98 | 84 |
99 #endif // CHROME_BROWSER_UI_BROWSER_FINDER_H_ | 85 #endif // CHROME_BROWSER_UI_BROWSER_FINDER_H_ |
OLD | NEW |