diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 15:49:12 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 15:49:12 +0000 |
commit | 9c049d3680865202aec4aa726ad4709e11796360 (patch) | |
tree | e9c40d8cd98481a3fcf3d252a3a7015cd3d17924 /chrome/installer/tools | |
parent | 0ad2f8e394d8e95852646433e106d9db77183de1 (diff) | |
download | chromium_src-9c049d3680865202aec4aa726ad4709e11796360.zip chromium_src-9c049d3680865202aec4aa726ad4709e11796360.tar.gz chromium_src-9c049d3680865202aec4aa726ad4709e11796360.tar.bz2 |
New installation validator machinery to check the machine state. This CL contains the first two parts of the validator:
1. installer::InstallationValidator class, used by setup.exe to confirm that all is well following an installer operation. Violations are logged at ERROR level.
2. validate_installation.exe, used by humans to check the overall state of a machine.
The third part, in which violations fire nonfatal test failures for use in other tests, will follow in a subsequent CL.
BUG=none
TEST=Run validate_installation.exe on machine(s) containing all conceivable permutations of Chrome and Chrome Frame, and see if it reports any violations.
Review URL: http://codereview.chromium.org/6490024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/tools')
-rw-r--r-- | chrome/installer/tools/validate_installation.rc | 65 | ||||
-rw-r--r-- | chrome/installer/tools/validate_installation_main.cc | 189 | ||||
-rw-r--r-- | chrome/installer/tools/validate_installation_resource.h | 18 |
3 files changed, 272 insertions, 0 deletions
diff --git a/chrome/installer/tools/validate_installation.rc b/chrome/installer/tools/validate_installation.rc new file mode 100644 index 0000000..e6d2858 --- /dev/null +++ b/chrome/installer/tools/validate_installation.rc @@ -0,0 +1,65 @@ +// Microsoft Visual C++ generated resource script.
+//
+#include "validate_installation_resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+LANGUAGE 9, 1
+#pragma code_page(1252)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "validate_installation_resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+#include "installer_util_strings.rc"
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/chrome/installer/tools/validate_installation_main.cc b/chrome/installer/tools/validate_installation_main.cc new file mode 100644 index 0000000..5661457 --- /dev/null +++ b/chrome/installer/tools/validate_installation_main.cc @@ -0,0 +1,189 @@ +// Copyright (c) 2011 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. + +// A command-line tool that inspects the current system, displaying information +// about installed products. Violations are dumped to stderr. The process +// exit code is 0 if there are no violations, or 1 otherwise. + +#include <cstdio> +#include <cstdlib> + +#include "base/at_exit.h" +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/path_service.h" +#include "chrome/installer/util/installation_validator.h" + +using installer::InstallationValidator; + +namespace { + +// A helper class that initializes logging and installs a log message handler to +// direct ERROR messages to stderr. Only one instance of this class may be live +// at a time. +class ConsoleLogHelper { + public: + ConsoleLogHelper(); + ~ConsoleLogHelper(); + + private: + static FilePath GetLogFilePath(); + static bool DumpLogMessage(int severity, + const char* file, + int line, + size_t message_start, + const std::string& str); + + static const wchar_t kLogFileName_[]; + static FILE* const kOutputStream_; + static const logging::LogSeverity kViolationSeverity_; + static logging::LogMessageHandlerFunction old_message_handler_; + FilePath log_file_path_; +}; + +// static +const wchar_t ConsoleLogHelper::kLogFileName_[] = L"validate_installation.log"; + +// Dump violations to stderr. +// static +FILE* const ConsoleLogHelper::kOutputStream_ = stderr; + +// InstallationValidator logs all violations at ERROR level. +// static +const logging::LogSeverity + ConsoleLogHelper::kViolationSeverity_ = logging::LOG_ERROR; + +// static +logging::LogMessageHandlerFunction + ConsoleLogHelper::old_message_handler_ = NULL; + +ConsoleLogHelper::ConsoleLogHelper() : log_file_path_(GetLogFilePath()) { + LOG_ASSERT(old_message_handler_ == NULL); + logging::InitLogging( + log_file_path_.value().c_str(), + logging::LOG_ONLY_TO_FILE, + logging::DONT_LOCK_LOG_FILE, + logging::DELETE_OLD_LOG_FILE, + logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); + + old_message_handler_ = logging::GetLogMessageHandler(); + logging::SetLogMessageHandler(&DumpLogMessage); +} + +ConsoleLogHelper::~ConsoleLogHelper() { + logging::SetLogMessageHandler(old_message_handler_); + old_message_handler_ = NULL; + + logging::CloseLogFile(); + + // Delete the log file if it wasn't written to (this is expected). + int64 file_size = 0; + if (file_util::GetFileSize(log_file_path_, &file_size) && file_size == 0) + file_util::Delete(log_file_path_, false); +} + +// Returns the path to the log file to create. The file should be empty at +// process exit since we redirect log messages to stderr. +// static +FilePath ConsoleLogHelper::GetLogFilePath() { + FilePath log_path; + + if (PathService::Get(base::DIR_TEMP, &log_path)) + return log_path.Append(kLogFileName_); + else + return FilePath(kLogFileName_); +} + +// A logging::LogMessageHandlerFunction that sends the body of messages logged +// at the severity of validation violations to stderr. All other messages are +// sent through the default logging pipeline. +// static +bool ConsoleLogHelper::DumpLogMessage(int severity, + const char* file, + int line, + size_t message_start, + const std::string& str) { + if (severity == kViolationSeverity_) { + fprintf(kOutputStream_, "%s", str.c_str() + message_start); + return true; + } + + if (old_message_handler_ != NULL) + return (old_message_handler_)(severity, file, line, message_start, str); + + return false; +} + +const char* LevelToString(bool system_level) { + return system_level ? "System-level" : "User-level"; +} + +std::string InstallationTypeToString( + InstallationValidator::InstallationType type) { + std::string result; + + static const struct ProductData { + int bit; + const char* name; + } kProdBitToName[] = { + { + InstallationValidator::ProductBits::CHROME_SINGLE, + "Chrome" + }, { + InstallationValidator::ProductBits::CHROME_MULTI, + "Chrome (multi)" + }, { + InstallationValidator::ProductBits::CHROME_FRAME_SINGLE, + "Chrome Frame" + }, { + InstallationValidator::ProductBits::CHROME_FRAME_MULTI, + "Chrome Frame (multi)" + }, { + InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE, + "Ready-mode Chrome Frame" + }, + }; + + for (size_t i = 0; i < arraysize(kProdBitToName); ++i) { + const ProductData& product_data = kProdBitToName[i]; + if ((type & product_data.bit) != 0) { + if (!result.empty()) + result.append(", "); + result.append(product_data.name); + } + } + + return result; +} + +} // namespace + +// The main program. +int wmain(int argc, wchar_t *argv[]) { + int result = EXIT_SUCCESS; + base::AtExitManager exit_manager; + + CommandLine::Init(0, NULL); + ConsoleLogHelper log_helper; + + // Check user-level and system-level for products. + for (int i = 0; i < 2; ++i) { + const bool system_level = (i != 0); + InstallationValidator::InstallationType type = + InstallationValidator::NO_PRODUCTS; + bool is_valid = + InstallationValidator::ValidateInstallationType(system_level, &type); + if (type != InstallationValidator::NO_PRODUCTS) { + FILE* stream = is_valid ? stdout : stderr; + fprintf(stream, "%s installations%s: %s\n", LevelToString(system_level), + (is_valid ? "" : " (with errors)"), + InstallationTypeToString(type).c_str()); + } + if (!is_valid) + result = EXIT_FAILURE; + } + + return result; +} diff --git a/chrome/installer/tools/validate_installation_resource.h b/chrome/installer/tools/validate_installation_resource.h new file mode 100644 index 0000000..4998008 --- /dev/null +++ b/chrome/installer/tools/validate_installation_resource.h @@ -0,0 +1,18 @@ +// Copyright (c) 2011 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. + +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by validate_installation.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif |