diff options
author | cmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 20:39:34 +0000 |
---|---|---|
committer | cmasone@google.com <cmasone@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-20 20:39:34 +0000 |
commit | c2eb2d6132dd631c5db8c86cf644184568a77807 (patch) | |
tree | 32dc23583824cfc33bac8d77891116147a089142 /chrome | |
parent | 065566b96e3aca9a6ac1288b64dd47eda305cc8a (diff) | |
download | chromium_src-c2eb2d6132dd631c5db8c86cf644184568a77807.zip chromium_src-c2eb2d6132dd631c5db8c86cf644184568a77807.tar.gz chromium_src-c2eb2d6132dd631c5db8c86cf644184568a77807.tar.bz2 |
Change to DBus-based IPC to talk to the Chromium OS session manager
Review URL: http://codereview.chromium.org/551066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_main.cc | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login_library.cc | 38 | ||||
-rw-r--r-- | chrome/browser/chromeos/login_library.h | 54 | ||||
-rw-r--r-- | chrome/browser/chromeos/login_manager_view.cc | 44 | ||||
-rw-r--r-- | chrome/browser/chromeos/login_manager_view.h | 9 | ||||
-rw-r--r-- | chrome/browser/views/browser_dialogs.h | 2 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 2 |
7 files changed, 107 insertions, 45 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 644a5f6..b2fba94 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -577,8 +577,7 @@ int BrowserMain(const MainFunctionParams& parameters) { #if defined(OS_CHROMEOS) if (parsed_command_line.HasSwitch(switches::kLoginManager)) { - browser::ShowLoginManager( - parsed_command_line.GetSwitchValuePath(switches::kSessionManagerPipe)); + browser::ShowLoginManager(); } #endif // OS_CHROMEOS diff --git a/chrome/browser/chromeos/login_library.cc b/chrome/browser/chromeos/login_library.cc new file mode 100644 index 0000000..79e7e2d --- /dev/null +++ b/chrome/browser/chromeos/login_library.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2010 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/chromeos/login_library.h" + +#include "base/message_loop.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/chromeos/cros_library.h" + +namespace chromeos { + +// static +LoginLibrary* LoginLibrary::Get() { + return Singleton<LoginLibrary>::get(); +} + +// static +bool LoginLibrary::EnsureLoaded() { + return CrosLibrary::EnsureLoaded(); +} + +bool LoginLibrary::EmitLoginPromptReady() { + return chromeos::EmitLoginPromptReady(); +} + +bool LoginLibrary::StartSession(const std::string& user_email, + const std::string& unique_id /* unused */) { + // only pass unique_id through once we use it for something. + return chromeos::StartSession(user_email.c_str(), ""); +} + +bool LoginLibrary::StopSession(const std::string& unique_id /* unused */) { + // only pass unique_id through once we use it for something. + return chromeos::StopSession(""); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/login_library.h b/chrome/browser/chromeos/login_library.h new file mode 100644 index 0000000..3b9f25a --- /dev/null +++ b/chrome/browser/chromeos/login_library.h @@ -0,0 +1,54 @@ +// Copyright (c) 2010 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_CHROMEOS_LOGIN_LIBRARY_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_LIBRARY_H_ + +#include <string> + +#include "base/singleton.h" +#include "third_party/cros/chromeos_login.h" + +namespace chromeos { + +// This class handles the interaction with the ChromeOS login library APIs. +// Users can get an instance of this library class like this: +// LoginLibrary::Get() +class LoginLibrary { + public: + // This gets the singleton LoginLibrary. + static LoginLibrary* Get(); + + // Makes sure the library is loaded, loading it if necessary. Returns true if + // the library has been successfully loaded. + static bool EnsureLoaded(); + + // Requests that the Upstart signal login-prompt-ready be emitted. + bool EmitLoginPromptReady(); + + // Tells the session manager to start a logged-in session for the user + // |user_email|. |unique_id| is meant to be used when we have a non-human- + // readable unique identifier by which we distinguish users (to deal with + // potential email address changes over time). + bool StartSession(const std::string& user_email, + const std::string& unique_id /* unused */); + + // Tells the session manager to terminate the current logged-in session. + // In the event that we ever support multiple simultaneous user sessions, + // This will tell the session manager to terminate the session for the user + // indicated by |unique_id|. + bool StopSession(const std::string& unique_id /* unused */); + + private: + friend struct DefaultSingletonTraits<LoginLibrary>; + + LoginLibrary() {} + ~LoginLibrary() {} + + DISALLOW_COPY_AND_ASSIGN(LoginLibrary); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LIBRARY_H_ diff --git a/chrome/browser/chromeos/login_manager_view.cc b/chrome/browser/chromeos/login_manager_view.cc index 6a48513..d727368 100644 --- a/chrome/browser/chromeos/login_manager_view.cc +++ b/chrome/browser/chromeos/login_manager_view.cc @@ -13,7 +13,7 @@ #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/browser/chromeos/login_library.h" #include "chrome/common/chrome_switches.h" #include "grit/theme_resources.h" #include "views/controls/label.h" @@ -72,10 +72,9 @@ 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( - const FilePath& pipe_name) { + static LoginManagerWindow* CreateLoginManagerWindow() { LoginManagerWindow* login_manager_window = - new LoginManagerWindow(pipe_name); + new LoginManagerWindow; login_manager_window->GetNonClientView()->SetFrameView( new LoginManagerNonClientFrameView()); login_manager_window->Init(NULL, gfx::Rect()); @@ -83,18 +82,18 @@ class LoginManagerWindow : public views::WindowGtk { } private: - explicit LoginManagerWindow(const FilePath& pipe_name) - : views::WindowGtk(new LoginManagerView(pipe_name)) { - } + LoginManagerWindow() : views::WindowGtk(new LoginManagerView) { } DISALLOW_COPY_AND_ASSIGN(LoginManagerWindow); }; // Declared in browser_dialogs.h so that others don't need to depend on our .h. -void ShowLoginManager(const FilePath& pipe_name) { +void ShowLoginManager() { + chromeos::LoginLibrary::EnsureLoaded(); views::WindowGtk* window = - LoginManagerWindow::CreateLoginManagerWindow(pipe_name); + LoginManagerWindow::CreateLoginManagerWindow(); window->Show(); + chromeos::LoginLibrary::Get()->EmitLoginPromptReady(); bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); MessageLoop::current()->Run(); @@ -102,14 +101,11 @@ void ShowLoginManager(const FilePath& pipe_name) { } } // namespace browser -LoginManagerView::LoginManagerView(const FilePath& pipe_name) - : pipe_(fopen(pipe_name.value().c_str(), "w")) { +LoginManagerView::LoginManagerView() { Init(); } LoginManagerView::~LoginManagerView() { - if (pipe_) - fclose(pipe_); MessageLoop::current()->Quit(); } @@ -192,7 +188,6 @@ void LoginManagerView::BuildWindow() { } layout->AddPaddingRow(1, 0); - EmitLoginPromptReady(); } views::View* LoginManagerView::GetContentsView() { @@ -216,25 +211,6 @@ bool LoginManagerView::Authenticate(const std::string& username, child_exit_code == 0; } -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; -} - -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) { if (window()) { window()->Close(); @@ -246,7 +222,7 @@ void LoginManagerView::SetupSession(const std::string& username) { CommandLine::ForCurrentProcess()->AppendSwitch( switches::kAutoSSLClientAuth); } - RunWindowManager(username); + chromeos::LoginLibrary::Get()->StartSession(username, ""); } bool LoginManagerView::HandleKeystroke(views::Textfield* s, diff --git a/chrome/browser/chromeos/login_manager_view.h b/chrome/browser/chromeos/login_manager_view.h index b6c8b52..49ebbbe 100644 --- a/chrome/browser/chromeos/login_manager_view.h +++ b/chrome/browser/chromeos/login_manager_view.h @@ -19,7 +19,7 @@ class LoginManagerView : public views::View, public views::WindowDelegate, public views::Textfield::Controller { public: - LoginManagerView(const FilePath& pipe_name); + LoginManagerView(); virtual ~LoginManagerView(); // Initialize the controls on the dialog. @@ -42,8 +42,6 @@ class LoginManagerView : public views::View, // Creates all examples and start UI event loop. private: - FILE* pipe_; - views::Textfield* username_field_; views::Textfield* password_field_; @@ -62,11 +60,6 @@ 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); diff --git a/chrome/browser/views/browser_dialogs.h b/chrome/browser/views/browser_dialogs.h index 81ab259..62e25e0 100644 --- a/chrome/browser/views/browser_dialogs.h +++ b/chrome/browser/views/browser_dialogs.h @@ -90,7 +90,7 @@ void ShowTaskManager(); #if defined(OS_CHROMEOS) // Shows the Login Manager. -void ShowLoginManager(const FilePath& pipe_name); +void ShowLoginManager(); #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 382d1b6..d5e8123 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -277,6 +277,8 @@ 'browser/chromeos/login_manager_view.h', 'browser/chromeos/main_menu.cc', 'browser/chromeos/main_menu.h', + 'browser/chromeos/login_library.cc', + 'browser/chromeos/login_library.h', 'browser/chromeos/mount_library.cc', 'browser/chromeos/mount_library.h', 'browser/chromeos/network_library.cc', |