diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 18:57:46 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 18:57:46 +0000 |
commit | 201b273dda785bdf5559cefa83c7955fd4aefeba (patch) | |
tree | 8f1bca5b3d307dcbdb2184557f6e791033c0a32c /chrome/browser | |
parent | 15cf713daabbba9e96ee2b9372de56941b7a46a2 (diff) | |
download | chromium_src-201b273dda785bdf5559cefa83c7955fd4aefeba.zip chromium_src-201b273dda785bdf5559cefa83c7955fd4aefeba.tar.gz chromium_src-201b273dda785bdf5559cefa83c7955fd4aefeba.tar.bz2 |
Small clean-up to not expose base::Process from RenderProcesHost, and instead only expose base::ProcessHandle. Precursor to moving process startup off the UI thread.
Review URL: http://codereview.chromium.org/387047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31922 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
16 files changed, 45 insertions, 47 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index e07b8e6..22149c2 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -13,6 +13,7 @@ #include "base/keyboard_codes.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/process_util.h" #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/thread.h" @@ -1049,7 +1050,7 @@ void AutomationProvider::GetTabProcessID(int handle, int* process_id) { TabContents* tab_contents = tab_tracker_->GetResource(handle)->tab_contents(); if (tab_contents->process()) - *process_id = tab_contents->process()->process().pid(); + *process_id = base::GetProcId(tab_contents->process()->GetHandle()); } } diff --git a/chrome/browser/child_process_security_policy_browser_test.cc b/chrome/browser/child_process_security_policy_browser_test.cc index ab613f3..7bd8d5c 100644 --- a/chrome/browser/child_process_security_policy_browser_test.cc +++ b/chrome/browser/child_process_security_policy_browser_test.cc @@ -40,8 +40,7 @@ IN_PROC_BROWSER_TEST_F(ChildProcessSecurityPolicyInProcessBrowserTest, NoLeak) { TabContents* tab = browser()->GetTabContentsAt(0); ASSERT_TRUE(tab != NULL); base::KillProcess( - tab->process()->process().handle(), base::PROCESS_END_KILLED_BY_USER, - true); + tab->process()->GetHandle(), base::PROCESS_END_KILLED_BY_USER, true); tab->controller().Reload(true); EXPECT_EQ( diff --git a/chrome/browser/cocoa/hung_renderer_controller.mm b/chrome/browser/cocoa/hung_renderer_controller.mm index 3c37cf8..6d7eb35 100644 --- a/chrome/browser/cocoa/hung_renderer_controller.mm +++ b/chrome/browser/cocoa/hung_renderer_controller.mm @@ -77,8 +77,8 @@ HungRendererController* g_instance = NULL; - (IBAction)kill:(id)sender { if (hungContents_) - base::KillProcess(hungContents_->process()->process().handle(), - ResultCodes::HUNG, false); + base::KillProcess(hungContents_->process()->GetHandle(), ResultCodes::HUNG, + false); // Cannot call performClose:, because the close button is disabled. [self close]; } diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index a99a362..1f67979 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -281,7 +281,7 @@ void ExtensionFunctionDispatcher::HandleBadMessage(ExtensionFunction* api) { CHECK(false); } else { NOTREACHED(); - base::KillProcess(render_view_host_->process()->process().handle(), + base::KillProcess(render_view_host_->process()->GetHandle(), ResultCodes::KILLED_BAD_MESSAGE, false); } } diff --git a/chrome/browser/gtk/hung_renderer_dialog_gtk.cc b/chrome/browser/gtk/hung_renderer_dialog_gtk.cc index dfd7fc2..a5e603d 100644 --- a/chrome/browser/gtk/hung_renderer_dialog_gtk.cc +++ b/chrome/browser/gtk/hung_renderer_dialog_gtk.cc @@ -183,8 +183,8 @@ void HungRendererDialogGtk::OnDialogResponse(gint response_id) { switch (response_id) { case kKillPagesButtonResponse: // Kill the process. - base::KillProcess(contents_->process()->process().handle(), - ResultCodes::HUNG, false); + base::KillProcess(contents_->process()->GetHandle(), ResultCodes::HUNG, + false); break; case GTK_RESPONSE_OK: diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc index 9953442a..f212698 100644 --- a/chrome/browser/memory_details.cc +++ b/chrome/browser/memory_details.cc @@ -92,8 +92,10 @@ void MemoryDetails::CollectChildInfoOnUIThread() { RenderProcessHost::AllHostsIterator()); !renderer_iter.IsAtEnd(); renderer_iter.Advance()) { DCHECK(renderer_iter.GetCurrentValue()); - if (process.pid != renderer_iter.GetCurrentValue()->process().pid()) + if (process.pid != + base::GetProcId(renderer_iter.GetCurrentValue()->GetHandle())) { continue; + } process.type = ChildProcessInfo::RENDER_PROCESS; // The RenderProcessHost may host multiple TabContents. Any // of them which contain diagnostics information make the whole diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 1a301ee..c180fa0 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -645,9 +645,10 @@ base::ProcessHandle BrowserRenderProcessHost::ExecuteRenderer( #endif // defined(OS_POSIX) -base::ProcessHandle BrowserRenderProcessHost::GetRendererProcessHandle() { +base::ProcessHandle BrowserRenderProcessHost::GetHandle() { if (run_renderer_in_process()) return base::Process::Current().handle(); + return process_.handle(); } @@ -658,8 +659,7 @@ void BrowserRenderProcessHost::InitVisitedLinks() { } base::SharedMemoryHandle handle_for_process; - bool r = visitedlink_master->ShareToProcess(GetRendererProcessHandle(), - &handle_for_process); + bool r = visitedlink_master->ShareToProcess(GetHandle(), &handle_for_process); DCHECK(r); if (base::SharedMemory::IsHandleValid(handle_for_process)) { @@ -691,8 +691,7 @@ void BrowserRenderProcessHost::InitExtensions() { void BrowserRenderProcessHost::SendUserScriptsUpdate( base::SharedMemory *shared_memory) { base::SharedMemoryHandle handle_for_process; - if (!shared_memory->ShareToProcess(GetRendererProcessHandle(), - &handle_for_process)) { + if (!shared_memory->ShareToProcess(GetHandle(), &handle_for_process)) { // This can legitimately fail if the renderer asserts at startup. return; } @@ -770,7 +769,7 @@ TransportDIB* BrowserRenderProcessHost::MapTransportDIB( #if defined(OS_WIN) // On Windows we need to duplicate the handle from the remote process HANDLE section = win_util::GetSectionFromProcess( - dib_id.handle, GetRendererProcessHandle(), false /* read write */); + dib_id.handle, GetHandle(), false /* read write */); return TransportDIB::Map(section); #elif defined(OS_MACOSX) // On OSX, the browser allocates all DIBs and keeps a file descriptor around @@ -1131,8 +1130,7 @@ void BrowserRenderProcessHost::InitSpellChecker() { file = base::FileDescriptor(spellcheck_host->bdict_file(), false); #elif defined(OS_WIN) ::DuplicateHandle(::GetCurrentProcess(), spellcheck_host->bdict_file(), - process().handle(), &file, - 0, false, DUPLICATE_SAME_ACCESS); + GetHandle(), &file, 0, false, DUPLICATE_SAME_ACCESS); #endif Send(new ViewMsg_SpellChecker_Init( file, diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h index 2d01df8..762beff 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.h +++ b/chrome/browser/renderer_host/browser_render_process_host.h @@ -70,6 +70,7 @@ class BrowserRenderProcessHost : public RenderProcessHost, virtual void ResetVisitedLinks(); virtual bool FastShutdownIfPossible(); virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms); + virtual base::ProcessHandle GetHandle(); virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); // IPC::Channel::Sender via RenderProcessHost. @@ -138,10 +139,6 @@ class BrowserRenderProcessHost : public RenderProcessHost, base::ProcessHandle ExecuteRenderer(CommandLine* cmd_line, bool has_cmd_prefix); - // Gets a handle to the renderer process, normalizing the case where we were - // started with --single-process. - base::ProcessHandle GetRendererProcessHandle(); - // Callers can reduce the RenderProcess' priority. // Returns true if the priority is backgrounded; false otherwise. void SetBackgrounded(bool boost); @@ -205,6 +202,8 @@ class BrowserRenderProcessHost : public RenderProcessHost, // True iff the renderer is a child of a zygote process. bool zygote_child_; + base::Process process_; + DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); }; diff --git a/chrome/browser/renderer_host/mock_render_process_host.h b/chrome/browser/renderer_host/mock_render_process_host.h index 79f1539..56e3bb3 100644 --- a/chrome/browser/renderer_host/mock_render_process_host.h +++ b/chrome/browser/renderer_host/mock_render_process_host.h @@ -11,9 +11,8 @@ class TransportDIB; -// A mock render process host that has no corresponding renderer process. The -// process() refers to the current process, and all IPC messages are sent into -// the message sink for inspection by tests. +// A mock render process host that has no corresponding renderer process. All +// IPC messages are sent into the message sink for inspection by tests. class MockRenderProcessHost : public RenderProcessHost { public: MockRenderProcessHost(Profile* profile); @@ -47,6 +46,10 @@ class MockRenderProcessHost : public RenderProcessHost { virtual void ResetVisitedLinks(); virtual bool FastShutdownIfPossible(); virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms); + virtual base::ProcessHandle GetHandle() { + return base::kNullProcessHandle; + } + virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); // IPC::Channel::Sender via RenderProcessHost. diff --git a/chrome/browser/renderer_host/render_process_host.h b/chrome/browser/renderer_host/render_process_host.h index e3e068f..5b1bfc7 100644 --- a/chrome/browser/renderer_host/render_process_host.h +++ b/chrome/browser/renderer_host/render_process_host.h @@ -55,11 +55,6 @@ class RenderProcessHost : public IPC::Channel::Sender, // etc. It is generated by ChildProcessInfo. int id() const { return id_; } - // Returns the process object associated with the child process. In certain - // tests or single-process mode, this will actually represent the current - // process. - const base::Process& process() const { return process_; } - // Returns true iff channel_ has been set to non-NULL. Use this for checking // if there is connection or not. bool HasConnection() { return channel_.get() != NULL; } @@ -194,6 +189,13 @@ class RenderProcessHost : public IPC::Channel::Sender, // not this method succeeds. Returns true on success. virtual bool SendWithTimeout(IPC::Message* msg, int timeout_ms) = 0; + // Returns the process object associated with the child process. In certain + // tests or single-process mode, this will actually represent the current + // process. + // NOTE: this is not valid after calling Init, as it starts the process + // asynchronously. It's guaranteed to be valid after the first IPC arrives. + virtual base::ProcessHandle GetHandle() = 0; + // Transport DIB functions --------------------------------------------------- // Return the TransportDIB for the given id. On Linux, this can involve @@ -238,8 +240,6 @@ class RenderProcessHost : public IPC::Channel::Sender, static RenderProcessHost* GetExistingProcessHost(Profile* profile, Type type); protected: - base::Process process_; - // A proxy for our IPC::Channel that lives on the IO thread (see // browser_process.h) scoped_ptr<IPC::SyncChannel> channel_; diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc index 3e723b4..8141258 100644 --- a/chrome/browser/renderer_host/render_widget_host.cc +++ b/chrome/browser/renderer_host/render_widget_host.cc @@ -1005,7 +1005,7 @@ void RenderWidgetHost::PaintBackingStoreRect(TransportDIB* bitmap, bool needs_full_paint = false; BackingStoreManager::PrepareBackingStore(this, view_size, - process_->process().handle(), + process_->GetHandle(), bitmap, bitmap_rect, &needs_full_paint); if (needs_full_paint) { @@ -1034,7 +1034,7 @@ void RenderWidgetHost::ScrollBackingStoreRect(TransportDIB* bitmap, BackingStore* backing_store = BackingStoreManager::Lookup(this); if (!backing_store || (backing_store->size() != view_size)) return; - backing_store->ScrollRect(process_->process().handle(), bitmap, bitmap_rect, + backing_store->ScrollRect(process_->GetHandle(), bitmap, bitmap_rect, dx, dy, clip_rect, view_size); } diff --git a/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc b/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc index bd4069e..18718f0 100644 --- a/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc +++ b/chrome/browser/renderer_host/test/web_cache_manager_browsertest.cc @@ -30,8 +30,7 @@ IN_PROC_BROWSER_TEST_F(WebCacheManagerBrowserTest, DISABLED_CrashOnceOnly) { TabContents* tab = browser()->GetTabContentsAt(0); ASSERT_TRUE(tab != NULL); base::KillProcess( - tab->process()->process().handle(), base::PROCESS_END_KILLED_BY_USER, - true); + tab->process()->GetHandle(), base::PROCESS_END_KILLED_BY_USER, true); browser()->SelectTabContentsAt(0, true); browser()->NewTab(); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 0d2ba96..a670b0a 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2223,8 +2223,7 @@ void TabContents::DidStopLoading() { // if an iframe injected by script into a blank page finishes loading. if (entry) { scoped_ptr<base::ProcessMetrics> metrics( - base::ProcessMetrics::CreateProcessMetrics( - process()->process().handle())); + base::ProcessMetrics::CreateProcessMetrics(process()->GetHandle())); base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index 20100c0..38d0687 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -53,7 +53,7 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource( pending_v8_memory_allocated_update_(false) { // We cache the process as when the TabContents is closed the process // becomes NULL and the TaskManager still needs it. - process_ = tab_contents_->process()->process().handle(); + process_ = tab_contents_->process()->GetHandle(); pid_ = base::GetProcId(process_); stats_.images.size = 0; stats_.cssStyleSheets.size = 0; @@ -162,14 +162,14 @@ TaskManager::Resource* TaskManagerTabContentsResourceProvider::GetResource( if (!tab_contents) // Not one of our resource. return NULL; - if (!tab_contents->process()->process().handle()) { + if (!tab_contents->process()->GetHandle()) { // We should not be holding on to a dead tab (it should have been removed // through the NOTIFY_TAB_CONTENTS_DISCONNECTED notification. NOTREACHED(); return NULL; } - int pid = tab_contents->process()->process().pid(); + int pid = base::GetProcId(tab_contents->process()->GetHandle()); if (pid != origin_pid) return NULL; @@ -241,7 +241,7 @@ void TaskManagerTabContentsResourceProvider::Add(TabContents* tab_contents) { // Don't add dead tabs or tabs that haven't yet connected. // Also ignore tabs which display extension content. We collapse // all of these into one extension row. - if (!tab_contents->process()->process().handle() || + if (!tab_contents->process()->GetHandle() || !tab_contents->notify_disconnection() || tab_contents->HostsExtension()) { return; @@ -515,9 +515,8 @@ TaskManagerExtensionProcessResource::TaskManagerExtensionProcessResource( ResourceBundle& rb = ResourceBundle::GetSharedInstance(); default_icon_ = rb.GetBitmapNamed(IDR_PLUGIN); } - base::Process process(extension_host_->render_process_host()->process()); - process_handle_ = process.handle(); - pid_ = process.pid(); + process_handle_ = extension_host_->render_process_host()->GetHandle(); + pid_ = base::GetProcId(process_handle_); std::wstring extension_name(UTF8ToWide(GetExtension()->name())); DCHECK(!extension_name.empty()); // Since the extension_name will be concatenated with a prefix, we need diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index 560dbb3..d73a0fc 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -316,8 +316,7 @@ void HungRendererDialogView::ButtonPressed( views::Button* sender, const views::Event& event) { if (sender == kill_button_) { // Kill the process. - HANDLE process = contents_->process()->process().handle(); - TerminateProcess(process, ResultCodes::HUNG); + TerminateProcess(contents_->process()->GetHandle(), ResultCodes::HUNG); } } diff --git a/chrome/browser/visitedlink_event_listener.cc b/chrome/browser/visitedlink_event_listener.cc index 86fe7d5..17ca1fd 100644 --- a/chrome/browser/visitedlink_event_listener.cc +++ b/chrome/browser/visitedlink_event_listener.cc @@ -25,7 +25,7 @@ void VisitedLinkEventListener::NewTable(base::SharedMemory* table_memory) { continue; base::SharedMemoryHandle new_table; - base::ProcessHandle process = i.GetCurrentValue()->process().handle(); + base::ProcessHandle process = i.GetCurrentValue()->GetHandle(); if (!process) { // process can be null if it's started with the --single-process flag. process = base::Process::Current().handle(); |