diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 08:04:53 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-09 08:04:53 +0000 |
commit | 3a3085e4167ef0a9e9b0b8c31930e2e61dc210fc (patch) | |
tree | b8b73d5e2d2418bd3a15e0ffdc488080cc21d27d /chrome | |
parent | 2191d2082e2bf1f937ec4592b4f8c185f04f3fd6 (diff) | |
download | chromium_src-3a3085e4167ef0a9e9b0b8c31930e2e61dc210fc.zip chromium_src-3a3085e4167ef0a9e9b0b8c31930e2e61dc210fc.tar.gz chromium_src-3a3085e4167ef0a9e9b0b8c31930e2e61dc210fc.tar.bz2 |
Revert 34146 - A place to store the pid>mach_port_t mapping.
Not yet for review.
Landing to measure perf impact, will revert immediately.
BUG=13156
TEST=unittests
Review URL: http://codereview.chromium.org/460126
TBR=thakis@chromium.org
Review URL: http://codereview.chromium.org/466088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34147 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/child_process_launcher.cc | 109 | ||||
-rw-r--r-- | chrome/browser/mach_broker_mac.cc | 47 | ||||
-rw-r--r-- | chrome/browser/mach_broker_mac.h | 81 | ||||
-rw-r--r-- | chrome/browser/mach_broker_mac_unittest.cc | 29 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 9 | ||||
-rw-r--r-- | chrome/browser/task_manager.cc | 6 | ||||
-rw-r--r-- | chrome/browser/task_manager.h | 9 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 2 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 | ||||
-rwxr-xr-x | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/mach_ipc_mac.h | 5 | ||||
-rw-r--r-- | chrome/common/mach_ipc_mac.mm | 8 | ||||
-rw-r--r-- | chrome/renderer/renderer_main.cc | 62 |
13 files changed, 9 insertions, 361 deletions
diff --git a/chrome/browser/child_process_launcher.cc b/chrome/browser/child_process_launcher.cc index 843188f..956f836 100644 --- a/chrome/browser/child_process_launcher.cc +++ b/chrome/browser/child_process_launcher.cc @@ -27,99 +27,6 @@ #include "base/global_descriptors_posix.h" #endif -#if defined(OS_MACOSX) -#include "ipc/ipc_switches.h" -#include "chrome/browser/mach_broker_mac.h" -#include "chrome/common/mach_ipc_mac.h" -#endif - -#if defined(OS_MACOSX) -class MachTask : public Task { - public: - MachTask(std::string channel_name, mach_port_t* task, mach_port_t* host) - : task_(task), host_(host) { - // TODO(thakis): Move some place central - const std::string kMachChannelPrefix = "com.Google.Chrome"; - std::string channel = kMachChannelPrefix + channel_name; - - // This creates our named server port -- needs to happen on the current - // thread. -printf("Creating receive port %s\n", channel.c_str()); - port_.reset(new ReceivePort(channel.c_str())); - } - - virtual void Run() { - // TODO(thakis): Move some place central - const int kMachPortMessageID = 57; - - const int kMachPortMessageReceiveWaitMs = 1000; - - - - //ReceivePort receivePort(channel_name.c_str()); - - // TODO(thakis): time histogram between creation and port reception? - MachReceiveMessage message; - kern_return_t result = port_->WaitForMessage( - &message, kMachPortMessageReceiveWaitMs); - if (result == KERN_SUCCESS) { - CHECK(kMachPortMessageID == message.GetMessageID()); - CHECK(2 == message.GetDescriptorCount()); - - // TODO(thakis): Constants for the indices? - *task_ = message.GetTranslatedPort(0); - *host_ = message.GetTranslatedPort(1); - printf("yay\n"); - } else { - // TODO(thakis): Log somewhere? - printf("nay\n"); - } - } - - private: - scoped_ptr<ReceivePort> port_; - mach_port_t* task_; - mach_port_t* host_; -}; - -class MachTask2 : public Task { - public: - MachTask2(mach_port_t task, mach_port_t host, base::ProcessHandle pid) - : task_(task), host_(host), pid_(pid) {} - - virtual void Run() { - MachBroker::instance()->RegisterPid( - pid_, - MachBroker::MachInfo().SetTask(task_).SetHost(host_)); - } - private: - mach_port_t task_; - mach_port_t host_; - base::ProcessHandle pid_; -}; - -class MachThread : public base::Thread { - public: - MachThread() : base::Thread("MachThread"), task_(0), host_(0) {} - - void DoIt(const std::string& channel_name) { - DCHECK(message_loop()); - message_loop()->PostTask(FROM_HERE, - new MachTask(channel_name, &task_, &host_)); - } - - void DoIt2(base::ProcessHandle pid) { - DCHECK(message_loop()); - message_loop()->PostTask(FROM_HERE, - new MachTask2(task_, host_, pid)); - } - - private: - mach_port_t task_; - mach_port_t host_; -}; -#endif - // Having the functionality of ChildProcessLauncher be in an internal // ref counted object allows us to automatically terminate the process when the // parent class destructs, while still holding on to state that we need. @@ -253,25 +160,9 @@ class ChildProcessLauncher::Context } #endif // defined(OS_LINUX) -#if defined(OS_MACOSX) - // TODO(thakis): Possibly somewhere else? - // (then again, the fds duping stuff is here too, so maybe it's ok) - - MachThread mach_thread; - CHECK(mach_thread.Start()); - mach_thread.DoIt( - cmd_line->GetSwitchValueASCII(switches::kProcessChannelID)); -#endif - - // Actually launch the app. if (!base::LaunchApp(cmd_line->argv(), env, fds_to_map, false, &handle)) handle = base::kNullProcessHandle; - -#if defined(OS_MACOSX) - // TODO(thakis): Check |handle| first. - mach_thread.DoIt2(handle); -#endif } #endif diff --git a/chrome/browser/mach_broker_mac.cc b/chrome/browser/mach_broker_mac.cc deleted file mode 100644 index 6d9779e..0000000 --- a/chrome/browser/mach_broker_mac.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2009 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/mach_broker_mac.h" - -#include "base/logging.h" - -// Constructor. -MachBroker::MachBroker() {} - -// Returns the global MachBroker. -MachBroker* MachBroker::instance() { - return Singleton<MachBroker>::get(); -} - -// Returns the mach task belonging to |pid|. -mach_port_t MachBroker::MachTaskForPid(base::ProcessHandle pid) const { - AutoLock lock(lock_); - MachBroker::MachMap::const_iterator it = mach_map_.find(pid); - if (it == mach_map_.end()) - return 0; - return it->second.mach_task_; -} - -// Returns the mach host belonging to |pid|. -mach_port_t MachBroker::MachHostForPid(base::ProcessHandle pid) const { - AutoLock lock(lock_); - MachMap::const_iterator it = mach_map_.find(pid); - if (it == mach_map_.end()) - return 0; - return it->second.mach_host_; -} - -// Adds mach info for a given pid. -void MachBroker::RegisterPid( - base::ProcessHandle pid, const MachInfo& mach_info) { - AutoLock lock(lock_); - DCHECK(mach_map_.count(pid) == 0); - mach_map_[pid] = mach_info; -} - -// Removes all mappings belonging to |pid| from the broker. -void MachBroker::Invalidate(base::ProcessHandle pid) { - AutoLock lock(lock_); - mach_map_.erase(pid); -} diff --git a/chrome/browser/mach_broker_mac.h b/chrome/browser/mach_broker_mac.h deleted file mode 100644 index 5672db5..0000000 --- a/chrome/browser/mach_broker_mac.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2009 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_MACH_BROKER_H_ -#define CHROME_BROWSER_MACH_BROKER_H_ - -#include <map> - -#include <mach/mach.h> - -#include "base/lock.h" -#include "base/process.h" -#include "base/singleton.h" - -// On OS X, the mach_port_t of a process is required to collect metrics about -// the process. Running |task_for_pid()| is only allowed for priviledged code. -// However, a process has port rights to all its subprocesses, so let the -// browser's child processes send their mach_port_t to the browser over IPC. -// This way, the brower can at least collect metrics of its child processes, -// which is what it's most interested in anyway. -// -// mach_port_ts can only be sent over mach ipc, not over the socketpair that -// the regular ipc system uses. Hence, the child processes open a mach -// connection shortly after launching and ipc their mach data to the browser -// process. This data is kept in a global |MachBroker| object. -// -// Due to this data arriving over a separate channel, it is not available -// immediately after a child process has been started. -class MachBroker { - public: - // Returns the global MachBroker. - static MachBroker* instance(); - - // Returns the mach task belonging to |pid|, or 0 if no mach task is - // registered for |pid|. - mach_port_t MachTaskForPid(base::ProcessHandle pid) const; - - // Returns the mach host belonging to |pid|, or 0 if no mach task is - // registered for |pid|. - mach_port_t MachHostForPid(base::ProcessHandle pid) const; - - struct MachInfo { - MachInfo() : mach_task_(0), mach_host_(0) {} - - MachInfo& SetTask(mach_port_t task) { - mach_task_ = task; - return *this; - } - - MachInfo& SetHost(mach_port_t host) { - mach_host_ = host; - return *this; - } - - mach_port_t mach_task_; - mach_port_t mach_host_; - }; - - // Adds mach info for a given pid. - void RegisterPid(base::ProcessHandle pid, const MachInfo& mach_info); - - // Removes all mappings belonging to |pid| from the broker. - void Invalidate(base::ProcessHandle pid); - - private: - // Private constructor. - MachBroker(); - friend struct DefaultSingletonTraits<MachBroker>; - friend class MachBrokerTest; - - // Stores - typedef std::map<base::ProcessHandle, MachInfo> MachMap; - MachMap mach_map_; - - // Mutex that guards |mach_map_|. - mutable Lock lock_; -}; - -#endif // CHROME_BROWSER_MACH_BROKER_H_ - diff --git a/chrome/browser/mach_broker_mac_unittest.cc b/chrome/browser/mach_broker_mac_unittest.cc deleted file mode 100644 index 745d0d7..0000000 --- a/chrome/browser/mach_broker_mac_unittest.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2009 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/mach_broker_mac.h" - -#include "testing/gtest/include/gtest/gtest.h" - -class MachBrokerTest : public testing::Test { - public: - MachBroker broker_; -}; - -TEST_F(MachBrokerTest, Setter) { - broker_.RegisterPid(1u, MachBroker::MachInfo().SetTask(2u).SetHost(3u)); - - EXPECT_EQ(2u, broker_.MachTaskForPid(1)); - EXPECT_EQ(3u, broker_.MachHostForPid(1)); - - EXPECT_EQ(0u, broker_.MachTaskForPid(2)); - EXPECT_EQ(0u, broker_.MachHostForPid(3)); -} - -TEST_F(MachBrokerTest, Invalidate) { - broker_.RegisterPid(1u, MachBroker::MachInfo().SetTask(2).SetHost(3)); - broker_.Invalidate(1u); - EXPECT_EQ(0u, broker_.MachTaskForPid(1)); - EXPECT_EQ(0u, broker_.MachHostForPid(1)); -} diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 8423516..c7325ad 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -62,10 +62,6 @@ #include "app/win_util.h" #endif -#if defined(OS_MACOSX) -#include "chrome/browser/mach_broker_mac.h" -#endif - using WebKit::WebCache; #include "third_party/skia/include/core/SkBitmap.h" @@ -841,11 +837,6 @@ void BrowserRenderProcessHost::OnChannelError() { ClearTransportDIBCache(); -#if defined(OS_MACOSX) - if (child_process_.get()) - MachBroker::instance()->Invalidate(child_process_->GetHandle()); -#endif - // this object is not deleted at this point and may be reused later. // TODO(darin): clean this up } diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index cd059be..43952a5 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -770,12 +770,12 @@ void TaskManagerModel::OnJobRemoved(URLRequestJob* job) { } void TaskManagerModel::OnJobDone(URLRequestJob* job, - const URLRequestStatus& status) { + const URLRequestStatus& status) { } void TaskManagerModel::OnJobRedirect(URLRequestJob* job, - const GURL& location, - int status_code) { + const GURL& location, + int status_code) { } void TaskManagerModel::OnBytesRead(URLRequestJob* job, int byte_count) { diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index 3df4653..f49e1e5 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -46,15 +46,6 @@ class TaskManager { virtual std::wstring GetTitle() const = 0; virtual SkBitmap GetIcon() const = 0; virtual base::ProcessHandle GetProcess() const = 0; -#if defined(OS_MACOSX) - // TODO(thakis): All the providers need to get these somewhere (child - // processes need to IPC them to us via mach IPC at some point). - // TODO(thakis): TMM needs to hand this on to ProcessMetrics. - // TODO(thakis): ProcessMetrics then needs to call mach data collection apis - // if it has the mach ports it needs. - virtual mach_port_t GetMachHostPort() const { return 0; }; - virtual mach_port_t GetMachTaskPort() const { return 0; }; -#endif virtual bool ReportsCacheStats() const { return false; } virtual WebKit::WebCache::ResourceTypeStats GetWebCoreCacheStats() const { diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 5d5e0b2..730ff1a 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -521,8 +521,6 @@ 'common/logging_chrome.cc', 'common/logging_chrome.h', 'common/main_function_params.h', - 'common/mach_ipc_mac.h', - 'common/mach_ipc_mac.mm', 'common/message_router.cc', 'common/message_router.h', 'common/mru_cache.h', diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index f54b3921..654c285 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1066,8 +1066,6 @@ 'browser/login_prompt_mac.h', 'browser/login_prompt_mac.mm', 'browser/login_prompt_win.cc', - 'browser/mach_broker_mac.cc', - 'browser/mach_broker_mac.h', 'browser/memory_details.cc', 'browser/memory_details_linux.cc', 'browser/memory_details_mac.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index d163070..65d8fbc 100755 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -706,7 +706,6 @@ 'browser/keychain_mock_mac.h', 'browser/login_prompt_unittest.cc', 'browser/meta_table_helper_unittest.cc', - 'browser/mach_broker_mac_unittest.cc', 'browser/metrics/metrics_log_unittest.cc', 'browser/metrics/metrics_response_unittest.cc', 'browser/metrics/metrics_service_unittest.cc', diff --git a/chrome/common/mach_ipc_mac.h b/chrome/common/mach_ipc_mac.h index 42b9c65..8c345dd 100644 --- a/chrome/common/mach_ipc_mac.h +++ b/chrome/common/mach_ipc_mac.h @@ -167,9 +167,8 @@ class MachMessage { bool AddDescriptor(const MachMsgPortDescriptor &desc); int GetDescriptorCount() const { - return storage_->body.msgh_descriptor_count; - } - + return storage_->body.msgh_descriptor_count; + } MachMsgPortDescriptor *GetDescriptor(int n); // Convenience method which gets the mach port described by the descriptor diff --git a/chrome/common/mach_ipc_mac.mm b/chrome/common/mach_ipc_mac.mm index 7693d9a..3c95ef6 100644 --- a/chrome/common/mach_ipc_mac.mm +++ b/chrome/common/mach_ipc_mac.mm @@ -213,10 +213,10 @@ ReceivePort::ReceivePort() { if (init_result_ != KERN_SUCCESS) return; - init_result_ = mach_port_insert_right(current_task, - port_, - port_, - MACH_MSG_TYPE_MAKE_SEND); + init_result_ = mach_port_insert_right(current_task, + port_, + port_, + MACH_MSG_TYPE_MAKE_SEND); } //============================================================================== diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc index ebacbbf..c8f89c9 100644 --- a/chrome/renderer/renderer_main.cc +++ b/chrome/renderer/renderer_main.cc @@ -32,12 +32,6 @@ #include "chrome/app/breakpad_linux.h" #endif -#if defined(OS_MACOSX) -#include "ipc/ipc_switches.h" -#include "base/thread.h" -#include "chrome/common/mach_ipc_mac.h" -#endif - // This function provides some ways to test crash and assertion handling // behavior of the renderer. static void HandleRendererErrorTestParameters(const CommandLine& command_line) { @@ -57,54 +51,6 @@ static void HandleRendererErrorTestParameters(const CommandLine& command_line) { } } -#if defined(OS_MACOSX) -class MachSendTask : public Task { - public: - MachSendTask(const std::string& channel_name) : channel_name_(channel_name) {} - - virtual void Run() { - // TODO(thakis): Put these somewhere central. - const int kMachPortMessageID = 57; - const std::string kMachChannelPrefix = "com.Google.Chrome"; - - const int kMachPortMessageSendWaitMs = 5000; - std::string channel_name = kMachChannelPrefix + channel_name_; -printf("Creating send port %s\n", channel_name.c_str()); - MachPortSender sender(channel_name.c_str()); - MachSendMessage message(kMachPortMessageID); - - // add some ports to be translated for us - message.AddDescriptor(mach_task_self()); - message.AddDescriptor(mach_host_self()); - - kern_return_t result = sender.SendMessage(message, - kMachPortMessageSendWaitMs); - - // TODO(thakis): Log error somewhere? (don't printf in any case :-P) - fprintf(stderr, "send result: %lu\n", (unsigned long)result); - if (result != KERN_SUCCESS) - fprintf(stderr, "(Failed :-( )\n"); - } - private: - std::string channel_name_; -}; - -class MachSendThread : public base::Thread { - public: - MachSendThread() : base::Thread("MachSendThread") {} - - void DoIt() { - DCHECK(message_loop()); - std::string name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kProcessChannelID); -printf("main thread: %s\n", name.c_str()); - message_loop()->PostTask( - FROM_HERE, - new MachSendTask(name)); - } -}; -#endif - // mainline routine for running as the Renderer process int RendererMain(const MainFunctionParams& parameters) { const CommandLine& parsed_command_line = parameters.command_line_; @@ -130,14 +76,6 @@ int RendererMain(const MainFunctionParams& parameters) { startup_timer(chrome::Counters::renderer_main()); #if defined(OS_MACOSX) - { - MachSendThread mach_thread; - CHECK(mach_thread.Start()); - mach_thread.DoIt(); - } -#endif - -#if defined(OS_MACOSX) // As long as we use Cocoa in the renderer (for the forseeable future as of // now; see http://crbug.com/13890 for info) we need to have a UI loop. MessageLoop main_message_loop(MessageLoop::TYPE_UI); |