diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 22:03:15 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 22:03:15 +0000 |
commit | c6e6700f0ad9075d6ef675dd4de0626570929000 (patch) | |
tree | 10621884ce2a81d52326ac3d8e32cc1063b88895 /chrome/browser | |
parent | 83ec6d395d0b8a836370579368e1b365a3abbca4 (diff) | |
download | chromium_src-c6e6700f0ad9075d6ef675dd4de0626570929000.zip chromium_src-c6e6700f0ad9075d6ef675dd4de0626570929000.tar.gz chromium_src-c6e6700f0ad9075d6ef675dd4de0626570929000.tar.bz2 |
Move the hang monitor to the BrowserView, since it's highly Windows/HWND specific.
http://crbug.com/4310
Review URL: http://codereview.chromium.org/10601
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.cc | 43 | ||||
-rw-r--r-- | chrome/browser/browser.h | 15 | ||||
-rw-r--r-- | chrome/browser/browser_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 43 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 23 |
5 files changed, 66 insertions, 60 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 1997a38..5213b4b 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -70,12 +70,6 @@ static const int kBrowserReleaseMemoryInterval = 30; // In seconds. // windows. static const int kWindowTilePixels = 20; -// How frequently we check for hung plugin windows. -static const int kDefaultHungPluginDetectFrequency = 2000; - -// How long do we wait before we consider a window hung (in ms). -static const int kDefaultPluginMessageResponseTimeout = 30000; - //////////////////////////////////////////////////////////////////////////////// // A task to reduce the working set of the plugins. @@ -166,10 +160,6 @@ void Browser::OpenNewBrowserWindow(Profile* profile, int show_command) { // static void Browser::RegisterPrefs(PrefService* prefs) { - prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, - kDefaultPluginMessageResponseTimeout); - prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, - kDefaultHungPluginDetectFrequency); prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); } @@ -206,8 +196,6 @@ Browser::Browser(const gfx::Rect& initial_bounds, controller_(this), chrome_updater_factory_(this), method_factory_(this), - hung_window_detector_(&hung_plugin_action_), - ticker_(0), tabstrip_model_(this, profile), toolbar_model_(this), type_(type), @@ -228,11 +216,6 @@ Browser::Browser(const gfx::Rect& initial_bounds, window_ = BrowserWindow::CreateBrowserWindow(this, create_bounds, show_command); - // Start a hung plugin window detector for this browser object (as long as - // hang detection is not disabled). - if (!parsed_command_line.HasSwitch(switches::kDisableHangMonitor)) - InitHangMonitor(); - NotificationService::current()->AddObserver( this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); @@ -280,10 +263,6 @@ Browser::~Browser() { NotificationService::current()->RemoveObserver( this, NOTIFY_SSL_STATE_CHANGED, NotificationService::AllSources()); - // Stop hung plugin monitoring. - ticker_.Stop(); - ticker_.UnregisterTickHandler(&hung_window_detector_); - if (profile_->IsOffTheRecord() && !BrowserList::IsOffTheRecordSessionActive()) { // We reuse the OTR cookie store across OTR windows. If the last OTR @@ -1341,28 +1320,6 @@ void Browser::TabStripEmpty() { method_factory_.NewRunnableMethod(&Browser::CloseFrame)); } -void Browser::InitHangMonitor() { - PrefService* pref_service = g_browser_process->local_state(); - DCHECK(pref_service != NULL); - int plugin_message_response_timeout = - pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); - int hung_plugin_detect_freq = - pref_service->GetInteger(prefs::kHungPluginDetectFrequency); - if ((hung_plugin_detect_freq > 0) && - hung_window_detector_.Initialize(GetTopLevelHWND(), - plugin_message_response_timeout)) { - ticker_.set_tick_interval(hung_plugin_detect_freq); - ticker_.RegisterTickHandler(&hung_window_detector_); - ticker_.Start(); - - pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, - plugin_message_response_timeout); - pref_service->SetInteger(prefs::kHungPluginDetectFrequency, - hung_plugin_detect_freq); - } -} - - Browser* Browser::GetOrCreateTabbedBrowser() { Browser* browser = BrowserList::FindBrowserWithType( profile_, BrowserType::TABBED_BROWSER); diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 0855d2f..dcbb3b7 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -6,8 +6,6 @@ #define CHROME_BROWSER_BROWSER_H_ #include "chrome/browser/controller.h" -#include "chrome/browser/hang_monitor/hung_plugin_action.h" -#include "chrome/browser/hang_monitor/hung_window_detector.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/browser/browser_type.h" #include "chrome/browser/session_id.h" @@ -526,19 +524,6 @@ class Browser : public TabStripModelDelegate, // The following factory is used to close the frame at a later time. ScopedRunnableMethodFactory<Browser> method_factory_; - // This object is used to perform periodic actions in a worker - // thread. It is currently used to monitor hung plugin windows. - WorkerThreadTicker ticker_; - - // This object is initialized with the frame window HWND. This - // object is also passed as a tick handler with the ticker_ object. - // It is used to periodically monitor for hung plugin windows - HungWindowDetector hung_window_detector_; - - // This object is invoked by hung_window_detector_ when it detects a hung - // plugin window. - HungPluginAction hung_plugin_action_; - // This browser type. BrowserType::Type type_; diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 46deec6..e0256a4 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -23,6 +23,7 @@ #include "chrome/browser/views/bookmark_bar_view.h" #include "chrome/browser/views/bookmark_manager_view.h" #include "chrome/browser/views/bookmark_table_view.h" +#include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/keyword_editor_view.h" #include "chrome/browser/views/page_info_window.h" #include "chrome/browser/web_contents.h" @@ -33,6 +34,7 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { // Prefs in Local State BookmarkManagerView::RegisterPrefs(local_state); Browser::RegisterPrefs(local_state); + BrowserView::RegisterBrowserViewPrefs(local_state); CacheManagerHost::RegisterPrefs(local_state); chrome_browser_net::RegisterPrefs(local_state); GoogleURLTracker::RegisterPrefs(local_state); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 5a992b8..e26cc95 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -59,6 +59,10 @@ static const int kSeparationLineHeight = 1; static const wchar_t* kBrowserWindowKey = L"__BROWSER_WINDOW__"; // The distance between tiled windows. static const int kWindowTilePixels = 10; +// How frequently we check for hung plugin windows. +static const int kDefaultHungPluginDetectFrequency = 2000; +// How long do we wait before we consider a window hung (in ms). +static const int kDefaultPluginMessageResponseTimeout = 30000; static const struct { bool separator; int command; int label; } kMenuLayout[] = { { true, 0, 0 }, @@ -98,6 +102,8 @@ BrowserView::BrowserView(Browser* browser) contents_container_(NULL), initialized_(false), can_drop_(false), + hung_window_detector_(&hung_plugin_action_), + ticker_(0), #ifdef CHROME_PERSONALIZATION personalization_enabled_(false), personalization_(NULL), @@ -111,6 +117,10 @@ BrowserView::BrowserView(Browser* browser) BrowserView::~BrowserView() { browser_->tabstrip_model()->RemoveObserver(this); + + // Stop hung plugin monitoring. + ticker_.Stop(); + ticker_.UnregisterTickHandler(&hung_window_detector_); } void BrowserView::WindowMoved() { @@ -260,6 +270,14 @@ unsigned int BrowserView::FeaturesForBrowserType(BrowserType::Type type) { return features; } +// static +void BrowserView::RegisterBrowserViewPrefs(PrefService* prefs) { + prefs->RegisterIntegerPref(prefs::kPluginMessageResponseTimeout, + kDefaultPluginMessageResponseTimeout); + prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, + kDefaultHungPluginDetectFrequency); +} + /////////////////////////////////////////////////////////////////////////////// // BrowserView, BrowserWindow implementation: @@ -268,6 +286,11 @@ void BrowserView::Init() { // at it later when all we have is a HWND. SetProp(GetContainer()->GetHWND(), kBrowserWindowKey, this); + // Start a hung plugin window detector for this browser object (as long as + // hang detection is not disabled). + if (!CommandLine().HasSwitch(switches::kDisableHangMonitor)) + InitHangMonitor(); + LoadAccelerators(); SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); @@ -1125,6 +1148,26 @@ int BrowserView::GetCommandIDForAppCommandID(int app_command_id) const { return -1; } +void BrowserView::InitHangMonitor() { + PrefService* pref_service = g_browser_process->local_state(); + int plugin_message_response_timeout = + pref_service->GetInteger(prefs::kPluginMessageResponseTimeout); + int hung_plugin_detect_freq = + pref_service->GetInteger(prefs::kHungPluginDetectFrequency); + if ((hung_plugin_detect_freq > 0) && + hung_window_detector_.Initialize(GetContainer()->GetHWND(), + plugin_message_response_timeout)) { + ticker_.set_tick_interval(hung_plugin_detect_freq); + ticker_.RegisterTickHandler(&hung_window_detector_); + ticker_.Start(); + + pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, + plugin_message_response_timeout); + pref_service->SetInteger(prefs::kHungPluginDetectFrequency, + hung_plugin_detect_freq); + } +} + // static void BrowserView::InitClass() { static bool initialized = false; diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 8e04f6d..73ba719 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -7,6 +7,8 @@ #include "chrome/browser/browser_type.h" #include "chrome/browser/browser_window.h" +#include "chrome/browser/hang_monitor/hung_plugin_action.h" +#include "chrome/browser/hang_monitor/hung_window_detector.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/views/frame/browser_frame.h" #include "chrome/common/pref_member.h" @@ -130,6 +132,9 @@ class BrowserView : public BrowserWindow, // Returns the set of WindowFeatures supported by the specified BrowserType. static unsigned int FeaturesForBrowserType(BrowserType::Type type); + // Register preferences specific to this view. + static void RegisterBrowserViewPrefs(PrefService* prefs); + // Overridden from BrowserWindow: virtual void Init(); virtual void Show(int command, bool adjust_to_fit); @@ -202,8 +207,6 @@ class BrowserView : public BrowserWindow, } #endif - - protected: // Overridden from views::View: virtual void Layout(); @@ -291,6 +294,9 @@ class BrowserView : public BrowserWindow, // Retrieves the command id for the specified Windows app command. int GetCommandIDForAppCommandID(int app_command_id) const; + // Initialize the hung plugin detector. + void InitHangMonitor(); + // Initialize class statics. static void InitClass(); @@ -352,6 +358,19 @@ class BrowserView : public BrowserWindow, // The delegate for the encoding menu. scoped_ptr<EncodingMenuControllerDelegate> encoding_menu_delegate_; + // This object is used to perform periodic actions in a worker + // thread. It is currently used to monitor hung plugin windows. + WorkerThreadTicker ticker_; + + // This object is initialized with the frame window HWND. This + // object is also passed as a tick handler with the ticker_ object. + // It is used to periodically monitor for hung plugin windows + HungWindowDetector hung_window_detector_; + + // This object is invoked by hung_window_detector_ when it detects a hung + // plugin window. + HungPluginAction hung_plugin_action_; + // P13N stuff #ifdef CHROME_PERSONALIZATION FramePersonalization personalization_; |