Skip to content

Commit

Permalink
Move wmi_util out of base and into chrome/installer/util since that's…
Browse files Browse the repository at this point in the history
… the only place where it's used.

TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/3696001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62123 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Oct 10, 2010
1 parent 8bac235 commit 54519a4
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 44 deletions.
2 changes: 0 additions & 2 deletions base/base.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
'watchdog_unittest.cc',
'weak_ptr_unittest.cc',
'win_util_unittest.cc',
'wmi_util_unittest.cc',
'worker_pool_unittest.cc',
],
'include_dirs': [
Expand Down Expand Up @@ -228,7 +227,6 @@
'time_win_unittest.cc',
'trace_event_win_unittest.cc',
'win_util_unittest.cc',
'wmi_util_unittest.cc',
],
}],
],
Expand Down
1 change: 1 addition & 0 deletions chrome/chrome_installer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
'installer/util/run_all_unittests.cc',
'installer/util/set_reg_value_work_item_unittest.cc',
'installer/util/shell_util_unittest.cc',
'installer/util/wmi_unittest.cc',
'installer/util/work_item_list_unittest.cc',
'installer/util/version_unittest.cc',
],
Expand Down
6 changes: 4 additions & 2 deletions chrome/chrome_installer_util.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
'installer/util/delete_reg_value_work_item.h',
'installer/util/delete_tree_work_item.cc',
'installer/util/delete_tree_work_item.h',
'installer/util/google_chrome_distribution.cc',
'installer/util/google_chrome_distribution.h',
'installer/util/google_chrome_sxs_distribution.cc',
'installer/util/google_chrome_sxs_distribution.h',
'installer/util/google_update_constants.cc',
Expand All @@ -49,6 +47,8 @@
'installer/util/util_constants.h',
'installer/util/version.cc',
'installer/util/version.h',
'installer/util/wmi.cc',
'installer/util/wmi.h',
'installer/util/work_item.cc',
'installer/util/work_item.h',
'installer/util/work_item_list.cc',
Expand Down Expand Up @@ -87,6 +87,8 @@
'installer/util/compat_checks.h',
'installer/util/delete_after_reboot_helper.cc',
'installer/util/delete_after_reboot_helper.h',
'installer/util/google_chrome_distribution.cc',
'installer/util/google_chrome_distribution.h',
'installer/util/helper.cc',
'installer/util/helper.h',
'installer/util/html_dialog.h',
Expand Down
4 changes: 2 additions & 2 deletions chrome/installer/util/google_chrome_distribution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win_util.h"
#include "base/wmi_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/json_value_serializer.h"
#include "chrome/common/pref_names.h"
Expand All @@ -33,6 +32,7 @@
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/util_constants.h"
#include "chrome/installer/util/wmi.h"

#include "installer_util_strings.h"

Expand Down Expand Up @@ -373,7 +373,7 @@ void GoogleChromeDistribution::DoPostUninstallOperations(
// process runs inside a Job object controlled by the shell. As long as there
// are processes running, the shell will not close the uninstall applet. WMI
// allows us to escape from the Job object so the applet will close.
WMIProcessUtil::Launch(command, &pid);
installer::WMIProcess::Launch(command, &pid);
}

std::wstring GoogleChromeDistribution::GetAppGuid() {
Expand Down
117 changes: 107 additions & 10 deletions chrome/installer/util/google_chrome_distribution_dummy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,110 @@

#include "base/logging.h"

bool GoogleChromeDistribution::BuildUninstallMetricsString(
DictionaryValue* uninstall_metrics_dict, std::wstring* metrics) {
GoogleChromeDistribution::GoogleChromeDistribution() {
}

void GoogleChromeDistribution::DoPostUninstallOperations(
const installer::Version& version,
const std::wstring& local_data_path,
const std::wstring& distribution_data) {
}

std::wstring GoogleChromeDistribution::GetAppGuid() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetApplicationName() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetAlternateApplicationName() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetBrowserAppId() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetInstallSubDir() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetPublisherName() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetAppDescription() {
NOTREACHED();
return std::wstring();
}

std::string GoogleChromeDistribution::GetSafeBrowsingName() {
NOTREACHED();
return std::string();
}

std::wstring GoogleChromeDistribution::GetStateKey() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetStateMediumKey() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetStatsServerURL() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetDistributionData(RegKey* key) {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetUninstallLinkName() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetUninstallRegPath() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetVersionKey() {
NOTREACHED();
return std::wstring();
}

std::wstring GoogleChromeDistribution::GetEnvVersionKey() {
NOTREACHED();
return std::wstring();
}

void GoogleChromeDistribution::UpdateDiffInstallStatus(bool system_install,
bool incremental_install, installer_util::InstallStatus install_status) {
NOTREACHED();
}

void GoogleChromeDistribution::LaunchUserExperiment(
installer_util::InstallStatus status, const installer::Version& version,
bool system_install) {
NOTREACHED();
}

void GoogleChromeDistribution::InactiveUserToastExperiment(
int flavor,
bool system_install) {
NOTREACHED();
return false;
}

bool GoogleChromeDistribution::ExtractUninstallMetricsFromFile(
Expand All @@ -32,12 +132,9 @@ bool GoogleChromeDistribution::ExtractUninstallMetrics(
return false;
}

void GoogleChromeDistribution::LaunchUserExperiment(
installer_util::InstallStatus status, const installer::Version& version,
bool system_install) {
NOTREACHED();
}
void GoogleChromeDistribution::InactiveUserToastExperiment(int flavor,
bool system_install) {
bool GoogleChromeDistribution::BuildUninstallMetricsString(
DictionaryValue* uninstall_metrics_dict, std::wstring* metrics) {
NOTREACHED();
return false;
}

30 changes: 18 additions & 12 deletions base/wmi_util.cc → chrome/installer/util/wmi.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// 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/installer/util/wmi.h"

#include <windows.h>

#include "base/basictypes.h"
#include "base/scoped_bstr_win.h"
#include "base/scoped_comptr_win.h"

#pragma comment(lib, "wbemuuid.lib")

#include "base/wmi_util.h"
namespace installer {

namespace {

// Simple class to manage the lifetime of a variant.
// TODO(tommi): Replace this for a more useful class.
class VariantHelper : public VARIANT {
Expand All @@ -31,8 +35,8 @@ class VariantHelper : public VARIANT {

} // namespace

bool WMIUtil::CreateLocalConnection(bool set_blanket,
IWbemServices** wmi_services) {
bool WMI::CreateLocalConnection(bool set_blanket,
IWbemServices** wmi_services) {
ScopedComPtr<IWbemLocator> wmi_locator;
HRESULT hr = wmi_locator.CreateInstance(CLSID_WbemLocator, NULL,
CLSCTX_INPROC_SERVER);
Expand Down Expand Up @@ -62,10 +66,10 @@ bool WMIUtil::CreateLocalConnection(bool set_blanket,
return true;
}

bool WMIUtil::CreateClassMethodObject(IWbemServices* wmi_services,
const std::wstring& class_name,
const std::wstring& method_name,
IWbemClassObject** class_instance) {
bool WMI::CreateClassMethodObject(IWbemServices* wmi_services,
const std::wstring& class_name,
const std::wstring& method_name,
IWbemClassObject** class_instance) {
// We attempt to instantiate a COM object that represents a WMI object plus
// a method rolled into one entity.
ScopedBstr b_class_name(class_name.c_str());
Expand Down Expand Up @@ -103,16 +107,16 @@ bool SetParameter(IWbemClassObject* class_method,
// CIM class is documented here:
// http://msdn2.microsoft.com/en-us/library/aa389388(VS.85).aspx

bool WMIProcessUtil::Launch(const std::wstring& command_line, int* process_id) {
bool WMIProcess::Launch(const std::wstring& command_line, int* process_id) {
ScopedComPtr<IWbemServices> wmi_local;
if (!WMIUtil::CreateLocalConnection(true, wmi_local.Receive()))
if (!WMI::CreateLocalConnection(true, wmi_local.Receive()))
return false;

const wchar_t class_name[] = L"Win32_Process";
const wchar_t method_name[] = L"Create";
ScopedComPtr<IWbemClassObject> process_create;
if (!WMIUtil::CreateClassMethodObject(wmi_local, class_name, method_name,
process_create.Receive()))
if (!WMI::CreateClassMethodObject(wmi_local, class_name, method_name,
process_create.Receive()))
return false;

VariantHelper b_command_line(VT_BSTR);
Expand Down Expand Up @@ -144,3 +148,5 @@ bool WMIProcessUtil::Launch(const std::wstring& command_line, int* process_id) {

return true;
}

} // namespace installer
16 changes: 10 additions & 6 deletions base/wmi_util.h → chrome/installer/util/wmi.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// 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.

Expand All @@ -17,14 +17,16 @@
// For more information about WMI programming:
// http://msdn2.microsoft.com/en-us/library/aa384642(VS.85).aspx

#ifndef BASE_WMI_UTIL_H__
#define BASE_WMI_UTIL_H__
#ifndef CHROME_INSTALLER_UTIL_WMI_H_
#define CHROME_INSTALLER_UTIL_WMI_H_
#pragma once

#include <string>
#include <wbemidl.h>

class WMIUtil {
namespace installer {

class WMI {
public:
// Creates an instance of the WMI service connected to the local computer and
// returns its COM interface. If 'set-blanket' is set to true, the basic COM
Expand Down Expand Up @@ -57,7 +59,7 @@ class WMIUtil {

// This class contains functionality of the WMI class 'Win32_Process'
// more info: http://msdn2.microsoft.com/en-us/library/aa394372(VS.85).aspx
class WMIProcessUtil {
class WMIProcess {
public:
// Creates a new process from 'command_line'. The advantage over CreateProcess
// is that it allows you to always break out from a Job object that the caller
Expand All @@ -71,4 +73,6 @@ class WMIProcessUtil {
static bool Launch(const std::wstring& command_line, int* process_id);
};

#endif // BASE_WMI_UTIL_H__
} // namespace installer

#endif // CHROME_INSTALLER_UTIL_WMI_H_
24 changes: 14 additions & 10 deletions base/wmi_util_unittest.cc → chrome/installer/util/wmi_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,38 @@

#include <windows.h>

#include "chrome/installer/util/wmi.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "base/wmi_util.h"

TEST(WMIUtilTest, TestLocalConnectionSecurityBlanket) {
namespace installer {

TEST(WMITest, TestLocalConnectionSecurityBlanket) {
::CoInitialize(NULL);
IWbemServices* services = NULL;
EXPECT_TRUE(WMIUtil::CreateLocalConnection(true, &services));
EXPECT_TRUE(WMI::CreateLocalConnection(true, &services));
ASSERT_TRUE(NULL != services);
ULONG refs = services->Release();
EXPECT_EQ(refs, 0);
::CoUninitialize();
}

TEST(WMIUtilTest, TestLocalConnectionNoSecurityBlanket) {
TEST(WMITest, TestLocalConnectionNoSecurityBlanket) {
::CoInitialize(NULL);
IWbemServices* services = NULL;
EXPECT_TRUE(WMIUtil::CreateLocalConnection(false, &services));
EXPECT_TRUE(WMI::CreateLocalConnection(false, &services));
ASSERT_TRUE(NULL != services);
ULONG refs = services->Release();
EXPECT_EQ(refs, 0);
::CoUninitialize();
}

TEST(WMIUtilTest, TestCreateClassMethod) {
TEST(WMITest, TestCreateClassMethod) {
::CoInitialize(NULL);
IWbemServices* wmi_services = NULL;
EXPECT_TRUE(WMIUtil::CreateLocalConnection(true, &wmi_services));
EXPECT_TRUE(WMI::CreateLocalConnection(true, &wmi_services));
ASSERT_TRUE(NULL != wmi_services);
IWbemClassObject* class_method = NULL;
EXPECT_TRUE(WMIUtil::CreateClassMethodObject(wmi_services,
EXPECT_TRUE(WMI::CreateClassMethodObject(wmi_services,
L"Win32_ShortcutFile",
L"Rename", &class_method));
ASSERT_TRUE(NULL != class_method);
Expand All @@ -45,11 +47,13 @@ TEST(WMIUtilTest, TestCreateClassMethod) {
}

// Creates an instance of cmd which executes 'echo' and exits immediately.
TEST(WMIUtilTest, TestLaunchProcess) {
TEST(WMITest, TestLaunchProcess) {
::CoInitialize(NULL);
int pid = 0;
bool result = WMIProcessUtil::Launch(L"cmd.exe /c echo excelent!", &pid);
bool result = WMIProcess::Launch(L"cmd.exe /c echo excelent!", &pid);
EXPECT_TRUE(result);
EXPECT_GT(pid, 0);
::CoUninitialize();
}

} // namespace installer

0 comments on commit 54519a4

Please sign in to comment.