Move chrome/browser/chromeos/process_proxy to chromeos
BUG=180711 Review URL: https://codereview.chromium.org/12433023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187641 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome
chromeos
@ -8,7 +8,7 @@
|
||||
#include "base/chromeos/chromeos_version.h"
|
||||
#include "base/json/json_writer.h"
|
||||
#include "base/values.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_proxy_registry.h"
|
||||
#include "chromeos/process_proxy/process_proxy_registry.h"
|
||||
#include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
|
||||
#include "chrome/browser/extensions/event_names.h"
|
||||
#include "chrome/browser/extensions/event_router.h"
|
||||
@ -105,9 +105,11 @@ bool TerminalPrivateOpenTerminalProcessFunction::RunTerminalFunction() {
|
||||
void TerminalPrivateOpenTerminalProcessFunction::OpenOnFileThread() {
|
||||
DCHECK(command_);
|
||||
|
||||
ProcessProxyRegistry* registry = ProcessProxyRegistry::Get();
|
||||
chromeos::ProcessProxyRegistry* registry =
|
||||
chromeos::ProcessProxyRegistry::Get();
|
||||
pid_t pid;
|
||||
if (!registry->OpenProcess(command_, &pid,
|
||||
if (!registry->OpenProcess(
|
||||
command_, &pid,
|
||||
base::Bind(&NotifyProcessOutput, profile_, extension_id()))) {
|
||||
// If new process could not be opened, we return -1.
|
||||
pid = -1;
|
||||
@ -143,7 +145,7 @@ bool TerminalPrivateSendInputFunction::RunTerminalFunction() {
|
||||
|
||||
void TerminalPrivateSendInputFunction::SendInputOnFileThread(pid_t pid,
|
||||
const std::string& text) {
|
||||
bool success = ProcessProxyRegistry::Get()->SendInput(pid, text);
|
||||
bool success = chromeos::ProcessProxyRegistry::Get()->SendInput(pid, text);
|
||||
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&TerminalPrivateSendInputFunction::RespondOnUIThread, this,
|
||||
@ -174,7 +176,7 @@ bool TerminalPrivateCloseTerminalProcessFunction::RunTerminalFunction() {
|
||||
}
|
||||
|
||||
void TerminalPrivateCloseTerminalProcessFunction::CloseOnFileThread(pid_t pid) {
|
||||
bool success = ProcessProxyRegistry::Get()->CloseProcess(pid);
|
||||
bool success = chromeos::ProcessProxyRegistry::Get()->CloseProcess(pid);
|
||||
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&TerminalPrivateCloseTerminalProcessFunction::
|
||||
@ -216,8 +218,8 @@ bool TerminalPrivateOnTerminalResizeFunction::RunTerminalFunction() {
|
||||
|
||||
void TerminalPrivateOnTerminalResizeFunction::OnResizeOnFileThread(pid_t pid,
|
||||
int width, int height) {
|
||||
bool success = ProcessProxyRegistry::Get()->OnTerminalResize(pid,
|
||||
width, height);
|
||||
bool success = chromeos::ProcessProxyRegistry::Get()->OnTerminalResize(
|
||||
pid, width, height);
|
||||
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&TerminalPrivateOnTerminalResizeFunction::RespondOnUIThread,
|
||||
|
@ -593,12 +593,6 @@
|
||||
'browser/chromeos/preferences.h',
|
||||
'browser/chromeos/prerender_condition_network.cc',
|
||||
'browser/chromeos/prerender_condition_network.h',
|
||||
'browser/chromeos/process_proxy/process_output_watcher.cc',
|
||||
'browser/chromeos/process_proxy/process_output_watcher.h',
|
||||
'browser/chromeos/process_proxy/process_proxy.cc',
|
||||
'browser/chromeos/process_proxy/process_proxy.h',
|
||||
'browser/chromeos/process_proxy/process_proxy_registry.cc',
|
||||
'browser/chromeos/process_proxy/process_proxy_registry.h',
|
||||
'browser/chromeos/profile_startup.cc',
|
||||
'browser/chromeos/profile_startup.h',
|
||||
'browser/chromeos/proxy_config_service_impl.cc',
|
||||
|
@ -1134,7 +1134,6 @@
|
||||
'browser/chromeos/memory/oom_priority_manager_browsertest.cc',
|
||||
'browser/chromeos/net/mock_connectivity_state_helper.cc',
|
||||
'browser/chromeos/net/mock_connectivity_state_helper.h',
|
||||
'browser/chromeos/process_proxy/process_proxy_browsertest.cc',
|
||||
'browser/chromeos/screensaver/screensaver_controller_browsertest.cc',
|
||||
'browser/chromeos/system/tray_accessibility_browsertest.cc',
|
||||
'browser/chromeos/ui/idle_logout_dialog_view_browsertest.cc',
|
||||
|
@ -608,7 +608,6 @@
|
||||
'browser/chromeos/offline/offline_load_page_unittest.cc',
|
||||
'browser/chromeos/power/session_length_limiter_unittest.cc',
|
||||
'browser/chromeos/preferences_unittest.cc',
|
||||
'browser/chromeos/process_proxy/process_output_watcher_unittest.cc',
|
||||
'browser/chromeos/proxy_config_service_impl_unittest.cc',
|
||||
'browser/chromeos/settings/cros_settings_unittest.cc',
|
||||
'browser/chromeos/settings/device_settings_provider_unittest.cc',
|
||||
|
@ -16,6 +16,7 @@
|
||||
'dependencies': [
|
||||
'../base/base.gyp:base',
|
||||
'../base/base.gyp:base_prefs',
|
||||
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
|
||||
'../build/linux/system.gyp:dbus',
|
||||
'../build/linux/system.gyp:ssl',
|
||||
'../dbus/dbus.gyp:dbus',
|
||||
@ -197,6 +198,12 @@
|
||||
'network/sms_watcher.h',
|
||||
'power/power_state_override.cc',
|
||||
'power/power_state_override.h',
|
||||
'process_proxy/process_output_watcher.cc',
|
||||
'process_proxy/process_output_watcher.h',
|
||||
'process_proxy/process_proxy.cc',
|
||||
'process_proxy/process_proxy.h',
|
||||
'process_proxy/process_proxy_registry.cc',
|
||||
'process_proxy/process_proxy_registry.h',
|
||||
],
|
||||
'conditions': [
|
||||
['use_x11 == 1', {
|
||||
@ -375,6 +382,8 @@
|
||||
'network/onc/onc_validator_unittest.cc',
|
||||
'network/shill_property_handler_unittest.cc',
|
||||
'power/power_state_override_unittest.cc',
|
||||
'process_proxy/process_output_watcher_unittest.cc',
|
||||
'process_proxy/process_proxy_unittest.cc',
|
||||
],
|
||||
'include_dirs': [
|
||||
'..',
|
||||
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/chromeos/process_proxy/process_output_watcher.h"
|
||||
#include "chromeos/process_proxy/process_output_watcher.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@ -34,6 +34,8 @@ void CloseFd(int* fd) {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
ProcessOutputWatcher::ProcessOutputWatcher(int out_fd, int stop_fd,
|
||||
const ProcessOutputCallback& callback)
|
||||
: out_fd_(out_fd),
|
||||
@ -114,3 +116,5 @@ void ProcessOutputWatcher::ReadFromFd(ProcessOutputType type, int* fd) {
|
||||
void ProcessOutputWatcher::OnStop() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
} // namespace chromeos
|
@ -2,12 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
||||
#define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
||||
#ifndef CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
||||
#define CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "chromeos/chromeos_export.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -15,6 +16,8 @@ const int kReadBufferSize = 256;
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
enum ProcessOutputType {
|
||||
PROCESS_OUTPUT_TYPE_OUT,
|
||||
PROCESS_OUTPUT_TYPE_ERR,
|
||||
@ -26,7 +29,7 @@ typedef base::Callback<void(ProcessOutputType, const std::string&)>
|
||||
|
||||
// This class should live on its own thread because running class makes
|
||||
// underlying thread block. It deletes itself when watching is stopped.
|
||||
class ProcessOutputWatcher {
|
||||
class CHROMEOS_EXPORT ProcessOutputWatcher {
|
||||
public:
|
||||
ProcessOutputWatcher(int out_fd, int stop_fd,
|
||||
const ProcessOutputCallback& callback);
|
||||
@ -64,4 +67,7 @@ class ProcessOutputWatcher {
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessOutputWatcher);
|
||||
};
|
||||
#endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
||||
|
||||
} // namespace chromeos
|
||||
|
||||
#endif // CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
|
@ -15,7 +15,9 @@
|
||||
#include "base/posix/eintr_wrapper.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_output_watcher.h"
|
||||
#include "chromeos/process_proxy/process_output_watcher.h"
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
struct TestCase {
|
||||
std::string str;
|
||||
@ -165,3 +167,5 @@ TEST_F(ProcessOutputWatcherTest, SendNull) {
|
||||
|
||||
RunTest(test_cases);
|
||||
};
|
||||
|
||||
} // namespace chromeos
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/chromeos/process_proxy/process_proxy.h"
|
||||
#include "chromeos/process_proxy/process_proxy.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
@ -15,8 +15,7 @@
|
||||
#include "base/process_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_output_watcher.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "chromeos/process_proxy/process_output_watcher.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -34,6 +33,8 @@ const int kInvalidFd = -1;
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
ProcessProxy::ProcessProxy(): process_launched_(false),
|
||||
callback_set_(false),
|
||||
watcher_started_(false) {
|
||||
@ -63,8 +64,9 @@ bool ProcessProxy::Open(const std::string& command, pid_t* pid) {
|
||||
return process_launched_;
|
||||
}
|
||||
|
||||
bool ProcessProxy::StartWatchingOnThread(base::Thread* watch_thread,
|
||||
const ProcessOutputCallback& callback) {
|
||||
bool ProcessProxy::StartWatchingOnThread(
|
||||
base::Thread* watch_thread,
|
||||
const ProcessOutputCallback& callback) {
|
||||
DCHECK(process_launched_);
|
||||
if (watcher_started_)
|
||||
return false;
|
||||
@ -80,6 +82,7 @@ bool ProcessProxy::StartWatchingOnThread(base::Thread* watch_thread,
|
||||
|
||||
callback_set_ = true;
|
||||
callback_ = callback;
|
||||
callback_runner_ = base::MessageLoopProxy::current();
|
||||
|
||||
// This object will delete itself once watching is stopped.
|
||||
// It also takes ownership of the passed fds.
|
||||
@ -102,13 +105,17 @@ bool ProcessProxy::StartWatchingOnThread(base::Thread* watch_thread,
|
||||
|
||||
void ProcessProxy::OnProcessOutput(ProcessOutputType type,
|
||||
const std::string& output) {
|
||||
// We have to check if callback is set on FILE thread..
|
||||
if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)) {
|
||||
content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
|
||||
base::Bind(&ProcessProxy::OnProcessOutput, this, type, output));
|
||||
if (!callback_runner_)
|
||||
return;
|
||||
}
|
||||
|
||||
callback_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProcessProxy::CallOnProcessOutputCallback,
|
||||
this, type, output));
|
||||
}
|
||||
|
||||
void ProcessProxy::CallOnProcessOutputCallback(ProcessOutputType type,
|
||||
const std::string& output) {
|
||||
// We may receive some output even after Close was called (crosh process does
|
||||
// not have to quit instantly, or there may be some trailing data left in
|
||||
// output stream fds). In that case owner of the callback may be gone so we
|
||||
@ -134,6 +141,8 @@ void ProcessProxy::Close() {
|
||||
|
||||
process_launched_ = false;
|
||||
callback_set_ = false;
|
||||
callback_ = ProcessOutputCallback();
|
||||
callback_runner_ = NULL;
|
||||
|
||||
base::KillProcess(pid_, 0, true /* wait */);
|
||||
|
||||
@ -252,3 +261,5 @@ void ProcessProxy::ClearFdPair(int* pipe) {
|
||||
pipe[PIPE_END_READ] = kInvalidFd;
|
||||
pipe[PIPE_END_WRITE] = kInvalidFd;
|
||||
}
|
||||
|
||||
} // namespace chromeos
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
||||
#define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
||||
#ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
||||
#define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
@ -12,12 +12,14 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_output_watcher.h"
|
||||
#include "chromeos/process_proxy/process_output_watcher.h"
|
||||
|
||||
namespace base {
|
||||
class TaskRunner;
|
||||
class Thread;
|
||||
} // namespace base
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
// Proxy to a single ChromeOS process.
|
||||
// This is refcounted. Note that output watcher, when it gets triggered owns a
|
||||
@ -62,6 +64,8 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {
|
||||
// Gets called by output watcher when the process writes something to its
|
||||
// output streams.
|
||||
void OnProcessOutput(ProcessOutputType type, const std::string& output);
|
||||
void CallOnProcessOutputCallback(ProcessOutputType type,
|
||||
const std::string& output);
|
||||
|
||||
bool StopWatching();
|
||||
|
||||
@ -80,6 +84,7 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {
|
||||
|
||||
bool callback_set_;
|
||||
ProcessOutputCallback callback_;
|
||||
scoped_refptr<base::TaskRunner> callback_runner_;
|
||||
|
||||
bool watcher_started_;
|
||||
|
||||
@ -89,4 +94,6 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessProxy);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
||||
} // namespace chromeos
|
||||
|
||||
#endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_
|
@ -2,10 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/chromeos/process_proxy/process_proxy_registry.h"
|
||||
#include "chromeos/process_proxy/process_proxy_registry.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
namespace {
|
||||
|
||||
const char kWatcherThreadName[] = "ProcessWatcherThread";
|
||||
@ -48,6 +50,10 @@ ProcessProxyRegistry::ProcessProxyRegistry() {
|
||||
}
|
||||
|
||||
ProcessProxyRegistry::~ProcessProxyRegistry() {
|
||||
// TODO(tbarzic): Fix issue with ProcessProxyRegistry being destroyed
|
||||
// on a different thread (it's a LazyInstance).
|
||||
DetachFromThread();
|
||||
|
||||
// Close all proxies we own.
|
||||
while (!proxy_map_.empty())
|
||||
CloseProcess(proxy_map_.begin()->first);
|
||||
@ -58,8 +64,12 @@ ProcessProxyRegistry* ProcessProxyRegistry::Get() {
|
||||
return g_process_proxy_registry.Pointer();
|
||||
}
|
||||
|
||||
bool ProcessProxyRegistry::OpenProcess(const std::string& command, pid_t* pid,
|
||||
bool ProcessProxyRegistry::OpenProcess(
|
||||
const std::string& command,
|
||||
pid_t* pid,
|
||||
const ProcessOutputCallbackWithPid& callback) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
// TODO(tbarzic): Instead of creating a new thread for each new process proxy,
|
||||
// use one thread for all processes.
|
||||
// We will need new thread for proxy's outpu watcher.
|
||||
@ -97,6 +107,8 @@ bool ProcessProxyRegistry::OpenProcess(const std::string& command, pid_t* pid,
|
||||
}
|
||||
|
||||
bool ProcessProxyRegistry::SendInput(pid_t pid, const std::string& data) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
std::map<pid_t, ProcessProxyInfo>::iterator it = proxy_map_.find(pid);
|
||||
if (it == proxy_map_.end())
|
||||
return false;
|
||||
@ -104,6 +116,8 @@ bool ProcessProxyRegistry::SendInput(pid_t pid, const std::string& data) {
|
||||
}
|
||||
|
||||
bool ProcessProxyRegistry::CloseProcess(pid_t pid) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
std::map<pid_t, ProcessProxyInfo>::iterator it = proxy_map_.find(pid);
|
||||
if (it == proxy_map_.end())
|
||||
return false;
|
||||
@ -115,6 +129,8 @@ bool ProcessProxyRegistry::CloseProcess(pid_t pid) {
|
||||
}
|
||||
|
||||
bool ProcessProxyRegistry::OnTerminalResize(pid_t pid, int width, int height) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
std::map<pid_t, ProcessProxyInfo>::iterator it = proxy_map_.find(pid);
|
||||
if (it == proxy_map_.end())
|
||||
return false;
|
||||
@ -124,6 +140,8 @@ bool ProcessProxyRegistry::OnTerminalResize(pid_t pid, int width, int height) {
|
||||
|
||||
void ProcessProxyRegistry::OnProcessOutput(pid_t pid,
|
||||
ProcessOutputType type, const std::string& data) {
|
||||
DCHECK(CalledOnValidThread());
|
||||
|
||||
const char* type_str = ProcessOutputTypeToString(type);
|
||||
DCHECK(type_str);
|
||||
|
||||
@ -138,3 +156,4 @@ void ProcessProxyRegistry::OnProcessOutput(pid_t pid,
|
||||
CloseProcess(pid);
|
||||
}
|
||||
|
||||
} // namespace chromeos
|
@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
||||
#define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
||||
#ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
||||
#define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -11,15 +11,19 @@
|
||||
#include "base/lazy_instance.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/threading/non_thread_safe.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_proxy.h"
|
||||
#include "chromeos/chromeos_export.h"
|
||||
#include "chromeos/process_proxy/process_proxy.h"
|
||||
|
||||
namespace chromeos {
|
||||
|
||||
typedef base::Callback<void(pid_t, const std::string&, const std::string&)>
|
||||
ProcessOutputCallbackWithPid;
|
||||
|
||||
// Keeps track of all created ProcessProxies. It is created lazily and should
|
||||
// live on the FILE thread (where all methods must be called).
|
||||
class ProcessProxyRegistry {
|
||||
// live on a single thread (where all methods must be called).
|
||||
class CHROMEOS_EXPORT ProcessProxyRegistry : public base::NonThreadSafe {
|
||||
public:
|
||||
// Info we need about a ProcessProxy instance.
|
||||
struct ProcessProxyInfo {
|
||||
@ -59,12 +63,6 @@ class ProcessProxyRegistry {
|
||||
void OnProcessOutput(pid_t pid,
|
||||
ProcessOutputType type,
|
||||
const std::string& data);
|
||||
// Must be called on UI thread. This lives on FILE thread, thus static.
|
||||
// Notifies CroshProcessEventRouter about new process output. Assumes the
|
||||
// event router has already been initialized by someone else.
|
||||
static void DispatchProcessOutputOnUIThread(pid_t pid,
|
||||
const std::string& output_type,
|
||||
const std::string& output);
|
||||
|
||||
// Map of all existing ProcessProxies.
|
||||
std::map<pid_t, ProcessProxyInfo> proxy_map_;
|
||||
@ -72,4 +70,6 @@ class ProcessProxyRegistry {
|
||||
DISALLOW_COPY_AND_ASSIGN(ProcessProxyRegistry);
|
||||
};
|
||||
|
||||
#endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
||||
} // namespace chromeos
|
||||
|
||||
#endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
|
@ -14,12 +14,9 @@
|
||||
#include "base/process_util.h"
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/threading/thread.h"
|
||||
#include "chrome/browser/chromeos/process_proxy/process_proxy_registry.h"
|
||||
#include "chrome/test/base/in_process_browser_test.h"
|
||||
#include "chrome/test/base/ui_test_utils.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "chromeos/process_proxy/process_proxy_registry.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
namespace chromeos {
|
||||
|
||||
namespace {
|
||||
|
||||
@ -80,7 +77,7 @@ class RegistryTestRunner : public TestRunner {
|
||||
}
|
||||
|
||||
if (!valid || TestSucceeded()) {
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
MessageLoop::QuitClosure());
|
||||
}
|
||||
}
|
||||
@ -96,7 +93,7 @@ class RegistryTestRunner : public TestRunner {
|
||||
if (stream >= arraysize(left_to_check_index_))
|
||||
return false;
|
||||
bool success = left_to_check_index_[stream] < expected_line_.length() &&
|
||||
expected_line_[left_to_check_index_[stream]] == received;
|
||||
expected_line_[left_to_check_index_[stream]] == received;
|
||||
if (success)
|
||||
left_to_check_index_[stream]++;
|
||||
if (left_to_check_index_[stream] == expected_line_.length() &&
|
||||
@ -111,8 +108,8 @@ class RegistryTestRunner : public TestRunner {
|
||||
|
||||
bool TestSucceeded() {
|
||||
return left_to_check_index_[0] == expected_line_.length() &&
|
||||
left_to_check_index_[1] == expected_line_.length() &&
|
||||
lines_left_ == 0;
|
||||
left_to_check_index_[1] == expected_line_.length() &&
|
||||
lines_left_ == 0;
|
||||
}
|
||||
|
||||
size_t left_to_check_index_[2];
|
||||
@ -140,7 +137,7 @@ class RegistryNotifiedOnProcessExitTestRunner : public TestRunner {
|
||||
return;
|
||||
}
|
||||
EXPECT_EQ("exit", type);
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
MessageLoop::QuitClosure());
|
||||
}
|
||||
|
||||
@ -166,10 +163,10 @@ class SigIntTestRunner : public TestRunner {
|
||||
// We may receive ^C on stdout, but we don't care about that, as long as we
|
||||
// eventually received exit event.
|
||||
if (type == "exit") {
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
MessageLoop::QuitClosure());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void StartRegistryTest(ProcessProxyRegistry* registry) OVERRIDE {
|
||||
// Send SingInt and verify the process exited.
|
||||
@ -179,7 +176,7 @@ class SigIntTestRunner : public TestRunner {
|
||||
|
||||
} // namespace
|
||||
|
||||
class ProcessProxyTest : public InProcessBrowserTest {
|
||||
class ProcessProxyTest : public testing::Test {
|
||||
public:
|
||||
ProcessProxyTest() {}
|
||||
virtual ~ProcessProxyTest() {}
|
||||
@ -188,9 +185,10 @@ class ProcessProxyTest : public InProcessBrowserTest {
|
||||
void InitRegistryTest() {
|
||||
registry_ = ProcessProxyRegistry::Get();
|
||||
|
||||
EXPECT_TRUE(registry_->OpenProcess(kCatCommand, &pid_,
|
||||
base::Bind(&TestRunner::OnSomeRead,
|
||||
base::Unretained(test_runner_.get()))));
|
||||
EXPECT_TRUE(registry_->OpenProcess(
|
||||
kCatCommand, &pid_,
|
||||
base::Bind(&TestRunner::OnSomeRead,
|
||||
base::Unretained(test_runner_.get()))));
|
||||
|
||||
test_runner_->SetupExpectations(pid_);
|
||||
test_runner_->StartRegistryTest(registry_);
|
||||
@ -204,25 +202,27 @@ class ProcessProxyTest : public InProcessBrowserTest {
|
||||
if (status == base::TERMINATION_STATUS_STILL_RUNNING)
|
||||
base::KillProcess(pid_, 0, true);
|
||||
|
||||
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
|
||||
MessageLoop::current()->PostTask(FROM_HERE,
|
||||
MessageLoop::QuitClosure());
|
||||
}
|
||||
|
||||
void RunTest() {
|
||||
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
||||
base::Bind(&ProcessProxyTest::InitRegistryTest,
|
||||
base::Unretained(this)));
|
||||
MessageLoop::current()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProcessProxyTest::InitRegistryTest,
|
||||
base::Unretained(this)));
|
||||
|
||||
// Wait until all data from output watcher is received (QuitTask will be
|
||||
// fired on watcher thread).
|
||||
content::RunMessageLoop();
|
||||
MessageLoop::current()->Run();
|
||||
|
||||
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
||||
base::Bind(&ProcessProxyTest::EndRegistryTest,
|
||||
base::Unretained(this)));
|
||||
MessageLoop::current()->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&ProcessProxyTest::EndRegistryTest,
|
||||
base::Unretained(this)));
|
||||
|
||||
// Wait until we clean up the process proxy.
|
||||
content::RunMessageLoop();
|
||||
MessageLoop::current()->Run();
|
||||
}
|
||||
|
||||
scoped_ptr<TestRunner> test_runner_;
|
||||
@ -230,24 +230,28 @@ class ProcessProxyTest : public InProcessBrowserTest {
|
||||
private:
|
||||
ProcessProxyRegistry* registry_;
|
||||
pid_t pid_;
|
||||
|
||||
MessageLoop message_loop_;
|
||||
};
|
||||
|
||||
// Test will open new process that will run cat command, and verify data we
|
||||
// write to process gets echoed back.
|
||||
IN_PROC_BROWSER_TEST_F(ProcessProxyTest, RegistryTest) {
|
||||
TEST_F(ProcessProxyTest, RegistryTest) {
|
||||
test_runner_.reset(new RegistryTestRunner());
|
||||
RunTest();
|
||||
}
|
||||
|
||||
// Open new process, then kill it. Verifiy that we detect when the process dies.
|
||||
IN_PROC_BROWSER_TEST_F(ProcessProxyTest, RegistryNotifiedOnProcessExit) {
|
||||
TEST_F(ProcessProxyTest, RegistryNotifiedOnProcessExit) {
|
||||
test_runner_.reset(new RegistryNotifiedOnProcessExitTestRunner());
|
||||
RunTest();
|
||||
}
|
||||
|
||||
// Test verifies that \003 message send to process is processed as SigInt.
|
||||
// Timing out on the waterfall: http://crbug.com/115064
|
||||
IN_PROC_BROWSER_TEST_F(ProcessProxyTest, DISABLED_SigInt) {
|
||||
TEST_F(ProcessProxyTest, DISABLED_SigInt) {
|
||||
test_runner_.reset(new SigIntTestRunner());
|
||||
RunTest();
|
||||
}
|
||||
|
||||
} // namespace chromeos
|
Reference in New Issue
Block a user