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