summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorcmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 19:40:32 +0000
committercmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 19:40:32 +0000
commit1aec2f80567b705f00a7a0d54956aaeb34527273 (patch)
treea4c38bca591a54a9fa619704b8fecca79f627777 /chrome/browser/chromeos
parente8bebc486242601ee6098f7c276af32bfe20542a (diff)
downloadchromium_src-1aec2f80567b705f00a7a0d54956aaeb34527273.zip
chromium_src-1aec2f80567b705f00a7a0d54956aaeb34527273.tar.gz
chromium_src-1aec2f80567b705f00a7a0d54956aaeb34527273.tar.bz2
Changes to support communication with a privileged process
This change allows the chrome-login code to talk back to a privileged process and ask it to emit upstart signals and such. Eventually, this IPC will be changed to use DBus, probably when cryptohomed lands. Review URL: http://codereview.chromium.org/518086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/ipc_message.h15
-rw-r--r--chrome/browser/chromeos/login_manager_view.cc65
-rw-r--r--chrome/browser/chromeos/login_manager_view.h13
3 files changed, 62 insertions, 31 deletions
diff --git a/chrome/browser/chromeos/ipc_message.h b/chrome/browser/chromeos/ipc_message.h
new file mode 100644
index 0000000..e92c066
--- /dev/null
+++ b/chrome/browser/chromeos/ipc_message.h
@@ -0,0 +1,15 @@
+// Copyright (c) 2010 The Chromium OS 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_CHROMEOS_IPC_MESSAGE_H_
+#define CHROME_BROWSER_CHROMEOS_IPC_MESSAGE_H_
+
+enum IpcMessage {
+ EMIT_LOGIN = 'a',
+ START_SESSION = 'b',
+ STOP_SESSION = 'c',
+ FAILED = 'f',
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_IPC_MESSAGE_H_
diff --git a/chrome/browser/chromeos/login_manager_view.cc b/chrome/browser/chromeos/login_manager_view.cc
index 89f6098..6a48513 100644
--- a/chrome/browser/chromeos/login_manager_view.cc
+++ b/chrome/browser/chromeos/login_manager_view.cc
@@ -4,11 +4,16 @@
#include "chrome/browser/chromeos/login_manager_view.h"
+#include <signal.h>
+#include <sys/types.h>
+
#include "app/resource_bundle.h"
+#include "base/file_path.h"
#include "base/keyboard_codes.h"
#include "base/logging.h"
#include "base/process_util.h"
#include "chrome/browser/chromeos/image_background.h"
+#include "chrome/browser/chromeos/ipc_message.h"
#include "chrome/common/chrome_switches.h"
#include "grit/theme_resources.h"
#include "views/controls/label.h"
@@ -36,15 +41,6 @@ const int kBottomPadding = 112;
namespace browser {
-bool EmitLoginPromptReady() {
- base::ProcessHandle handle;
- std::vector<std::string> argv;
- argv.push_back("/opt/google/chrome/emit_login_prompt_ready");
- base::environment_vector no_env;
- base::file_handle_mapping_vector no_files;
- return base::LaunchApp(argv, no_env, no_files, false, &handle);
-}
-
// Acts as a frame view with no UI.
class LoginManagerNonClientFrameView : public views::NonClientFrameView {
public:
@@ -76,8 +72,10 @@ class LoginManagerNonClientFrameView : public views::NonClientFrameView {
// Subclass of WindowGtk, for use as the top level login window.
class LoginManagerWindow : public views::WindowGtk {
public:
- static LoginManagerWindow* CreateLoginManagerWindow() {
- LoginManagerWindow* login_manager_window = new LoginManagerWindow();
+ static LoginManagerWindow* CreateLoginManagerWindow(
+ const FilePath& pipe_name) {
+ LoginManagerWindow* login_manager_window =
+ new LoginManagerWindow(pipe_name);
login_manager_window->GetNonClientView()->SetFrameView(
new LoginManagerNonClientFrameView());
login_manager_window->Init(NULL, gfx::Rect());
@@ -85,16 +83,18 @@ class LoginManagerWindow : public views::WindowGtk {
}
private:
- explicit LoginManagerWindow() : views::WindowGtk(new LoginManagerView()) {}
+ explicit LoginManagerWindow(const FilePath& pipe_name)
+ : views::WindowGtk(new LoginManagerView(pipe_name)) {
+ }
DISALLOW_COPY_AND_ASSIGN(LoginManagerWindow);
};
// Declared in browser_dialogs.h so that others don't need to depend on our .h.
-void ShowLoginManager() {
- views::WindowGtk* window = LoginManagerWindow::CreateLoginManagerWindow();
+void ShowLoginManager(const FilePath& pipe_name) {
+ views::WindowGtk* window =
+ LoginManagerWindow::CreateLoginManagerWindow(pipe_name);
window->Show();
- EmitLoginPromptReady();
bool old_state = MessageLoop::current()->NestableTasksAllowed();
MessageLoop::current()->SetNestableTasksAllowed(true);
MessageLoop::current()->Run();
@@ -102,11 +102,14 @@ void ShowLoginManager() {
}
} // namespace browser
-LoginManagerView::LoginManagerView() {
+LoginManagerView::LoginManagerView(const FilePath& pipe_name)
+ : pipe_(fopen(pipe_name.value().c_str(), "w")) {
Init();
}
LoginManagerView::~LoginManagerView() {
+ if (pipe_)
+ fclose(pipe_);
MessageLoop::current()->Quit();
}
@@ -189,6 +192,7 @@ void LoginManagerView::BuildWindow() {
}
layout->AddPaddingRow(1, 0);
+ EmitLoginPromptReady();
}
views::View* LoginManagerView::GetContentsView() {
@@ -212,18 +216,23 @@ bool LoginManagerView::Authenticate(const std::string& username,
child_exit_code == 0;
}
-bool LoginManagerView::RunWindowManager(const std::string& username) {
- base::ProcessHandle handle;
- std::vector<std::string> argv;
- // TODO(cmasone): we'll want this to be configurable.
- argv.push_back("/etc/init.d/start_wm.sh");
- base::environment_vector env;
+bool LoginManagerView::Send(IpcMessage outgoing) {
+ if (pipe_) {
+ if (fwrite(&outgoing, sizeof(IpcMessage), 1, pipe_) == 1) {
+ // since we're only writing 1 "member", fwrite will return 1 on success
+ // and 0 on failure. On success, we want to flush the buffer.
+ return fflush(pipe_) != EOF;
+ }
+ }
+ return false;
+}
- // TODO(cmasone): This is a legacy way of communication the logged in user's
- // email to xscreensaver. Figure out a better way.
- env.push_back(std::pair<std::string, std::string>("CHROMEOS_USER", username));
- base::file_handle_mapping_vector no_files;
- return base::LaunchApp(argv, env, no_files, false, &handle);
+bool LoginManagerView::EmitLoginPromptReady() {
+ return Send(EMIT_LOGIN);
+}
+
+bool LoginManagerView::RunWindowManager(const std::string& username) {
+ return Send(START_SESSION);
}
void LoginManagerView::SetupSession(const std::string& username) {
@@ -270,5 +279,3 @@ bool LoginManagerView::HandleKeystroke(views::Textfield* s,
// Return false so that processing does not end
return false;
}
-
-
diff --git a/chrome/browser/chromeos/login_manager_view.h b/chrome/browser/chromeos/login_manager_view.h
index 2ac687b..b6c8b52 100644
--- a/chrome/browser/chromeos/login_manager_view.h
+++ b/chrome/browser/chromeos/login_manager_view.h
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <string>
+#include "chrome/browser/chromeos/ipc_message.h"
#include "views/accelerator.h"
#include "views/controls/textfield/textfield.h"
#include "views/view.h"
@@ -12,11 +13,13 @@
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MANAGER_VIEW_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGER_VIEW_H_
+class FilePath;
+
class LoginManagerView : public views::View,
public views::WindowDelegate,
public views::Textfield::Controller {
public:
- LoginManagerView();
+ LoginManagerView(const FilePath& pipe_name);
virtual ~LoginManagerView();
// Initialize the controls on the dialog.
@@ -39,6 +42,8 @@ class LoginManagerView : public views::View,
// Creates all examples and start UI event loop.
private:
+ FILE* pipe_;
+
views::Textfield* username_field_;
views::Textfield* password_field_;
@@ -57,6 +62,11 @@ class LoginManagerView : public views::View,
bool Authenticate(const std::string& username,
const std::string& password);
+ bool Send(IpcMessage outgoing);
+
+ // Asynchronously emits the login-prompt-ready upstart signal.
+ bool EmitLoginPromptReady();
+
// Asynchronously launches the Chrome OS window manager.
bool RunWindowManager(const std::string& username);
@@ -72,4 +82,3 @@ class LoginManagerView : public views::View,
};
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_MANAGER_VIEW_H_
-