Skip to content

Commit

Permalink
Moves methods for finding browsers to browser_finder.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none
R=ben@chromium.org
TBR=tim@chromium.org, davemoore@chromium.org, scottbyer@chromium.org, keybuk@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10391158

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137511 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed May 16, 2012
1 parent 08ac3eb commit d874814
Show file tree
Hide file tree
Showing 152 changed files with 670 additions and 575 deletions.
4 changes: 3 additions & 1 deletion chrome/browser/accessibility/invert_bubble_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "chrome/browser/accessibility/invert_bubble_views.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/views/event_utils.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -141,7 +143,7 @@ void InvertBubbleView::LinkClicked(views::Link* source, int event_flags) {
}

void InvertBubbleView::OpenLink(const std::string& url, int event_flags) {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
Browser* browser = browser::FindLastActiveWithProfile(profile_);
if (browser) {
WindowOpenDisposition disposition =
event_utils::DispositionFromEventFlags(event_flags);
Expand Down
9 changes: 5 additions & 4 deletions chrome/browser/app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/sync/sync_ui_util_mac.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
Expand Down Expand Up @@ -106,7 +107,7 @@ - (void)setHelpMenu:(NSMenu*)helpMenu;
// not possible. If the last active browser is minimized (in particular, if
// there are only minimized windows), it will unminimize it.
Browser* ActivateBrowser(Profile* profile) {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
Browser* browser = browser::FindLastActiveWithProfile(profile);
if (browser)
browser->window()->Activate();
return browser;
Expand Down Expand Up @@ -372,8 +373,8 @@ - (void)applicationWillTerminate:(NSNotification*)aNotification {
}

- (void)didEndMainMessageLoop {
DCHECK(!BrowserList::HasBrowserWithProfile([self lastProfile]));
if (!BrowserList::HasBrowserWithProfile([self lastProfile])) {
DCHECK_EQ(0u, browser::GetBrowserCount([self lastProfile]));
if (!browser::GetBrowserCount([self lastProfile])) {
// As we're shutting down, we need to nuke the TabRestoreService, which
// will start the shutdown of the NavigationControllers and allow for
// proper shutdown. If we don't do this, Chrome won't shut down cleanly,
Expand Down Expand Up @@ -682,7 +683,7 @@ - (BOOL)shouldQuitWithInProgressDownloads {
if ([self userWillWaitForInProgressDownloads:downloadCount]) {
// Create a new browser window (if necessary) and navigate to the
// downloads page if the user chooses to wait.
Browser* browser = BrowserList::FindBrowserWithProfile(profiles[i]);
Browser* browser = browser::FindBrowserWithProfile(profiles[i]);
if (!browser) {
browser = Browser::Create(profiles[i]);
browser->window()->Show();
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/app_controller_mac_browsertest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/memory/scoped_nsobject.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/app_controller_mac.h"
#import "chrome/browser/ui/browser.h"
#import "chrome/browser/ui/browser_list.h"
#import "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/webui/feedback_ui.h"
#include "chrome/browser/feedback/proto/extension.pb.h"
#include "content/public/browser/navigation_controller.h"
Expand Down Expand Up @@ -45,7 +46,7 @@ string16 AutofillFeedbackInfoBarDelegate::GetLinkText() const {
bool AutofillFeedbackInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
browser::ShowWebFeedbackView(
Browser::GetBrowserForController(
browser::FindBrowserForController(
&owner()->web_contents()->GetController(), NULL),
feedback_message_,
std::string(kCategoryTagAutofill));
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/autofill/autofill_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/autofill_messages.h"
Expand Down Expand Up @@ -635,7 +635,7 @@ void AutofillManager::OnShowAutofillDialog() {
#if defined(OS_ANDROID)
NOTIMPLEMENTED();
#else
Browser* browser = BrowserList::GetLastActiveWithProfile(
Browser* browser = browser::FindLastActiveWithProfile(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
if (browser)
browser->ShowOptionsTab(chrome::kAutofillSubPage);
Expand Down Expand Up @@ -691,7 +691,7 @@ void AutofillManager::OnShowPasswordGenerationPopup(const gfx::Rect& bounds) {
#if defined(OS_ANDROID)
NOTIMPLEMENTED();
#else
Browser* browser = BrowserList::GetLastActiveWithProfile(
Browser* browser = browser::FindLastActiveWithProfile(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
browser->window()->ShowPasswordGenerationBubble(bounds);
#endif // #if defined(OS_ANDROID)
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/automation/automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "chrome/browser/ssl/ssl_blocking_page.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
Expand Down Expand Up @@ -472,7 +472,7 @@ bool AutomationProvider::Send(IPC::Message* msg) {
Browser* AutomationProvider::FindAndActivateTab(
NavigationController* controller) {
int tab_index;
Browser* browser = Browser::GetBrowserForController(controller, &tab_index);
Browser* browser = browser::FindBrowserForController(controller, &tab_index);
if (browser)
browser->ActivateTabAt(tab_index, true);

Expand Down
13 changes: 7 additions & 6 deletions chrome/browser/automation/testing_automation_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
#include "chrome/browser/ui/bookmarks/bookmark_bar.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/find_bar/find_bar.h"
#include "chrome/browser/ui/fullscreen_controller.h"
Expand Down Expand Up @@ -631,7 +633,7 @@ void TestingAutomationProvider::CloseTab(int tab_handle,
if (tab_tracker_->ContainsHandle(tab_handle)) {
NavigationController* controller = tab_tracker_->GetResource(tab_handle);
int index;
Browser* browser = Browser::GetBrowserForController(controller, &index);
Browser* browser = browser::FindBrowserForController(controller, &index);
DCHECK(browser);
new TabClosedNotificationObserver(this, wait_until_closed, reply_message);
browser->CloseTabContents(controller->GetWebContents());
Expand Down Expand Up @@ -748,8 +750,7 @@ void TestingAutomationProvider::GetBrowserWindowCount(int* window_count) {
}

void TestingAutomationProvider::GetNormalBrowserWindowCount(int* window_count) {
*window_count = static_cast<int>(
BrowserList::GetBrowserCountForType(profile_, true));
*window_count = static_cast<int>(browser::GetTabbedBrowserCount(profile_));
}

void TestingAutomationProvider::GetBrowserWindow(int index, int* handle) {
Expand All @@ -761,7 +762,7 @@ void TestingAutomationProvider::GetBrowserWindow(int index, int* handle) {

void TestingAutomationProvider::FindTabbedBrowserWindow(int* handle) {
*handle = 0;
Browser* browser = BrowserList::FindTabbedBrowser(profile_, false);
Browser* browser = browser::FindTabbedBrowser(profile_, false);
if (browser)
*handle = browser_tracker_->Add(browser);
}
Expand Down Expand Up @@ -1253,7 +1254,7 @@ void TestingAutomationProvider::GetTabIndex(int handle, int* tabstrip_index) {

if (tab_tracker_->ContainsHandle(handle)) {
NavigationController* tab = tab_tracker_->GetResource(handle);
Browser* browser = Browser::GetBrowserForController(tab, NULL);
Browser* browser = browser::FindBrowserForController(tab, NULL);
*tabstrip_index = browser->GetIndexOfController(tab);
}
}
Expand Down Expand Up @@ -7107,7 +7108,7 @@ void TestingAutomationProvider::GetParentBrowserOfTab(int tab_handle,
if (tab_tracker_->ContainsHandle(tab_handle)) {
NavigationController* controller = tab_tracker_->GetResource(tab_handle);
int index;
Browser* browser = Browser::GetBrowserForController(controller, &index);
Browser* browser = browser::FindBrowserForController(controller, &index);
if (browser) {
*browser_handle = browser_tracker_->Add(browser);
*success = true;
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/automation/testing_automation_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PowerManagerClientObserverForTesting;
class AutofillProfile;
class CreditCard;
class ImporterList;
struct NativeWebKeyboardEvent;

namespace base {
class DictionaryValue;
Expand All @@ -44,6 +45,10 @@ namespace content {
class RenderViewHost;
}

namespace gfx {
class Rect;
}

namespace webkit {
struct WebPluginInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "chrome/browser/policy/cloud_policy_subsystem.h"
#include "chrome/browser/policy/enterprise_install_attributes.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/common/pref_names.h"
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/automation/testing_automation_provider_win.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -10,6 +10,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/automation_browser_tracker.h"
#include "chrome/browser/automation/automation_window_tracker.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"

void TestingAutomationProvider::ActivateWindow(int handle) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/background/background_contents_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
Expand Down Expand Up @@ -605,7 +605,7 @@ void BackgroundContentsService::AddWebContents(
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
Browser* browser = BrowserList::GetLastActiveWithProfile(
Browser* browser = browser::FindLastActiveWithProfile(
Profile::FromBrowserContext(new_contents->GetBrowserContext()));
if (!browser)
return;
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/background/background_mode_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
Expand Down Expand Up @@ -85,10 +87,10 @@ void BackgroundModeManager::BackgroundModeData::ExecuteCommand(int item) {
}

Browser* BackgroundModeManager::BackgroundModeData::GetBrowserWindow() {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
Browser* browser = browser::FindLastActiveWithProfile(profile_);
if (!browser) {
Browser::OpenEmptyWindow(profile_);
browser = BrowserList::GetLastActiveWithProfile(profile_);
browser = browser::FindLastActiveWithProfile(profile_);
}
return browser;
}
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/bookmarks/bookmark_context_menu_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/user_metrics.h"
Expand Down Expand Up @@ -197,7 +197,7 @@ void BookmarkContextMenuController::ExecuteCommand(int id) {

case IDC_BOOKMARK_MANAGER: {
content::RecordAction(UserMetricsAction("ShowBookmarkManager"));
Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
Browser* browser = browser::FindLastActiveWithProfile(profile_);
if (!browser) NOTREACHED();

if (selection_.size() != 1)
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/bookmarks/bookmark_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -155,7 +155,7 @@ void OpenAllImpl(const BookmarkNode* node,
*opened_url = true;
// We opened the first URL which may have opened a new window or clobbered
// the current page, reset the navigator just to be sure.
Browser* new_browser = BrowserList::GetLastActiveWithProfile(profile);
Browser* new_browser = browser::FindLastActiveWithProfile(profile);
if (new_browser) {
WebContents* current_tab = new_browser->GetSelectedWebContents();
if (current_tab)
Expand Down Expand Up @@ -388,7 +388,7 @@ void OpenAll(gfx::NativeWindow parent,

NewBrowserPageNavigator navigator_impl(profile);
if (!navigator) {
Browser* browser = BrowserList::FindTabbedBrowser(profile, false);
Browser* browser = browser::FindTabbedBrowser(profile, false);
if (!browser || !browser->GetSelectedWebContents()) {
navigator = &navigator_impl;
} else {
Expand Down Expand Up @@ -666,7 +666,7 @@ void GetURLAndTitleToBookmark(WebContents* web_contents,
void GetURLAndTitleToBookmarkFromCurrentTab(Profile* profile,
GURL* url,
string16* title) {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
Browser* browser = browser::FindLastActiveWithProfile(profile);
WebContents* web_contents = browser ? browser->GetSelectedWebContents()
: NULL;
if (web_contents)
Expand Down
19 changes: 8 additions & 11 deletions chrome/browser/chrome_main_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunch) {
ui_test_utils::BrowserAddedObserver observer;
Relaunch(GetCommandLineForRelaunch());
observer.WaitForSingleNewBrowser();
ASSERT_EQ(BrowserList::GetBrowserCount(browser()->profile()), 2u);
ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile()));
}

IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) {
Expand All @@ -61,8 +62,7 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) {

IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchWithIncognitoUrl) {
// We should start with one normal window.
ASSERT_EQ(1u,
BrowserList::GetBrowserCountForType(browser()->profile(), true));
ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile()));

// Run with --incognito switch and an URL specified.
FilePath test_file_path = ui_test_utils::GetTestFilePath(
Expand All @@ -79,21 +79,18 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchWithIncognitoUrl) {
observer.WaitForSingleNewBrowser();
ASSERT_EQ(2u, BrowserList::size());

ASSERT_EQ(1u,
BrowserList::GetBrowserCountForType(browser()->profile(), true));
ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile()));
}

IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) {
// We should start with one normal window.
ASSERT_EQ(1u,
BrowserList::GetBrowserCountForType(browser()->profile(), true));
ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile()));

// Create an incognito window.
browser()->NewIncognitoWindow();

ASSERT_EQ(2u, BrowserList::size());
ASSERT_EQ(1u,
BrowserList::GetBrowserCountForType(browser()->profile(), true));
ASSERT_EQ(1u, browser::GetTabbedBrowserCount(browser()->profile()));

// Close the first window.
Profile* profile = browser()->profile();
Expand All @@ -105,7 +102,7 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) {

// There should only be the incognito window open now.
ASSERT_EQ(1u, BrowserList::size());
ASSERT_EQ(0u, BrowserList::GetBrowserCountForType(profile, true));
ASSERT_EQ(0u, browser::GetTabbedBrowserCount(profile));

// Run with just an URL specified, no --incognito switch.
FilePath test_file_path = ui_test_utils::GetTestFilePath(
Expand All @@ -120,7 +117,7 @@ IN_PROC_BROWSER_TEST_F(ChromeMainTest, SecondLaunchFromIncognitoWithNormalUrl) {

// There should be one normal and one incognito window now.
ASSERT_EQ(2u, BrowserList::size());
ASSERT_EQ(1u, BrowserList::GetBrowserCountForType(profile, true));
ASSERT_EQ(1u, browser::GetTabbedBrowserCount(profile));
}

#endif // !OS_MACOSX
Loading

0 comments on commit d874814

Please sign in to comment.