summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/browser_main.cc3
-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
-rw-r--r--chrome/browser/views/browser_dialogs.h3
-rwxr-xr-xchrome/chrome_browser.gypi1
-rw-r--r--chrome/common/chrome_switches.cc1
-rw-r--r--chrome/common/chrome_switches.h1
8 files changed, 69 insertions, 33 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 995f625..521513f 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -504,7 +504,8 @@ int BrowserMain(const MainFunctionParams& parameters) {
#if defined(OS_CHROMEOS)
if (parsed_command_line.HasSwitch(switches::kLoginManager)) {
- browser::ShowLoginManager();
+ browser::ShowLoginManager(
+ parsed_command_line.GetSwitchValuePath(switches::kSessionManagerPipe));
}
#endif // OS_CHROMEOS
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_
-
diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h
index feeb2aeb..81ab259 100644
--- a/chrome/browser/views/browser_dialogs.h
+++ b/chrome/browser/views/browser_dialogs.h
@@ -15,6 +15,7 @@
class Browser;
class BrowserView;
class EditSearchEngineControllerDelegate;
+class FilePath;
class FindBar;
class GURL;
class HtmlDialogUIDelegate;
@@ -89,7 +90,7 @@ void ShowTaskManager();
#if defined(OS_CHROMEOS)
// Shows the Login Manager.
-void ShowLoginManager();
+void ShowLoginManager(const FilePath& pipe_name);
#endif
// Shows a dialog box that allows a search engine to be edited. |template_url|
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index b18c7b9..16d33a9 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -262,6 +262,7 @@
'browser/chromeos/external_protocol_dialog.h',
'browser/chromeos/gview_request_interceptor.cc',
'browser/chromeos/gview_request_interceptor.h',
+ 'browser/chromeos/ipc_message.h',
'browser/chromeos/language_library.cc',
'browser/chromeos/language_library.h',
'browser/chromeos/language_menu_button.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index b4e5ce4..96df9be 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -681,6 +681,7 @@ const char kEnableGView[] = "enable-gview";
// Enable experimental Chrome-as-a-login-manager behavior.
const char kLoginManager[] = "login-manager";
+const char kSessionManagerPipe[] = "session-manager-pipe";
// Attempts to load libcros and validate it, then exits. A nonzero return code
// means the library could not be loaded correctly.
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 56b5189..11ca7c4 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -197,6 +197,7 @@ extern const char kZygoteProcess[];
extern const char kCookiePipe[];
extern const char kEnableGView[];
extern const char kLoginManager[];
+extern const char kSessionManagerPipe[];
extern const char kTestLoadLibcros[];
extern const char kProfile[];
extern const char kChromeosFrame[];