summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-12 22:58:17 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-12 22:58:17 +0000
commit3770c24a1359d01dae7c48508fda5a55c342ee1e (patch)
tree9ee9ae3397fa4225ebd061597378d5117791dfe1 /chrome/browser
parentbe61f4b20100e2b4514b670c36ed69527664513b (diff)
downloadchromium_src-3770c24a1359d01dae7c48508fda5a55c342ee1e.zip
chromium_src-3770c24a1359d01dae7c48508fda5a55c342ee1e.tar.gz
chromium_src-3770c24a1359d01dae7c48508fda5a55c342ee1e.tar.bz2
Move implementation of BrowserList onto an inner, instantiatable class, BrowserListImpl.
This is so we can create one BrowserListImpl per universe. Eventually we'll get rid of BrowserList, but for now this change strives for compat. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10690151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/automation/testing_automation_provider.h6
-rw-r--r--chrome/browser/chrome_browser_main.cc2
-rw-r--r--chrome/browser/chromeos/extensions/file_manager_util.cc1
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_api.cc1
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_api.h6
-rw-r--r--chrome/browser/extensions/bundle_installer.cc1
-rw-r--r--chrome/browser/extensions/bundle_installer.h6
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc1
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.h8
-rw-r--r--chrome/browser/importer/importer_host.cc1
-rw-r--r--chrome/browser/importer/importer_host.h6
-rw-r--r--chrome/browser/managed_mode.cc1
-rw-r--r--chrome/browser/managed_mode.h6
-rw-r--r--chrome/browser/page_cycler/page_cycler.cc2
-rw-r--r--chrome/browser/page_cycler/page_cycler.h9
-rw-r--r--chrome/browser/page_cycler/page_cycler_unittest.cc1
-rw-r--r--chrome/browser/profiles/profile_manager.cc1
-rw-r--r--chrome/browser/profiles/profile_manager.h6
-rw-r--r--chrome/browser/protector/settings_change_global_error.cc1
-rw-r--r--chrome/browser/protector/settings_change_global_error.h6
-rw-r--r--chrome/browser/ui/browser_close_browsertest.cc1
-rw-r--r--chrome/browser/ui/browser_list.cc269
-rw-r--r--chrome/browser/ui/browser_list.h25
-rw-r--r--chrome/browser/ui/browser_list_impl.cc206
-rw-r--r--chrome/browser/ui/browser_list_impl.h94
-rw-r--r--chrome/browser/ui/browser_list_observer.h31
-rw-r--r--chrome/browser/ui/cocoa/profile_menu_controller.mm5
-rw-r--r--chrome/browser/ui/host_desktop.h34
-rw-r--r--chrome/browser/ui/network_profile_bubble.cc8
-rw-r--r--chrome/browser/ui/startup/startup_browser_creator_browsertest.cc3
-rw-r--r--chrome/browser/ui/uma_browsing_activity_observer.cc88
-rw-r--r--chrome/browser/ui/uma_browsing_activity_observer.h45
32 files changed, 576 insertions, 305 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h
index 884e9ff..fb3cdbf 100644
--- a/chrome/browser/automation/testing_automation_provider.h
+++ b/chrome/browser/automation/testing_automation_provider.h
@@ -19,7 +19,7 @@
#include "chrome/browser/history/history.h"
#include "chrome/browser/importer/importer_list_observer.h"
#include "chrome/browser/sync/profile_sync_service_harness.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/common/page_type.h"
#include "content/public/common/security_style.h"
@@ -54,7 +54,7 @@ struct WebPluginInfo;
// This is an automation provider containing testing calls.
class TestingAutomationProvider : public AutomationProvider,
- public BrowserList::Observer,
+ public chrome::BrowserListObserver,
public importer::ImporterListObserver,
public content::NotificationObserver {
public:
@@ -78,7 +78,7 @@ class TestingAutomationProvider : public AutomationProvider,
virtual ~TestingAutomationProvider();
- // BrowserList::Observer:
+ // chrome::BrowserListObserver:
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index c984994..a73f0bf 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -85,6 +85,7 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_ui_prefs.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
+#include "chrome/browser/ui/uma_browsing_activity_observer.h"
#include "chrome/browser/ui/user_data_dir_dialog.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
#include "chrome/common/child_process_logging.h"
@@ -1292,6 +1293,7 @@ int ChromeBrowserMainParts::PreCreateThreadsImpl() {
// These members must be initialized before returning from this function.
master_prefs_.reset(new first_run::MasterPrefs);
browser_creator_.reset(new StartupBrowserCreator);
+ chrome::UMABrowsingActivityObserver::Init();
// Convert active labs into switches. This needs to be done before
// ResourceBundle::InitSharedInstanceWithLocale as some loaded resources are
diff --git a/chrome/browser/chromeos/extensions/file_manager_util.cc b/chrome/browser/chromeos/extensions/file_manager_util.cc
index b6df7fa..f188083 100644
--- a/chrome/browser/chromeos/extensions/file_manager_util.cc
+++ b/chrome/browser/chromeos/extensions/file_manager_util.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/profiles/profile_manager.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_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h"
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
index c69c127..6ce0043 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/retargeting_details.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/view_type_utils.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.h b/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
index d37cac9..be16da2 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.h
@@ -14,7 +14,7 @@
#include "base/compiler_specific.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -195,7 +195,7 @@ class WebNavigationTabObserver : public content::NotificationObserver,
// Observes navigation notifications and routes them as events to the extension
// system.
class WebNavigationEventRouter : public TabStripModelObserver,
- public BrowserList::Observer,
+ public chrome::BrowserListObserver,
public content::NotificationObserver {
public:
explicit WebNavigationEventRouter(Profile* profile);
@@ -229,7 +229,7 @@ class WebNavigationEventRouter : public TabStripModelObserver,
TabContents* new_contents,
int index) OVERRIDE;
- // BrowserList::Observer implementation.
+ // chrome::BrowserListObserver implementation.
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/extensions/bundle_installer.cc b/chrome/browser/extensions/bundle_installer.cc
index 2b3b7db..43fdd63 100644
--- a/chrome/browser/extensions/bundle_installer.cc
+++ b/chrome/browser/extensions/bundle_installer.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/extensions/extension_install_dialog.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_switches.h"
#include "chrome/common/extensions/extension.h"
diff --git a/chrome/browser/extensions/bundle_installer.h b/chrome/browser/extensions/bundle_installer.h
index 4c2d145..b1986d6 100644
--- a/chrome/browser/extensions/bundle_installer.h
+++ b/chrome/browser/extensions/bundle_installer.h
@@ -14,7 +14,7 @@
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/browser/extensions/webstore_install_helper.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/common/extensions/extension.h"
namespace base {
@@ -39,7 +39,7 @@ namespace extensions {
class BundleInstaller : public WebstoreInstallHelper::Delegate,
public ExtensionInstallPrompt::Delegate,
public WebstoreInstaller::Delegate,
- public BrowserList::Observer,
+ public chrome::BrowserListObserver,
public base::RefCountedThreadSafe<BundleInstaller> {
public:
// Auto approve or cancel the permission prompt.
@@ -164,7 +164,7 @@ class BundleInstaller : public WebstoreInstallHelper::Delegate,
virtual void OnExtensionInstallFailure(const std::string& id,
const std::string& error) OVERRIDE;
- // BrowserList::observer implementation:
+ // chrome::BrowserListObserver implementation:
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 3d814ce..45b5309 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_window_controller.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_tabstrip.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h
index 58bc08f..9dd8b97 100644
--- a/chrome/browser/extensions/extension_browser_event_router.h
+++ b/chrome/browser/extensions/extension_browser_event_router.h
@@ -12,7 +12,7 @@
#include "base/compiler_specific.h"
#include "chrome/browser/extensions/api/tabs/tabs.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "content/public/browser/notification_registrar.h"
#if defined(TOOLKIT_VIEWS)
@@ -36,7 +36,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
#elif defined(TOOLKIT_GTK)
public ui::ActiveWindowWatcherXObserver,
#endif
- public BrowserList::Observer,
+ public chrome::BrowserListObserver,
public content::NotificationObserver {
public:
explicit ExtensionBrowserEventRouter(Profile* profile);
@@ -45,7 +45,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
// Must be called once. Subsequent calls have no effect.
void Init();
- // BrowserList::Observer
+ // chrome::BrowserListObserver
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
@@ -58,7 +58,7 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver,
#endif
// Called from Observe() on BROWSER_WINDOW_READY (not a part of
- // BrowserList::Observer).
+ // chrome::BrowserListObserver).
void OnBrowserWindowReady(Browser* browser);
// TabStripModelObserver
diff --git a/chrome/browser/importer/importer_host.cc b/chrome/browser/importer/importer_host.cc
index 1485dca..44949cf 100644
--- a/chrome/browser/importer/importer_host.cc
+++ b/chrome/browser/importer/importer_host.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/common/chrome_notification_types.h"
diff --git a/chrome/browser/importer/importer_host.h b/chrome/browser/importer/importer_host.h
index 6e92bc6..2571c84 100644
--- a/chrome/browser/importer/importer_host.h
+++ b/chrome/browser/importer/importer_host.h
@@ -13,7 +13,7 @@
#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
#include "chrome/browser/importer/importer_data_types.h"
#include "chrome/browser/importer/profile_writer.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/native_widget_types.h"
@@ -32,7 +32,7 @@ class ImporterProgressObserver;
class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>,
public BaseBookmarkModelObserver,
public content::NotificationObserver,
- public BrowserList::Observer {
+ public chrome::BrowserListObserver {
public:
ImporterHost();
@@ -142,7 +142,7 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
- // BrowserList::Observer
+ // chrome::BrowserListObserver
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
// The task is the process of importing settings from other browsers.
diff --git a/chrome/browser/managed_mode.cc b/chrome/browser/managed_mode.cc
index e9740520..86575e0 100644
--- a/chrome/browser/managed_mode.cc
+++ b/chrome/browser/managed_mode.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
diff --git a/chrome/browser/managed_mode.h b/chrome/browser/managed_mode.h
index 76f0b32..c77e163 100644
--- a/chrome/browser/managed_mode.h
+++ b/chrome/browser/managed_mode.h
@@ -13,7 +13,7 @@
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "chrome/browser/extensions/management_policy.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -27,7 +27,7 @@ class Profile;
// person by pre-configuring and then locking a managed User profile.
// The ManagedMode class provides methods to check whether the browser is in
// managed mode, and to attempt to enter or leave managed mode.
-class ManagedMode : public BrowserList::Observer,
+class ManagedMode : public chrome::BrowserListObserver,
public extensions::ManagementPolicy::Provider,
public content::NotificationObserver {
public:
@@ -52,7 +52,7 @@ class ManagedMode : public BrowserList::Observer,
virtual bool UserMayModifySettings(const extensions::Extension* extension,
string16* error) const OVERRIDE;
- // BrowserList::Observer implementation:
+ // chrome::BrowserListObserver implementation:
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/page_cycler/page_cycler.cc b/chrome/browser/page_cycler/page_cycler.cc
index dea717b..5647d6d 100644
--- a/chrome/browser/page_cycler/page_cycler.cc
+++ b/chrome/browser/page_cycler/page_cycler.cc
@@ -13,7 +13,9 @@
#include "base/string_split.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/chrome_process_util.h"
diff --git a/chrome/browser/page_cycler/page_cycler.h b/chrome/browser/page_cycler/page_cycler.h
index 7fd9e6f..7304be4 100644
--- a/chrome/browser/page_cycler/page_cycler.h
+++ b/chrome/browser/page_cycler/page_cycler.h
@@ -7,11 +7,12 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents_observer.h"
+class Browser;
+
namespace content {
class RenderViewHost;
} // namespace content
@@ -25,7 +26,7 @@ class TimeTicks;
// does most of its work there. However, some work happens on background threads
// too; those are named with 'OnBackgroundThread'.
class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
- public BrowserList::Observer,
+ public chrome::BrowserListObserver,
public content::WebContentsObserver {
public:
PageCycler(Browser* browser, const FilePath& urls_file);
@@ -101,7 +102,7 @@ class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
// PageCycler.
void Abort();
- // BrowserList::Observer
+ // chrome::BrowserListObserver
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/page_cycler/page_cycler_unittest.cc b/chrome/browser/page_cycler/page_cycler_unittest.cc
index 6b6e408..df99e39 100644
--- a/chrome/browser/page_cycler/page_cycler_unittest.cc
+++ b/chrome/browser/page_cycler/page_cycler_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/page_cycler/page_cycler.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index 5e10d3b..ec5c258 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -31,6 +31,7 @@
#include "chrome/browser/sync/profile_sync_service_factory.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"
#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h
index af2abe4..6ee7cc5 100644
--- a/chrome/browser/profiles/profile_manager.h
+++ b/chrome/browser/profiles/profile_manager.h
@@ -19,7 +19,7 @@
#include "base/message_loop.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/startup/startup_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -315,12 +315,12 @@ class ProfileManager : public base::NonThreadSafe,
#endif
#if !defined(OS_ANDROID)
- class BrowserListObserver : public BrowserList::Observer {
+ class BrowserListObserver : public chrome::BrowserListObserver {
public:
explicit BrowserListObserver(ProfileManager* manager);
virtual ~BrowserListObserver();
- // BrowserList::Observer implementation.
+ // chrome::BrowserListObserver implementation.
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/protector/settings_change_global_error.cc b/chrome/browser/protector/settings_change_global_error.cc
index a25d7e1..68b6ae4 100644
--- a/chrome/browser/protector/settings_change_global_error.cc
+++ b/chrome/browser/protector/settings_change_global_error.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/protector/settings_change_global_error_delegate.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/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
diff --git a/chrome/browser/protector/settings_change_global_error.h b/chrome/browser/protector/settings_change_global_error.h
index c7bfe1f..ebab480 100644
--- a/chrome/browser/protector/settings_change_global_error.h
+++ b/chrome/browser/protector/settings_change_global_error.h
@@ -10,7 +10,7 @@
#include "base/memory/weak_ptr.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/protector/base_setting_change.h"
-#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/global_error/global_error.h"
class Browser;
@@ -23,7 +23,7 @@ class SettingsChangeGlobalErrorDelegate;
// Global error about unwanted settings changes.
class SettingsChangeGlobalError : public GlobalError,
- public BrowserList::Observer {
+ public chrome::BrowserListObserver {
public:
// Creates new global error about setting changes |change| which must not be
// deleted until |delegate->OnRemovedFromProfile| is called. Uses |delegate|
@@ -64,7 +64,7 @@ class SettingsChangeGlobalError : public GlobalError,
virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
- // BrowserList::Observer implementation.
+ // chrome::BrowserListObserver implementation.
virtual void OnBrowserAdded(Browser* browser) OVERRIDE {}
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE {}
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/ui/browser_close_browsertest.cc b/chrome/browser/ui/browser_close_browsertest.cc
index 8b907b5..1eb4ab1 100644
--- a/chrome/browser/ui/browser_close_browsertest.cc
+++ b/chrome/browser/ui/browser_close_browsertest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_paths.h"
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc
index e86821e..397d2e3 100644
--- a/chrome/browser/ui/browser_list.cc
+++ b/chrome/browser/ui/browser_list.cc
@@ -4,318 +4,91 @@
#include "chrome/browser/ui/browser_list.h"
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "base/metrics/histogram.h"
-#include "base/observer_list.h"
-#include "build/build_config.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/browser_shutdown.h"
-#include "chrome/browser/lifetime/application_lifetime.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_window.h"
-#include "chrome/browser/ui/tab_contents/tab_contents.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
-#include "content/public/browser/browser_shutdown.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/navigation_details.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_service.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/common/result_codes.h"
-
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/login/user_manager.h"
-#endif
+#include "chrome/browser/ui/browser_list_impl.h"
+#include "chrome/browser/ui/browser_list_observer.h"
using content::WebContents;
-namespace browser {
-
-// This object is instantiated when the first Browser object is added to the
-// list and delete when the last one is removed. It watches for loads and
-// creates histograms of some global object counts.
-class BrowserActivityObserver : public content::NotificationObserver {
- public:
- BrowserActivityObserver() {
- registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
- content::NotificationService::AllSources());
- registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
- content::NotificationService::AllSources());
- }
- ~BrowserActivityObserver() {}
-
- private:
- // content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
- const content::LoadCommittedDetails& load =
- *content::Details<content::LoadCommittedDetails>(details).ptr();
- if (!load.is_navigation_to_different_page())
- return; // Don't log for subframes or other trivial types.
-
- LogRenderProcessHostCount();
- LogBrowserTabCount();
- } else if (type == content::NOTIFICATION_APP_TERMINATING) {
- delete this;
- }
- }
-
- // Counts the number of active RenderProcessHosts and logs them.
- void LogRenderProcessHostCount() const {
- int hosts_count = 0;
- for (content::RenderProcessHost::iterator i(
- content::RenderProcessHost::AllHostsIterator());
- !i.IsAtEnd(); i.Advance())
- ++hosts_count;
- UMA_HISTOGRAM_CUSTOM_COUNTS("MPArch.RPHCountPerLoad", hosts_count,
- 1, 50, 50);
- }
-
- // Counts the number of tabs in each browser window and logs them. This is
- // different than the number of WebContents objects since WebContents objects
- // can be used for popups and in dialog boxes. We're just counting toplevel
- // tabs here.
- void LogBrowserTabCount() const {
- int tab_count = 0;
- for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
- browser_iterator != BrowserList::end(); browser_iterator++) {
- // Record how many tabs each window has open.
- Browser* browser = (*browser_iterator);
- UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerWindow",
- browser->tab_count(), 1, 200, 50);
- tab_count += browser->tab_count();
-
- if (browser->window()->IsActive()) {
- // Record how many tabs the active window has open.
- UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountActiveWindow",
- browser->tab_count(), 1, 200, 50);
- }
- }
- // Record how many tabs total are open (across all windows).
- UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tab_count, 1, 200, 50);
- }
-
- content::NotificationRegistrar registrar_;
-
- DISALLOW_COPY_AND_ASSIGN(BrowserActivityObserver);
-};
-
-BrowserActivityObserver* g_activity_observer = NULL;
-
-} // namespace browser
-
namespace {
-static BrowserList::BrowserVector& browsers() {
- CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, browser_vector, ());
- return browser_vector;
-}
-
-static BrowserList::BrowserVector& last_active_browsers() {
- CR_DEFINE_STATIC_LOCAL(BrowserList::BrowserVector, last_active_vector, ());
- return last_active_vector;
-}
-
-static ObserverList<BrowserList::Observer>& observers() {
- CR_DEFINE_STATIC_LOCAL(
- ObserverList<BrowserList::Observer>, observer_vector, ());
- return observer_vector;
+chrome::BrowserListImpl* GetNativeList() {
+ return chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
}
} // namespace
// static
void BrowserList::AddBrowser(Browser* browser) {
- DCHECK(browser);
- browsers().push_back(browser);
-
- g_browser_process->AddRefModule();
-
- if (!browser::g_activity_observer)
- browser::g_activity_observer = new browser::BrowserActivityObserver;
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_BROWSER_OPENED,
- content::Source<Browser>(browser),
- content::NotificationService::NoDetails());
-
- // Send out notifications after add has occurred. Do some basic checking to
- // try to catch evil observers that change the list from under us.
- size_t original_count = observers().size();
- FOR_EACH_OBSERVER(Observer, observers(), OnBrowserAdded(browser));
- DCHECK_EQ(original_count, observers().size())
- << "observer list modified during notification";
+ GetNativeList()->AddBrowser(browser);
}
// static
void BrowserList::RemoveBrowser(Browser* browser) {
- RemoveBrowserFrom(browser, &last_active_browsers());
-
- // Many UI tests rely on closing the last browser window quitting the
- // application.
- // Mac: Closing all windows does not indicate quitting the application. Lie
- // for now and ignore behavior outside of unit tests.
- // ChromeOS: Force closing last window to close app with flag.
- // TODO(andybons | pkotwicz): Fix the UI tests to Do The Right Thing.
-#if defined(OS_CHROMEOS)
- bool closing_app;
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableZeroBrowsersOpenForTests))
- closing_app = (browsers().size() == 1);
- else
- closing_app = (browsers().size() == 1 &&
- browser_shutdown::IsTryingToQuit());
-#else
- bool closing_app = (browsers().size() == 1);
-#endif // OS_CHROMEOS
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_BROWSER_CLOSED,
- content::Source<Browser>(browser),
- content::Details<bool>(&closing_app));
-
- RemoveBrowserFrom(browser, &browsers());
-
- // Do some basic checking to try to catch evil observers
- // that change the list from under us.
- size_t original_count = observers().size();
- FOR_EACH_OBSERVER(Observer, observers(), OnBrowserRemoved(browser));
- DCHECK_EQ(original_count, observers().size())
- << "observer list modified during notification";
-
- g_browser_process->ReleaseModule();
-
- // If we're exiting, send out the APP_TERMINATING notification to allow other
- // modules to shut themselves down.
- if (browsers().empty() &&
- (browser_shutdown::IsTryingToQuit() ||
- g_browser_process->IsShuttingDown())) {
- // Last browser has just closed, and this is a user-initiated quit or there
- // is no module keeping the app alive, so send out our notification. No need
- // to call ProfileManager::ShutdownSessionServices() as part of the
- // shutdown, because Browser::WindowClosing() already makes sure that the
- // SessionService is created and notified.
- browser::NotifyAppTerminating();
- browser::OnAppExiting();
- }
+ GetNativeList()->RemoveBrowser(browser);
}
// static
-void BrowserList::AddObserver(BrowserList::Observer* observer) {
- observers().AddObserver(observer);
+void BrowserList::AddObserver(chrome::BrowserListObserver* observer) {
+ GetNativeList()->AddObserver(observer);
}
// static
-void BrowserList::RemoveObserver(BrowserList::Observer* observer) {
- observers().RemoveObserver(observer);
+void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) {
+ GetNativeList()->RemoveObserver(observer);
}
void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) {
- BrowserVector browsers_to_close;
- for (BrowserList::const_iterator i = BrowserList::begin();
- i != BrowserList::end(); ++i) {
- if ((*i)->profile()->GetOriginalProfile() == profile->GetOriginalProfile())
- browsers_to_close.push_back(*i);
- }
-
- for (BrowserVector::const_iterator i = browsers_to_close.begin();
- i != browsers_to_close.end(); ++i) {
- (*i)->window()->Close();
- }
+ GetNativeList()->CloseAllBrowsersWithProfile(profile);
}
// static
BrowserList::const_iterator BrowserList::begin() {
- return browsers().begin();
+ return GetNativeList()->begin();
}
// static
BrowserList::const_iterator BrowserList::end() {
- return browsers().end();
+ return GetNativeList()->end();
}
// static
bool BrowserList::empty() {
- return browsers().empty();
+ return GetNativeList()->empty();
}
// static
size_t BrowserList::size() {
- return browsers().size();
+ return GetNativeList()->size();
}
// static
void BrowserList::SetLastActive(Browser* browser) {
- // If the browser is currently trying to quit, we don't want to set the last
- // active browser because that can alter the last active browser that the user
- // intended depending on the order in which the windows close.
- if (browser_shutdown::IsTryingToQuit())
- return;
- RemoveBrowserFrom(browser, &last_active_browsers());
- last_active_browsers().push_back(browser);
-
- FOR_EACH_OBSERVER(Observer, observers(), OnBrowserSetLastActive(browser));
+ GetNativeList()->SetLastActive(browser);
}
// static
BrowserList::const_reverse_iterator BrowserList::begin_last_active() {
- return last_active_browsers().rbegin();
+ return GetNativeList()->begin_last_active();
}
// static
BrowserList::const_reverse_iterator BrowserList::end_last_active() {
- return last_active_browsers().rend();
+ return GetNativeList()->end_last_active();
}
// static
bool BrowserList::IsOffTheRecordSessionActive() {
- for (BrowserList::const_iterator i = BrowserList::begin();
- i != BrowserList::end(); ++i) {
- if ((*i)->profile()->IsOffTheRecord())
- return true;
- }
- return false;
+ return GetNativeList()->IsIncognitoWindowOpen();
}
// static
bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) {
-#if defined(OS_CHROMEOS)
- // In ChromeOS, we assume that the default profile is always valid, so if
- // we are in guest mode, keep the OTR profile active so it won't be deleted.
- if (chromeos::UserManager::Get()->IsLoggedInAsGuest())
- return true;
-#endif
- for (BrowserList::const_iterator i = BrowserList::begin();
- i != BrowserList::end(); ++i) {
- if ((*i)->profile()->IsSameProfile(profile) &&
- (*i)->profile()->IsOffTheRecord()) {
- return true;
- }
- }
- return false;
+ return GetNativeList()->IsIncognitoWindowOpenForProfile(profile);
}
// static
Browser* BrowserList::GetLastActive() {
- if (!last_active_browsers().empty())
- return *(last_active_browsers().rbegin());
-
- return NULL;
+ return GetNativeList()->GetLastActive();
}
-
-// static
-void BrowserList::RemoveBrowserFrom(Browser* browser,
- BrowserVector* browser_list) {
- const iterator remove_browser =
- std::find(browser_list->begin(), browser_list->end(), browser);
- if (remove_browser != browser_list->end())
- browser_list->erase(remove_browser);
-}
-
diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h
index 6050280..b0b3974 100644
--- a/chrome/browser/ui/browser_list.h
+++ b/chrome/browser/ui/browser_list.h
@@ -24,6 +24,7 @@ class ExtensionInstallDialog;
}
namespace chrome {
+class BrowserListObserver;
namespace internal {
void NotifyNotDefaultBrowserCallback();
}
@@ -51,31 +52,14 @@ class BrowserList {
typedef BrowserVector::const_iterator const_iterator;
typedef BrowserVector::const_reverse_iterator const_reverse_iterator;
- // It is not allowed to change the global window list (add or remove any
- // browser windows while handling observer callbacks.
- class Observer {
- public:
- // Called immediately after a browser is added to the list
- virtual void OnBrowserAdded(Browser* browser) {}
-
- // Called immediately after a browser is removed from the list
- virtual void OnBrowserRemoved(Browser* browser) {}
-
- // Called immediately after a browser is set active (SetLastActive)
- virtual void OnBrowserSetLastActive(Browser* browser) {}
-
- protected:
- virtual ~Observer() {}
- };
-
// Adds and removes browsers from the global list. The browser object should
// be valid BEFORE these calls (for the benefit of observers), so notify and
// THEN delete the object.
static void AddBrowser(Browser* browser);
static void RemoveBrowser(Browser* browser);
- static void AddObserver(Observer* observer);
- static void RemoveObserver(Observer* observer);
+ static void AddObserver(chrome::BrowserListObserver* observer);
+ static void RemoveObserver(chrome::BrowserListObserver* observer);
// Called by Browser objects when their window is activated (focused). This
// allows us to determine what the last active Browser was.
@@ -142,9 +126,6 @@ class BrowserList {
// THIS FUNCTION IS PRIVATE AND NOT TO BE USED AS A REPLACEMENT FOR RELEVANT
// CONTEXT.
static Browser* GetLastActive();
-
- // Helper method to remove a browser instance from a list of browsers
- static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list);
};
#endif // CHROME_BROWSER_UI_BROWSER_LIST_H_
diff --git a/chrome/browser/ui/browser_list_impl.cc b/chrome/browser/ui/browser_list_impl.cc
new file mode 100644
index 0000000..5105928
--- /dev/null
+++ b/chrome/browser/ui/browser_list_impl.cc
@@ -0,0 +1,206 @@
+// 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.
+
+#include "chrome/browser/ui/browser_list_impl.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_shutdown.h"
+#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list_observer.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/browser/notification_service.h"
+
+// #include "build/build_config.h"
+// #include "chrome/browser/prefs/pref_service.h"
+
+
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/user_manager.h"
+#endif
+
+namespace chrome {
+
+// static
+BrowserListImpl* BrowserListImpl::native_instance_ = NULL;
+BrowserListImpl* BrowserListImpl::ash_instance_ = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// BrowserListImpl, public:
+
+// static
+BrowserListImpl* BrowserListImpl::GetInstance(HostDesktopType type) {
+ BrowserListImpl** list = NULL;
+ if (type == HOST_DESKTOP_TYPE_NATIVE)
+ list = &native_instance_;
+ else if (type == HOST_DESKTOP_TYPE_ASH)
+ list = &ash_instance_;
+ else
+ NOTREACHED();
+ if (!*list)
+ *list = new BrowserListImpl;
+ return *list;
+}
+
+void BrowserListImpl::AddBrowser(Browser* browser) {
+ DCHECK(browser);
+ browsers_.push_back(browser);
+
+ g_browser_process->AddRefModule();
+
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_BROWSER_OPENED,
+ content::Source<Browser>(browser),
+ content::NotificationService::NoDetails());
+
+ // Send out notifications after add has occurred. Do some basic checking to
+ // try to catch evil observers that change the list from under us.
+ size_t original_count = observers_.size();
+ FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserAdded(browser));
+ DCHECK_EQ(original_count, observers_.size())
+ << "observer list modified during notification";
+}
+
+void BrowserListImpl::RemoveBrowser(Browser* browser) {
+ RemoveBrowserFrom(browser, &last_active_browsers_);
+
+ // Many UI tests rely on closing the last browser window quitting the
+ // application.
+ // Mac: Closing all windows does not indicate quitting the application. Lie
+ // for now and ignore behavior outside of unit tests.
+ // ChromeOS: Force closing last window to close app with flag.
+ // TODO(andybons | pkotwicz): Fix the UI tests to Do The Right Thing.
+#if defined(OS_CHROMEOS)
+ bool closing_app;
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableZeroBrowsersOpenForTests))
+ closing_app = (browsers_.size() == 1);
+ else
+ closing_app = (browsers_.size() == 1 &&
+ browser_shutdown::IsTryingToQuit());
+#else
+ bool closing_app = (browsers_.size() == 1);
+#endif // OS_CHROMEOS
+
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::Source<Browser>(browser),
+ content::Details<bool>(&closing_app));
+
+ RemoveBrowserFrom(browser, &browsers_);
+
+ // Do some basic checking to try to catch evil observers
+ // that change the list from under us.
+ size_t original_count = observers_.size();
+ FOR_EACH_OBSERVER(BrowserListObserver, observers_, OnBrowserRemoved(browser));
+ DCHECK_EQ(original_count, observers_.size())
+ << "observer list modified during notification";
+
+ g_browser_process->ReleaseModule();
+
+ // If we're exiting, send out the APP_TERMINATING notification to allow other
+ // modules to shut themselves down.
+ if (browsers_.empty() &&
+ (browser_shutdown::IsTryingToQuit() ||
+ g_browser_process->IsShuttingDown())) {
+ // Last browser has just closed, and this is a user-initiated quit or there
+ // is no module keeping the app alive, so send out our notification. No need
+ // to call ProfileManager::ShutdownSessionServices() as part of the
+ // shutdown, because Browser::WindowClosing() already makes sure that the
+ // SessionService is created and notified.
+ browser::NotifyAppTerminating();
+ browser::OnAppExiting();
+ }
+}
+
+void BrowserListImpl::AddObserver(BrowserListObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void BrowserListImpl::RemoveObserver(BrowserListObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void BrowserListImpl::SetLastActive(Browser* browser) {
+ // If the browser is currently trying to quit, we don't want to set the last
+ // active browser because that can alter the last active browser that the user
+ // intended depending on the order in which the windows close.
+ if (browser_shutdown::IsTryingToQuit())
+ return;
+ RemoveBrowserFrom(browser, &last_active_browsers_);
+ last_active_browsers_.push_back(browser);
+
+ FOR_EACH_OBSERVER(BrowserListObserver, observers_,
+ OnBrowserSetLastActive(browser));
+}
+
+Browser* BrowserListImpl::GetLastActive() {
+ if (!last_active_browsers_.empty())
+ return *(last_active_browsers_.rbegin());
+ return NULL;
+}
+
+void BrowserListImpl::CloseAllBrowsersWithProfile(Profile* profile) {
+ BrowserVector browsers_to_close;
+ for (BrowserListImpl::const_iterator i = BrowserListImpl::begin();
+ i != BrowserListImpl::end(); ++i) {
+ if ((*i)->profile()->GetOriginalProfile() == profile->GetOriginalProfile())
+ browsers_to_close.push_back(*i);
+ }
+
+ for (BrowserVector::const_iterator i = browsers_to_close.begin();
+ i != browsers_to_close.end(); ++i) {
+ (*i)->window()->Close();
+ }
+}
+
+bool BrowserListImpl::IsIncognitoWindowOpen() {
+ for (BrowserListImpl::const_iterator i = BrowserListImpl::begin();
+ i != BrowserListImpl::end(); ++i) {
+ if ((*i)->profile()->IsOffTheRecord())
+ return true;
+ }
+ return false;
+}
+
+bool BrowserListImpl::IsIncognitoWindowOpenForProfile(Profile* profile) {
+#if defined(OS_CHROMEOS)
+ // In ChromeOS, we assume that the default profile is always valid, so if
+ // we are in guest mode, keep the OTR profile active so it won't be deleted.
+ if (chromeos::UserManager::Get()->IsLoggedInAsGuest())
+ return true;
+#endif
+ for (BrowserListImpl::const_iterator i = BrowserListImpl::begin();
+ i != BrowserListImpl::end(); ++i) {
+ if ((*i)->profile()->IsSameProfile(profile) &&
+ (*i)->profile()->IsOffTheRecord()) {
+ return true;
+ }
+ }
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BrowserListImpl, private:
+
+BrowserListImpl::BrowserListImpl() {
+}
+
+BrowserListImpl::~BrowserListImpl() {
+}
+
+void BrowserListImpl::RemoveBrowserFrom(Browser* browser,
+ BrowserVector* browser_list) {
+ const iterator remove_browser =
+ std::find(browser_list->begin(), browser_list->end(), browser);
+ if (remove_browser != browser_list->end())
+ browser_list->erase(remove_browser);
+}
+
+} // namespace chrome
diff --git a/chrome/browser/ui/browser_list_impl.h b/chrome/browser/ui/browser_list_impl.h
new file mode 100644
index 0000000..93a31ec
--- /dev/null
+++ b/chrome/browser/ui/browser_list_impl.h
@@ -0,0 +1,94 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_
+#define CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_
+
+#include "base/observer_list.h"
+#include "chrome/browser/ui/host_desktop.h"
+
+class Browser;
+class BrowserList;
+class Profile;
+
+namespace chrome {
+
+class BrowserListObserver;
+
+// Maintains a list of Browser objects present in a given HostDesktop (see
+// HostDesktopType).
+class BrowserListImpl {
+ public:
+ typedef std::vector<Browser*> BrowserVector;
+ typedef BrowserVector::iterator iterator;
+ typedef BrowserVector::const_iterator const_iterator;
+ typedef BrowserVector::const_reverse_iterator const_reverse_iterator;
+
+ static BrowserListImpl* GetInstance(HostDesktopType type);
+
+ // Adds and removes browsers from the global list. The browser object should
+ // be valid BEFORE these calls (for the benefit of observers), so notify and
+ // THEN delete the object.
+ void AddBrowser(Browser* browser);
+ void RemoveBrowser(Browser* browser);
+
+ void AddObserver(BrowserListObserver* observer);
+ void RemoveObserver(BrowserListObserver* observer);
+
+ // Called by Browser objects when their window is activated (focused). This
+ // allows us to determine what the last active Browser was.
+ void SetLastActive(Browser* browser);
+
+ Browser* GetLastActive();
+
+ // Closes all browsers for |profile|.
+ void CloseAllBrowsersWithProfile(Profile* profile);
+
+ // Browsers are added to the list before they have constructed windows,
+ // so the |window()| member function may return NULL.
+ const_iterator begin() const { return browsers_.begin(); }
+ const_iterator end() const { return browsers_.end(); }
+
+ bool empty() const { return browsers_.empty(); }
+ size_t size() const { return browsers_.size(); }
+
+ // Returns iterated access to list of open browsers ordered by when
+ // they were last active. The underlying data structure is a vector
+ // and we push_back on recent access so a reverse iterator gives the
+ // latest accessed browser first.
+ const_reverse_iterator begin_last_active() {
+ return last_active_browsers_.rbegin();
+ }
+ const_reverse_iterator end_last_active() {
+ return last_active_browsers_.rend();
+ }
+
+ // Returns true if at least one incognito window is open.
+ bool IsIncognitoWindowOpen();
+
+ // Returns true if at least one incognito window is open for |profile|.
+ bool IsIncognitoWindowOpenForProfile(Profile* profile);
+
+ private:
+ BrowserListImpl();
+ ~BrowserListImpl();
+
+ // Helper method to remove a browser instance from a list of browsers
+ void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list);
+
+ ObserverList<BrowserListObserver> observers_;
+
+ BrowserVector browsers_;
+ BrowserVector last_active_browsers_;
+
+ // Nothing fancy, since we only have two HDTs.
+ static BrowserListImpl* native_instance_;
+ static BrowserListImpl* ash_instance_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserListImpl);
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_BROWSER_LIST_IMPL_H_
diff --git a/chrome/browser/ui/browser_list_observer.h b/chrome/browser/ui/browser_list_observer.h
new file mode 100644
index 0000000..4a52594
--- /dev/null
+++ b/chrome/browser/ui/browser_list_observer.h
@@ -0,0 +1,31 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_BROWSER_LIST_OBSERVER_H_
+#define CHROME_BROWSER_UI_BROWSER_LIST_OBSERVER_H_
+
+class Browser;
+
+namespace chrome {
+
+// Implementations must not change the contents of the BrowserList inside any
+// of these methods.
+class BrowserListObserver {
+ public:
+ // Called immediately after a browser is added to the list
+ virtual void OnBrowserAdded(Browser* browser) {}
+
+ // Called immediately after a browser is removed from the list
+ virtual void OnBrowserRemoved(Browser* browser) {}
+
+ // Called immediately after a browser is set active (SetLastActive)
+ virtual void OnBrowserSetLastActive(Browser* browser) {}
+
+ protected:
+ virtual ~BrowserListObserver() {}
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_BROWSER_LIST_OBSERVER_H_
diff --git a/chrome/browser/ui/cocoa/profile_menu_controller.mm b/chrome/browser/ui/cocoa/profile_menu_controller.mm
index 62f3ac4..2531833 100644
--- a/chrome/browser/ui/cocoa/profile_menu_controller.mm
+++ b/chrome/browser/ui/cocoa/profile_menu_controller.mm
@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
#import "chrome/browser/ui/cocoa/menu_controller.h"
#include "grit/generated_resources.h"
@@ -27,7 +28,7 @@
namespace ProfileMenuControllerInternal {
-class Observer : public BrowserList::Observer,
+class Observer : public chrome::BrowserListObserver,
public AvatarMenuModelObserver {
public:
Observer(ProfileMenuController* controller) : controller_(controller) {
@@ -38,7 +39,7 @@ class Observer : public BrowserList::Observer,
BrowserList::RemoveObserver(this);
}
- // BrowserList::Observer:
+ // chrome::BrowserListObserver:
virtual void OnBrowserAdded(Browser* browser) {}
virtual void OnBrowserRemoved(Browser* browser) {
[controller_ activeBrowserChangedTo:browser::GetLastActiveBrowser()];
diff --git a/chrome/browser/ui/host_desktop.h b/chrome/browser/ui/host_desktop.h
new file mode 100644
index 0000000..03e37d1
--- /dev/null
+++ b/chrome/browser/ui/host_desktop.h
@@ -0,0 +1,34 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_HOST_DESKTOP_H_
+#define CHROME_BROWSER_UI_HOST_DESKTOP_H_
+
+namespace chrome {
+
+// A value that specifies what desktop environment hosts a particular piece of
+// UI.
+// Note that HOST_DESKTOP_TYPE_ASH is always used on ChromeOS.
+enum HostDesktopType {
+ // The UI is hosted on the system native desktop.
+ HOST_DESKTOP_TYPE_NATIVE = 0,
+
+ // The UI is hosted in the synthetic Ash desktop.
+ HOST_DESKTOP_TYPE_ASH,
+
+ HOST_DESKTOP_TYPE_COUNT
+};
+
+/*
+TODO(beng): implement utilities as needed, e.g.:
+HostDesktopType GetActiveDesktop();
+HostDesktopType GetHostDesktopTypeForNativeView(gfx::NativeView native_view);
+HostDesktopType GetHostDesktopTypeForNativeWindow(
+ gfx::NativeWindow native_window);
+HostDesktopType GetHostDesktopTypeForBrowser(Browser* browser);
+*/
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_HOST_DESKTOP_H_
diff --git a/chrome/browser/ui/network_profile_bubble.cc b/chrome/browser/ui/network_profile_bubble.cc
index 7d0844d..5d57c82 100644
--- a/chrome/browser/ui/network_profile_bubble.cc
+++ b/chrome/browser/ui/network_profile_bubble.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -34,12 +35,13 @@ const int kSilenceDurationDays = 100;
// silent period starts.
const int kMaxWarnings = 2;
-// Implementation of BrowserList::Observer used to wait for a browser window.
-class BrowserListObserver : public BrowserList::Observer {
+// Implementation of chrome::BrowserListObserver used to wait for a browser
+// window.
+class BrowserListObserver : public chrome::BrowserListObserver {
private:
virtual ~BrowserListObserver();
- // Overridden from BrowserList::Observer:
+ // Overridden from chrome::BrowserListObserver:
virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
index 087c16f..0e84ca2 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc
@@ -19,6 +19,7 @@
#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_list_observer.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
@@ -100,7 +101,7 @@ class StartupBrowserCreatorTest : public ExtensionBrowserTest {
}
};
-class OpenURLsPopupObserver : public BrowserList::Observer {
+class OpenURLsPopupObserver : public chrome::BrowserListObserver {
public:
OpenURLsPopupObserver() : added_browser_(NULL) { }
diff --git a/chrome/browser/ui/uma_browsing_activity_observer.cc b/chrome/browser/ui/uma_browsing_activity_observer.cc
new file mode 100644
index 0000000..473cb57
--- /dev/null
+++ b/chrome/browser/ui/uma_browsing_activity_observer.cc
@@ -0,0 +1,88 @@
+// 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.
+
+#include "chrome/browser/ui/uma_browsing_activity_observer.h"
+
+#include "base/metrics/histogram.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace chrome {
+namespace {
+
+UMABrowsingActivityObserver* g_instance = NULL;
+
+} // namespace
+
+// static
+void UMABrowsingActivityObserver::Init() {
+ DCHECK(!g_instance);
+ DCHECK(BrowserList::empty()); // Must be created before any Browsers are.
+ g_instance = new UMABrowsingActivityObserver;
+}
+
+UMABrowsingActivityObserver::UMABrowsingActivityObserver() {
+ registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
+ content::NotificationService::AllSources());
+}
+
+UMABrowsingActivityObserver::~UMABrowsingActivityObserver() {
+}
+
+void UMABrowsingActivityObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
+ const content::LoadCommittedDetails& load =
+ *content::Details<content::LoadCommittedDetails>(details).ptr();
+ if (!load.is_navigation_to_different_page())
+ return; // Don't log for subframes or other trivial types.
+
+ LogRenderProcessHostCount();
+ LogBrowserTabCount();
+ } else if (type == content::NOTIFICATION_APP_TERMINATING) {
+ delete g_instance;
+ g_instance = NULL;
+ }
+}
+
+void UMABrowsingActivityObserver::LogRenderProcessHostCount() const {
+ int hosts_count = 0;
+ for (content::RenderProcessHost::iterator i(
+ content::RenderProcessHost::AllHostsIterator());
+ !i.IsAtEnd(); i.Advance())
+ ++hosts_count;
+ UMA_HISTOGRAM_CUSTOM_COUNTS("MPArch.RPHCountPerLoad", hosts_count,
+ 1, 50, 50);
+}
+
+void UMABrowsingActivityObserver::LogBrowserTabCount() const {
+ int tab_count = 0;
+ for (BrowserList::const_iterator browser_iterator = BrowserList::begin();
+ browser_iterator != BrowserList::end(); browser_iterator++) {
+ // Record how many tabs each window has open.
+ Browser* browser = (*browser_iterator);
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerWindow",
+ browser->tab_count(), 1, 200, 50);
+ tab_count += browser->tab_count();
+
+ if (browser->window()->IsActive()) {
+ // Record how many tabs the active window has open.
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountActiveWindow",
+ browser->tab_count(), 1, 200, 50);
+ }
+ }
+ // Record how many tabs total are open (across all windows).
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tab_count, 1, 200, 50);
+}
+
+} // namespace chrome
diff --git a/chrome/browser/ui/uma_browsing_activity_observer.h b/chrome/browser/ui/uma_browsing_activity_observer.h
new file mode 100644
index 0000000..a0669a1
--- /dev/null
+++ b/chrome/browser/ui/uma_browsing_activity_observer.h
@@ -0,0 +1,45 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_
+#define CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_
+
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_observer.h"
+
+namespace chrome {
+
+// This object is instantiated when the first Browser object is added to the
+// list and delete when the last one is removed. It watches for loads and
+// creates histograms of some global object counts.
+class UMABrowsingActivityObserver : public content::NotificationObserver {
+ public:
+ static void Init();
+
+ private:
+ UMABrowsingActivityObserver();
+ virtual ~UMABrowsingActivityObserver();
+
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // Counts the number of active RenderProcessHosts and logs them.
+ void LogRenderProcessHostCount() const;
+
+ // Counts the number of tabs in each browser window and logs them. This is
+ // different than the number of WebContents objects since WebContents objects
+ // can be used for popups and in dialog boxes. We're just counting toplevel
+ // tabs here.
+ void LogBrowserTabCount() const;
+
+ content::NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(UMABrowsingActivityObserver);
+};
+
+} // namespace chrome
+
+#endif // CHROME_BROWSER_UI_UMA_BROWSING_ACTIVITY_OBSERVER_H_