diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-10 20:14:48 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-10 20:14:48 +0000 |
commit | 54519a4e3eb314153b0cdf9ae96a2fbaffb7a217 (patch) | |
tree | 755447f058c35530a0ed75c2b2f427d1653d4319 | |
parent | 8bac235e7c08c21851934cf771d7d473b3beca4d (diff) | |
download | chromium_src-54519a4e3eb314153b0cdf9ae96a2fbaffb7a217.zip chromium_src-54519a4e3eb314153b0cdf9ae96a2fbaffb7a217.tar.gz chromium_src-54519a4e3eb314153b0cdf9ae96a2fbaffb7a217.tar.bz2 |
Move wmi_util out of base and into chrome/installer/util since that's 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
-rw-r--r-- | base/base.gyp | 2 | ||||
-rw-r--r-- | chrome/chrome_installer.gypi | 1 | ||||
-rw-r--r-- | chrome/chrome_installer_util.gypi | 6 | ||||
-rw-r--r-- | chrome/installer/util/google_chrome_distribution.cc | 4 | ||||
-rw-r--r-- | chrome/installer/util/google_chrome_distribution_dummy.cc | 117 | ||||
-rw-r--r-- | chrome/installer/util/wmi.cc (renamed from base/wmi_util.cc) | 30 | ||||
-rw-r--r-- | chrome/installer/util/wmi.h (renamed from base/wmi_util.h) | 16 | ||||
-rw-r--r-- | chrome/installer/util/wmi_unittest.cc (renamed from base/wmi_util_unittest.cc) | 24 |
8 files changed, 156 insertions, 44 deletions
diff --git a/base/base.gyp b/base/base.gyp index 10a9e61..2f541ee 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -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': [ @@ -228,7 +227,6 @@ 'time_win_unittest.cc', 'trace_event_win_unittest.cc', 'win_util_unittest.cc', - 'wmi_util_unittest.cc', ], }], ], diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi index dfe89a7..e4b515c 100644 --- a/chrome/chrome_installer.gypi +++ b/chrome/chrome_installer.gypi @@ -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', ], diff --git a/chrome/chrome_installer_util.gypi b/chrome/chrome_installer_util.gypi index 02b9377..721d62b 100644 --- a/chrome/chrome_installer_util.gypi +++ b/chrome/chrome_installer_util.gypi @@ -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', @@ -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', @@ -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', diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc index bb9a5a6..9715e71 100644 --- a/chrome/installer/util/google_chrome_distribution.cc +++ b/chrome/installer/util/google_chrome_distribution.cc @@ -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" @@ -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" @@ -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() { diff --git a/chrome/installer/util/google_chrome_distribution_dummy.cc b/chrome/installer/util/google_chrome_distribution_dummy.cc index 0f13891..b2cafe9 100644 --- a/chrome/installer/util/google_chrome_distribution_dummy.cc +++ b/chrome/installer/util/google_chrome_distribution_dummy.cc @@ -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( @@ -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; } + diff --git a/base/wmi_util.cc b/chrome/installer/util/wmi.cc index 8b56a86..957ec99 100644 --- a/base/wmi_util.cc +++ b/chrome/installer/util/wmi.cc @@ -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 { @@ -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); @@ -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()); @@ -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); @@ -144,3 +148,5 @@ bool WMIProcessUtil::Launch(const std::wstring& command_line, int* process_id) { return true; } + +} // namespace installer diff --git a/base/wmi_util.h b/chrome/installer/util/wmi.h index 7d4fed0..5d0a1a9 100644 --- a/base/wmi_util.h +++ b/chrome/installer/util/wmi.h @@ -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. @@ -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 @@ -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 @@ -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_ diff --git a/base/wmi_util_unittest.cc b/chrome/installer/util/wmi_unittest.cc index 7898288..591f688 100644 --- a/base/wmi_util_unittest.cc +++ b/chrome/installer/util/wmi_unittest.cc @@ -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); @@ -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 |