Skip to content

Commit

Permalink
Move chrome/browser/chromeos/process_proxy to chromeos
Browse files Browse the repository at this point in the history
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
  • Loading branch information
phajdan.jr@chromium.org committed Mar 12, 2013
1 parent b0cc590 commit 3a01162
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 77 deletions.
16 changes: 9 additions & 7 deletions chrome/browser/extensions/api/terminal/terminal_private_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions chrome/chrome_browser_chromeos.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion chrome/chrome_tests_unit.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions chromeos/chromeos.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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': [
'..',
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -114,3 +116,5 @@ void ProcessOutputWatcher::ReadFromFd(ProcessOutputType type, int* fd) {
void ProcessOutputWatcher::OnStop() {
delete this;
}

} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
// 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 {

const int kReadBufferSize = 256;

} // namespace

namespace chromeos {

enum ProcessOutputType {
PROCESS_OUTPUT_TYPE_OUT,
PROCESS_OUTPUT_TYPE_ERR,
Expand All @@ -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);
Expand Down Expand Up @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -165,3 +167,5 @@ TEST_F(ProcessOutputWatcherTest, SendNull) {

RunTest(test_cases);
};

} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 {

Expand All @@ -34,6 +33,8 @@ const int kInvalidFd = -1;

} // namespace

namespace chromeos {

ProcessProxy::ProcessProxy(): process_launched_(false),
callback_set_(false),
watcher_started_(false) {
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -134,6 +141,8 @@ void ProcessProxy::Close() {

process_launched_ = false;
callback_set_ = false;
callback_ = ProcessOutputCallback();
callback_runner_ = NULL;

base::KillProcess(pid_, 0, true /* wait */);

Expand Down Expand Up @@ -252,3 +261,5 @@ void ProcessProxy::ClearFdPair(int* pipe) {
pipe[PIPE_END_READ] = kInvalidFd;
pipe[PIPE_END_WRITE] = kInvalidFd;
}

} // namespace chromeos
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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();

Expand All @@ -80,6 +84,7 @@ class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> {

bool callback_set_;
ProcessOutputCallback callback_;
scoped_refptr<base::TaskRunner> callback_runner_;

bool watcher_started_;

Expand All @@ -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_
Loading

0 comments on commit 3a01162

Please sign in to comment.