Skip to content

Commit

Permalink
Add --dbus-stub for testing dbus stub implementations on a device.
Browse files Browse the repository at this point in the history
Change-Id: I4730996e6a860833ce7e66792d62dbd1f6db00ea

BUG=none
TEST=Add --dbus-stub to /sbin/session_manager_startup.sh; dbus stub implementation should be used for non-critical components (e.g. power manager)

Review URL: https://chromiumcodereview.appspot.com/10392029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136629 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
stevenjb@google.com committed May 11, 2012
1 parent db92eeb commit 66149a5
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 60 deletions.
94 changes: 48 additions & 46 deletions chrome/browser/chromeos/login/login_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "chrome/common/net/gaia/gaia_urls.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -1041,82 +1042,83 @@ std::string LoginUtilsImpl::GetOffTheRecordCommandLine(
const CommandLine& base_command_line,
CommandLine* command_line) {
static const char* kForwardSwitches[] = {
switches::kCompressSystemFeedback,
switches::kDeviceManagementUrl,
switches::kDefaultDeviceScaleFactor,
switches::kDisableAccelerated2dCanvas,
switches::kDisableAcceleratedPlugins,
switches::kDisableGpuWatchdog,
switches::kDisableLoginAnimations,
switches::kDisableSeccompFilterSandbox,
switches::kDisableSeccompSandbox,
switches::kDisableThreadedAnimation,
switches::kEnableDevicePolicy,
switches::kEnableGView,
switches::kEnableLogging,
switches::kEnablePartialSwap,
switches::kEnableSmoothScrolling,
switches::kEnableThreadedCompositing,
switches::kEnableTouchEvents,
switches::kEnableViewport,
switches::kDisableThreadedCompositing,
switches::kForceCompositingMode,
switches::kGpuStartupDialog,
switches::kLoginProfile,
switches::kScrollPixels,
switches::kNoFirstRun,
switches::kNoSandbox,
switches::kPpapiFlashArgs,
switches::kPpapiFlashInProcess,
switches::kPpapiFlashPath,
switches::kPpapiFlashVersion,
switches::kRendererStartupDialog,
switches::kFlingTapSuppressMaxDown,
switches::kFlingTapSuppressMaxGap,
switches::kTouchDevices,
switches::kTouchOptimizedUI,
::switches::kCompressSystemFeedback,
::switches::kDeviceManagementUrl,
::switches::kDefaultDeviceScaleFactor,
::switches::kDisableAccelerated2dCanvas,
::switches::kDisableAcceleratedPlugins,
::switches::kDisableGpuWatchdog,
::switches::kDisableLoginAnimations,
::switches::kDisableSeccompFilterSandbox,
::switches::kDisableSeccompSandbox,
::switches::kDisableThreadedAnimation,
::switches::kEnableDevicePolicy,
::switches::kEnableGView,
::switches::kEnableLogging,
::switches::kEnablePartialSwap,
::switches::kEnableSmoothScrolling,
::switches::kEnableThreadedCompositing,
::switches::kEnableTouchEvents,
::switches::kEnableViewport,
::switches::kDisableThreadedCompositing,
::switches::kForceCompositingMode,
::switches::kGpuStartupDialog,
::switches::kLoginProfile,
::switches::kScrollPixels,
::switches::kNoFirstRun,
::switches::kNoSandbox,
::switches::kPpapiFlashArgs,
::switches::kPpapiFlashInProcess,
::switches::kPpapiFlashPath,
::switches::kPpapiFlashVersion,
::switches::kRendererStartupDialog,
::switches::kFlingTapSuppressMaxDown,
::switches::kFlingTapSuppressMaxGap,
::switches::kTouchDevices,
::switches::kTouchOptimizedUI,
ash::switches::kAuraLegacyPowerButton,
ash::switches::kAuraNoShadows,
ash::switches::kAuraPanelManager,
ash::switches::kAuraWindowAnimationsDisabled,
switches::kUIEnablePartialSwap,
switches::kUseGL,
switches::kUserDataDir,
::switches::kUIEnablePartialSwap,
::switches::kUseGL,
::switches::kUserDataDir,
#if defined(USE_VIRTUAL_KEYBOARD)
// The virtual keyboard extension (chrome://keyboard) highly relies on
// experimental APIs.
switches::kEnableExperimentalExtensionApis,
::switches::kEnableExperimentalExtensionApis,
#endif
chromeos::switches::kDbusStub,
};
command_line->CopySwitchesFrom(base_command_line,
kForwardSwitches,
arraysize(kForwardSwitches));
command_line->AppendSwitch(switches::kGuestSession);
command_line->AppendSwitch(switches::kIncognito);
command_line->AppendSwitchASCII(switches::kLoggingLevel,
command_line->AppendSwitch(::switches::kGuestSession);
command_line->AppendSwitch(::switches::kIncognito);
command_line->AppendSwitchASCII(::switches::kLoggingLevel,
kGuestModeLoggingLevel);

command_line->AppendSwitchASCII(switches::kLoginUser, kGuestUserName);
command_line->AppendSwitchASCII(::switches::kLoginUser, kGuestUserName);

if (start_url.is_valid())
command_line->AppendArg(start_url.spec());

// Override the value of the homepage that is set in first run mode.
// TODO(altimofeev): extend action of the |kNoFirstRun| to cover this case.
command_line->AppendSwitchASCII(
switches::kHomePage,
::switches::kHomePage,
GURL(chrome::kChromeUINewTabURL).spec());

std::string cmd_line_str = command_line->GetCommandLineString();
// Special workaround for the arguments that should be quoted.
// Copying switches won't be needed when Guest mode won't need restart
// http://crosbug.com/6924
if (base_command_line.HasSwitch(switches::kRegisterPepperPlugins)) {
if (base_command_line.HasSwitch(::switches::kRegisterPepperPlugins)) {
cmd_line_str += base::StringPrintf(
kSwitchFormatString,
switches::kRegisterPepperPlugins,
::switches::kRegisterPepperPlugins,
base_command_line.GetSwitchValueNative(
switches::kRegisterPepperPlugins).c_str());
::switches::kRegisterPepperPlugins).c_str());
}

return cmd_line_str;
Expand Down
2 changes: 2 additions & 0 deletions chromeos/chromeos.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
],
'sources': [
'chromeos_export.h',
'chromeos_switches.cc',
'chromeos_switches.h',
'dbus/blocking_method_caller.cc',
'dbus/blocking_method_caller.h',
'dbus/bluetooth_adapter_client.cc',
Expand Down
14 changes: 14 additions & 0 deletions chromeos/chromeos_switches.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2012 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 "chromeos/chromeos_switches.h"

namespace chromeos {
namespace switches {

// Forces the stub implementation of dbus clients.
const char kDbusStub[] = "dbus-stub";

} // namespace switches
} // namespace chromeos
29 changes: 29 additions & 0 deletions chromeos/chromeos_switches.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2012 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 CHROMEOS_CHROMEOS_SWITCHES_H_
#define CHROMEOS_CHROMEOS_SWITCHES_H_
#pragma once

#include "chromeos/chromeos_export.h"

namespace chromeos {
namespace switches {

// Switches that are used in src/chromeos must go here.
// Other switches that apply just to chromeos code should go here also (along
// with any code that is specific to the chromeos system). ChromeOS specific UI
// should be in src/ash.

// Note: If you add a switch, consider if it needs to be copied to a subsequent
// command line if the process executes a new copy of itself. (For example,
// see chromeos::LoginUtil::GetOffTheRecordCommandLine().)

// Please keep alphabetized.
CHROMEOS_EXPORT extern const char kDbusStub[];

} // namespace switches
} // namespace chromeos

#endif // CHROMEOS_CHROMEOS_SWITCHES_H_
44 changes: 31 additions & 13 deletions chromeos/dbus/dbus_thread_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include "chromeos/dbus/dbus_thread_manager.h"

#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
#include "base/threading/thread.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/bluetooth_adapter_client.h"
#include "chromeos/dbus/bluetooth_device_client.h"
#include "chromeos/dbus/bluetooth_input_client.h"
Expand Down Expand Up @@ -38,8 +40,15 @@ static DBusThreadManager* g_dbus_thread_manager = NULL;
// The DBusThreadManager implementation used in production.
class DBusThreadManagerImpl : public DBusThreadManager {
public:
DBusThreadManagerImpl() {
// Create the D-Bus thread.
explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) {
// If --dbus-stub was requested, pass STUB to specific components;
// Many components like login are not useful with a stub implementation.
DBusClientImplementationType client_type_maybe_stub = client_type;
if (CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDbusStub))
client_type_maybe_stub = STUB_DBUS_CLIENT_IMPLEMENTATION;

// Create the D-Bus thread.
base::Thread::Options thread_options;
thread_options.message_loop_type = MessageLoop::TYPE_IO;
dbus_thread_.reset(new base::Thread("D-Bus thread"));
Expand All @@ -53,11 +62,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
dbus_thread_->message_loop_proxy();
system_bus_ = new dbus::Bus(system_bus_options);

// Determine whether we use stub or real client implementations.
const DBusClientImplementationType client_type =
base::chromeos::IsRunningOnChromeOS() ?
REAL_DBUS_CLIENT_IMPLEMENTATION : STUB_DBUS_CLIENT_IMPLEMENTATION;

// Create the bluetooth clients.
bluetooth_manager_client_.reset(BluetoothManagerClient::Create(
client_type, system_bus_.get()));
Expand Down Expand Up @@ -108,8 +112,8 @@ class DBusThreadManagerImpl : public DBusThreadManager {
introspectable_client_.reset(
IntrospectableClient::Create(client_type, system_bus_.get()));
// Create the power manager client.
power_manager_client_.reset(PowerManagerClient::Create(client_type,
system_bus_.get()));
power_manager_client_.reset(
PowerManagerClient::Create(client_type_maybe_stub, system_bus_.get()));
// Create the session manager client.
session_manager_client_.reset(
SessionManagerClient::Create(client_type, system_bus_.get()));
Expand Down Expand Up @@ -277,8 +281,16 @@ void DBusThreadManager::Initialize() {
LOG(WARNING) << "DBusThreadManager was already initialized";
return;
}
g_dbus_thread_manager = new DBusThreadManagerImpl;
VLOG(1) << "DBusThreadManager initialized";
// Determine whether we use stub or real client implementations.
if (base::chromeos::IsRunningOnChromeOS()) {
g_dbus_thread_manager =
new DBusThreadManagerImpl(REAL_DBUS_CLIENT_IMPLEMENTATION);
VLOG(1) << "DBusThreadManager initialized for ChromeOS";
} else {
g_dbus_thread_manager =
new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION);
VLOG(1) << "DBusThreadManager initialized with Stub";
}
}

// static
Expand All @@ -288,8 +300,14 @@ void DBusThreadManager::InitializeForTesting(
LOG(WARNING) << "DBusThreadManager was already initialized";
return;
}
g_dbus_thread_manager = dbus_thread_manager;
VLOG(1) << "DBusThreadManager initialized";
if (dbus_thread_manager) {
g_dbus_thread_manager = dbus_thread_manager;
VLOG(1) << "DBusThreadManager initialized with test implementation";
} else {
g_dbus_thread_manager =
new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION);
VLOG(1) << "DBusThreadManager initialized with stub implementation";
}
}

// static
Expand Down
2 changes: 1 addition & 1 deletion chromeos/dbus/dbus_thread_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CHROMEOS_EXPORT DBusThreadManager {
// Similar to Initialize(), but can inject an alternative
// DBusThreadManager such as MockDBusThreadManager for testing.
// The injected object will be owned by the internal pointer and deleted
// by Shutdown().
// by Shutdown(). If NULL, a stub implementation will be constructed.
static void InitializeForTesting(DBusThreadManager* dbus_thread_manager);

// Destroys the global instance.
Expand Down

0 comments on commit 66149a5

Please sign in to comment.