diff options
-rw-r--r-- | chrome/browser/jumplist_win.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.h | 11 | ||||
-rw-r--r-- | chrome/browser/ui/views/load_complete_listener.cc | 38 | ||||
-rw-r--r-- | chrome/browser/ui/views/load_complete_listener.h | 50 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 |
7 files changed, 113 insertions, 3 deletions
diff --git a/chrome/browser/jumplist_win.h b/chrome/browser/jumplist_win.h index 8a801ba..0bbe265 100644 --- a/chrome/browser/jumplist_win.h +++ b/chrome/browser/jumplist_win.h @@ -244,6 +244,8 @@ class JumpList : public TabRestoreServiceObserver, // Lock for most_visited_pages_, recently_closed_pages_, icon_urls_ // as they may be used by up to 3 threads. base::Lock list_lock_; + + DISALLOW_COPY_AND_ASSIGN(JumpList); }; #endif // CHROME_BROWSER_JUMPLIST_WIN_H_ diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index d790098..f2238f5 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -2236,8 +2236,7 @@ void BrowserView::Init() { // Create a custom JumpList and add it to an observer of TabRestoreService // so we can update the custom JumpList when a tab is added or removed. if (JumpList::Enabled()) { - jumplist_ = new JumpList(); - jumplist_->AddObserver(browser_->profile()); + load_complete_listener_.reset(new LoadCompleteListener(this)); } #endif @@ -2270,6 +2269,14 @@ void BrowserView::LoadingAnimationCallback() { } } +void BrowserView::OnLoadCompleted() { +#if defined(OS_WIN) && !defined(USE_AURA) + DCHECK(!jumplist_); + jumplist_ = new JumpList(); + jumplist_->AddObserver(browser_->profile()); +#endif +} + // BrowserView, private -------------------------------------------------------- BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 264b874..5b1d9d8 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -19,6 +19,7 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/browser/ui/views/frame/browser_frame.h" +#include "chrome/browser/ui/views/load_complete_listener.h" #include "chrome/browser/ui/views/unhandled_keyboard_event_handler.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/models/simple_menu_model.h" @@ -95,7 +96,8 @@ class BrowserView : public BrowserWindow, public views::ClientView, public InfoBarContainer::Delegate, public views::SingleSplitViewListener, - public gfx::SysColorChangeListener { + public gfx::SysColorChangeListener, + public LoadCompleteListener::Delegate { public: // The browser view's class name. static const char kViewClassName[]; @@ -458,6 +460,10 @@ class BrowserView : public BrowserWindow, // Callback for the loading animation(s) associated with this view. virtual void LoadingAnimationCallback(); + // LoadCompleteListener::Delegate implementation. Creates and initializes the + // |jumplist_| after the first page load. + virtual void OnLoadCompleted() OVERRIDE; + private: friend class BrowserViewLayout; FRIEND_TEST_ALL_PREFIXES(BrowserViewsAccessibilityTest, @@ -701,6 +707,9 @@ class BrowserView : public BrowserWindow, // plugin window. HungPluginAction hung_plugin_action_; + // Helper class to listen for completion of first page load. + scoped_ptr<LoadCompleteListener> load_complete_listener_; + // The custom JumpList for Windows 7. scoped_refptr<JumpList> jumplist_; #endif diff --git a/chrome/browser/ui/views/load_complete_listener.cc b/chrome/browser/ui/views/load_complete_listener.cc new file mode 100644 index 0000000..4ff3aa6 --- /dev/null +++ b/chrome/browser/ui/views/load_complete_listener.cc @@ -0,0 +1,38 @@ +// 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/views/load_complete_listener.h" + +#include "chrome/common/chrome_notification_types.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" +#include "content/public/browser/notification_types.h" + +LoadCompleteListener::LoadCompleteListener(Delegate* delegate) + : delegate_(delegate) { + registrar_ = new content::NotificationRegistrar(); + // Register for notification of when initial page load is complete to ensure + // that we wait until start-up is complete before calling the callback. + registrar_->Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, + content::NotificationService::AllSources()); +} + +LoadCompleteListener::~LoadCompleteListener() { +} + +void LoadCompleteListener::Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { + delegate_->OnLoadCompleted(); + registrar_->Remove(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, + content::NotificationService::AllSources()); + break; + } + default: + NOTREACHED() << "Unexpected notification type."; + } +} diff --git a/chrome/browser/ui/views/load_complete_listener.h b/chrome/browser/ui/views/load_complete_listener.h new file mode 100644 index 0000000..6745fa6 --- /dev/null +++ b/chrome/browser/ui/views/load_complete_listener.h @@ -0,0 +1,50 @@ +// 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_VIEWS_LOAD_COMPLETE_LISTENER_H_ +#define CHROME_BROWSER_UI_VIEWS_LOAD_COMPLETE_LISTENER_H_ + +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_observer.h" + +namespace content { +class NotificationSource; +class NotificationRegistrar; +class NotificationDetails; +} + +// A class which takes a delegate which can be notified after the first page +// load has been completed. This is particularly useful for triggering +// IO-intensive tasks which should not be run until start-up is complete. +class LoadCompleteListener + : public content::NotificationObserver { + public: + class Delegate { + public: + // Invoked when initial page load has completed. + virtual void OnLoadCompleted() = 0; + + protected: + virtual ~Delegate() {} + }; + + explicit LoadCompleteListener(Delegate* delegate); + + virtual ~LoadCompleteListener(); + + // NotificationObserver implementation. + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + private: + content::NotificationRegistrar* registrar_; + + // Delegate to be notified after the first page load has completed. + Delegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(LoadCompleteListener); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_LOAD_COMPLETE_LISTENER_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index fba7538..ac13ca3 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2579,6 +2579,8 @@ ['exclude', '^browser/hang_monitor/hung_plugin_action.h'], ['exclude', '^browser/hang_monitor/hung_window_detector.cc'], ['exclude', '^browser/hang_monitor/hung_window_detector.h'], + ['exclude', '^browser/jumplist_win.cc'], + ['exclude', '^browser/jumplist_win.h'], ['exclude', '^browser/lifetime/application_lifetime_stub.cc'], ['exclude', '^browser/renderer_host/render_widget_host_view_views*'], ['exclude', '^browser/tab_contents/web_drag_bookmark_handler_win.cc'], diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 3fd6935..a69014c 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -1568,6 +1568,8 @@ 'browser/ui/views/infobars/translate_message_infobar.h', 'browser/ui/views/javascript_app_modal_dialog_views.cc', 'browser/ui/views/javascript_app_modal_dialog_views.h', + 'browser/ui/views/load_complete_listener.cc', + 'browser/ui/views/load_complete_listener.h', 'browser/ui/views/location_bar/action_box_button_view.cc', 'browser/ui/views/location_bar/action_box_button_view.h', 'browser/ui/views/location_bar/content_setting_image_view.cc', |