diff options
author | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 21:15:09 +0000 |
---|---|---|
committer | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-12 21:15:09 +0000 |
commit | 6eac57a601d0f2e88390609b5716c08eb5f19b73 (patch) | |
tree | 6038bcdc6309799c2c7375fd9a72dc79ff80dac4 | |
parent | b32c028c0bbcd40cc74067968a0aebb4a52a3bd7 (diff) | |
download | chromium_src-6eac57a601d0f2e88390609b5716c08eb5f19b73.zip chromium_src-6eac57a601d0f2e88390609b5716c08eb5f19b73.tar.gz chromium_src-6eac57a601d0f2e88390609b5716c08eb5f19b73.tar.bz2 |
Convert ViewMsg_NetworkStateChanged from routed -> control,
minimizing the number of required IPCs (since the online state
is a per-WebKit singleton).
In doing so, I've disentangled online state management from TabContents:
it now resides off by itself in BrowserOnlineStateObserver, a tiny class
owned by BrowserProcessImpl.
This is an attempt to re-land r91390 without the OnProcessLaunched IPC
(since r92062 solved that in a different way by using WebPreferences).
The previous commit was reverted due to missing message_loop.h includes.
R=darin@chromium.org
Review URL: http://codereview.chromium.org/7343011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92233 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 3 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 4 | ||||
-rw-r--r-- | chrome/browser/speech/speech_input_bubble.cc | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_drag_dest_gtk.cc | 1 | ||||
-rw-r--r-- | chrome/browser/ui/shell_dialogs.cc | 1 | ||||
-rw-r--r-- | content/browser/net/browser_online_state_observer.cc | 24 | ||||
-rw-r--r-- | content/browser/net/browser_online_state_observer.h | 27 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.cc | 16 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.h | 11 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_delegate_unittest.cc | 1 | ||||
-rw-r--r-- | content/common/view_messages.h | 4 | ||||
-rw-r--r-- | content/content_browser.gypi | 2 | ||||
-rw-r--r-- | content/renderer/render_thread.cc | 8 | ||||
-rw-r--r-- | content/renderer/render_thread.h | 1 | ||||
-rw-r--r-- | content/renderer/render_view.cc | 7 | ||||
-rw-r--r-- | content/renderer/render_view.h | 1 |
16 files changed, 77 insertions, 35 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 8455db0..d554f7e 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -73,6 +73,7 @@ #include "content/browser/debugger/devtools_manager.h" #include "content/browser/debugger/devtools_protocol_handler.h" #include "content/browser/gpu/gpu_process_host_ui_shim.h" +#include "content/browser/net/browser_online_state_observer.h" #include "content/browser/plugin_service.h" #include "content/browser/renderer_host/render_process_host.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" @@ -147,6 +148,8 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) extension_event_router_forwarder_ = new ExtensionEventRouterForwarder; ExtensionTabIdMap::GetInstance()->Init(); + + online_state_observer_.reset(new BrowserOnlineStateObserver); } BrowserProcessImpl::~BrowserProcessImpl() { diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index e6bede0..0c52f94 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -27,6 +27,7 @@ #include "content/common/notification_registrar.h" #include "ipc/ipc_message.h" +class BrowserOnlineStateObserver; class ChromeNetLog; class ChromeResourceDispatcherHostDelegate; class CommandLine; @@ -312,6 +313,9 @@ class BrowserProcessImpl : public BrowserProcess, chromeos_proxy_config_service_impl_; #endif + // Per-process listener for online state changes. + scoped_ptr<BrowserOnlineStateObserver> online_state_observer_; + DISALLOW_COPY_AND_ASSIGN(BrowserProcessImpl); }; diff --git a/chrome/browser/speech/speech_input_bubble.cc b/chrome/browser/speech/speech_input_bubble.cc index 251c1c3..c0598d0 100644 --- a/chrome/browser/speech/speech_input_bubble.cc +++ b/chrome/browser/speech/speech_input_bubble.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/lazy_instance.h" +#include "base/message_loop.h" #include "chrome/browser/speech/speech_input_bubble.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.cc b/chrome/browser/tab_contents/web_drag_dest_gtk.cc index b87b8fb..9612ac3 100644 --- a/chrome/browser/tab_contents/web_drag_dest_gtk.cc +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.cc @@ -7,6 +7,7 @@ #include <string> #include "base/file_path.h" +#include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" diff --git a/chrome/browser/ui/shell_dialogs.cc b/chrome/browser/ui/shell_dialogs.cc index 5b9d391..603c75f 100644 --- a/chrome/browser/ui/shell_dialogs.cc +++ b/chrome/browser/ui/shell_dialogs.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/shell_dialogs.h" #include "base/logging.h" +#include "base/message_loop.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" diff --git a/content/browser/net/browser_online_state_observer.cc b/content/browser/net/browser_online_state_observer.cc new file mode 100644 index 0000000..2b0ccd8 --- /dev/null +++ b/content/browser/net/browser_online_state_observer.cc @@ -0,0 +1,24 @@ +// Copyright (c) 2011 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 "content/browser/net/browser_online_state_observer.h" + +#include "content/browser/renderer_host/render_process_host.h" +#include "content/common/view_messages.h" +#include "net/base/network_change_notifier.h" + +BrowserOnlineStateObserver::BrowserOnlineStateObserver() { + net::NetworkChangeNotifier::AddOnlineStateObserver(this); +} + +BrowserOnlineStateObserver::~BrowserOnlineStateObserver() { + net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); +} + +void BrowserOnlineStateObserver::OnOnlineStateChanged(bool online) { + for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); + !it.IsAtEnd(); it.Advance()) { + it.GetCurrentValue()->Send(new ViewMsg_NetworkStateChanged(online)); + } +} diff --git a/content/browser/net/browser_online_state_observer.h b/content/browser/net/browser_online_state_observer.h new file mode 100644 index 0000000..1e5e71a --- /dev/null +++ b/content/browser/net/browser_online_state_observer.h @@ -0,0 +1,27 @@ +// Copyright (c) 2011 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 CONTENT_BROWSER_NET_BROWSER_ONLINE_STATE_OBSERVER_H_ +#define CONTENT_BROWSER_NET_BROWSER_ONLINE_STATE_OBSERVER_H_ +#pragma once + +#include "base/basictypes.h" +#include "net/base/network_change_notifier.h" + +// Listens for changes to the online state and manages sending +// updates to each RenderProcess via RenderProcessHost IPC. +class BrowserOnlineStateObserver + : public net::NetworkChangeNotifier::OnlineStateObserver { + public: + BrowserOnlineStateObserver(); + virtual ~BrowserOnlineStateObserver(); + + // OnlineStateObserver implementation. + virtual void OnOnlineStateChanged(bool online); + + private: + DISALLOW_COPY_AND_ASSIGN(BrowserOnlineStateObserver); +}; + +#endif // CONTENT_BROWSER_NET_BROWSER_ONLINE_STATE_OBSERVER_H_ diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 25057f4..340c067 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -198,11 +198,6 @@ TabContents::TabContents(Profile* profile, // tab contents (normally a tab from the same window). view_->CreateView(base_tab_contents ? base_tab_contents->view()->GetContainerSize() : gfx::Size()); - - // Can only add observers after render_manager_.Init() is called, since that's - // what sets up the render_view_host which TabContentObserver's constructor - // uses to get the routing_id. - AddObservers(); } TabContents::~TabContents() { @@ -245,8 +240,6 @@ TabContents::~TabContents() { FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed()); - net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); - set_delegate(NULL); } @@ -261,10 +254,6 @@ void TabContents::set_delegate(TabContentsDelegate* delegate) { delegate_->Attach(this); } -void TabContents::AddObservers() { - net::NetworkChangeNotifier::AddOnlineStateObserver(this); -} - bool TabContents::OnMessageReceived(const IPC::Message& message) { if (web_ui() && web_ui()->OnMessageReceived(message)) return true; @@ -1831,8 +1820,3 @@ void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh); rwh_view->SetSize(view()->GetContainerSize()); } - -void TabContents::OnOnlineStateChanged(bool online) { - render_view_host()->Send(new ViewMsg_NetworkStateChanged( - render_view_host()->routing_id(), online)); -} diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 7a92b22..9883a02 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "base/observer_list.h" #include "base/string16.h" #include "content/browser/javascript_dialogs.h" #include "content/browser/renderer_host/render_view_host_delegate.h" @@ -26,7 +27,6 @@ #include "content/common/property_bag.h" #include "content/common/renderer_preferences.h" #include "net/base/load_states.h" -#include "net/base/network_change_notifier.h" #include "ui/gfx/native_widget_types.h" #if defined(OS_WIN) @@ -59,8 +59,7 @@ class WebUI; class TabContents : public PageNavigator, public RenderViewHostDelegate, public RenderViewHostManager::Delegate, - public content::JavaScriptDialogDelegate, - public net::NetworkChangeNotifier::OnlineStateObserver { + public content::JavaScriptDialogDelegate { public: // Flags passed to the TabContentsDelegate.NavigationStateChanged to tell it // what has changed. Combine them to update more than one thing. @@ -506,9 +505,6 @@ class TabContents : public PageNavigator, // TODO(brettw) TestTabContents shouldn't exist! friend class TestTabContents; - // Add all the TabContentObservers. - void AddObservers(); - // Message handlers. void OnDidStartProvisionalLoadForFrame(int64 frame_id, bool main_frame, @@ -694,9 +690,6 @@ class TabContents : public PageNavigator, virtual bool CreateRenderViewForRenderManager( RenderViewHost* render_view_host); - // NetworkChangeNotifier::OnlineStateObserver: - virtual void OnOnlineStateChanged(bool online); - // Adds the given window to the list of child windows. The window will notify // via WillClose() when it is being destroyed. void AddConstrainedDialog(ConstrainedWindow* window); diff --git a/content/browser/tab_contents/tab_contents_delegate_unittest.cc b/content/browser/tab_contents/tab_contents_delegate_unittest.cc index 93df01fa..b94df5b 100644 --- a/content/browser/tab_contents/tab_contents_delegate_unittest.cc +++ b/content/browser/tab_contents/tab_contents_delegate_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/memory/scoped_ptr.h" +#include "base/message_loop.h" #include "chrome/test/testing_profile.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_delegate.h" diff --git a/content/common/view_messages.h b/content/common/view_messages.h index 258ea13..17654d2b 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -1149,8 +1149,8 @@ IPC_MESSAGE_ROUTED3(ViewMsg_AsyncOpenFile_ACK, // Tells the renderer that the network state has changed and that // window.navigator.onLine should be updated for all WebViews. -IPC_MESSAGE_ROUTED1(ViewMsg_NetworkStateChanged, - bool /* online */) +IPC_MESSAGE_CONTROL1(ViewMsg_NetworkStateChanged, + bool /* online */) // Enable accessibility in the renderer process. IPC_MESSAGE_ROUTED0(ViewMsg_EnableAccessibility) diff --git a/content/content_browser.gypi b/content/content_browser.gypi index c0d2549a..50414b5 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -200,6 +200,8 @@ 'browser/mach_broker_mac.h', 'browser/mime_registry_message_filter.cc', 'browser/mime_registry_message_filter.h', + 'browser/net/browser_online_state_observer.cc', + 'browser/net/browser_online_state_observer.h', # TODO: These should be moved to test_support (see below), but # are currently used by production code in automation_provider.cc. 'browser/net/url_request_failed_dns_job.cc', diff --git a/content/renderer/render_thread.cc b/content/renderer/render_thread.cc index 93d240b..e933573 100644 --- a/content/renderer/render_thread.cc +++ b/content/renderer/render_thread.cc @@ -58,6 +58,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptController.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" @@ -87,6 +88,7 @@ using WebKit::WebDocument; using WebKit::WebFrame; +using WebKit::WebNetworkStateNotifier; using WebKit::WebRuntimeFeatures; using WebKit::WebScriptController; using WebKit::WebString; @@ -411,6 +413,7 @@ bool RenderThread::OnControlMessageReceived(const IPC::Message& msg) { // is there a new non-windows message I should add here? IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView) IPC_MESSAGE_HANDLER(ViewMsg_PurgePluginListCache, OnPurgePluginListCache) + IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) IPC_MESSAGE_HANDLER(DOMStorageMsg_Event, OnDOMStorageEvent) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -686,6 +689,11 @@ void RenderThread::OnPurgePluginListCache(bool reload_pages) { plugin_refresh_allowed_ = true; } +void RenderThread::OnNetworkStateChanged(bool online) { + EnsureWebKitInitialized(); + WebNetworkStateNotifier::setOnLine(online); +} + scoped_refptr<base::MessageLoopProxy> RenderThread::GetFileThreadMessageLoopProxy() { DCHECK(message_loop() == MessageLoop::current()); diff --git a/content/renderer/render_thread.h b/content/renderer/render_thread.h index 97af783..97419bd 100644 --- a/content/renderer/render_thread.h +++ b/content/renderer/render_thread.h @@ -247,6 +247,7 @@ class RenderThread : public RenderThreadBase, void OnCreateNewView(const ViewMsg_New_Params& params); void OnTransferBitmap(const SkBitmap& bitmap, int resource_id); void OnPurgePluginListCache(bool reload_pages); + void OnNetworkStateChanged(bool online); void OnGetAccessibilityTree(); // We initialize WebKit as late as possible. diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc index aa2493a..06d6a88 100644 --- a/content/renderer/render_view.cc +++ b/content/renderer/render_view.cc @@ -90,7 +90,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" @@ -191,7 +190,6 @@ using WebKit::WebMediaPlayerAction; using WebKit::WebMediaPlayerClient; using WebKit::WebNavigationPolicy; using WebKit::WebNavigationType; -using WebKit::WebNetworkStateNotifier; using WebKit::WebNode; using WebKit::WebPlugin; using WebKit::WebPluginContainer; @@ -671,7 +669,6 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) #endif IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed) - IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged) // TODO(viettrungluu): Move to a separate message filter. #if defined(ENABLE_FLAPPER_HACKS) IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK) @@ -4261,7 +4258,3 @@ void RenderView::OnContextMenuClosed( else context_menu_node_.reset(); } - -void RenderView::OnNetworkStateChanged(bool online) { - WebNetworkStateNotifier::setOnLine(online); -} diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h index cfa86ff..2578eb1 100644 --- a/content/renderer/render_view.h +++ b/content/renderer/render_view.h @@ -776,7 +776,6 @@ class RenderView : public RenderWidget, const WebKit::WebMediaPlayerAction& action); void OnMoveOrResizeStarted(); void OnNavigate(const ViewMsg_Navigate_Params& params); - void OnNetworkStateChanged(bool online); void OnPaste(); #if defined(OS_MACOSX) void OnPluginImeCompositionCompleted(const string16& text, int plugin_id); |