Remove various unused files - base/unguessable_token.* - base/value_conversions.* - base/version.* - base/syslog_logging.* Change-Id: I8fbb339d9c22b4efa1c7565706adc16d435418a4 Reviewed-on: https://gn-review.googlesource.com/1500 Reviewed-by: Brett Wilson <brettw@chromium.org> Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/syslog_logging.cc b/base/syslog_logging.cc deleted file mode 100644 index 03c2b5e..0000000 --- a/base/syslog_logging.cc +++ /dev/null
@@ -1,118 +0,0 @@ -// Copyright 2016 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 "base/syslog_logging.h" - -#if defined(OS_WIN) -#include <windows.h> -#include "base/bind.h" -#include "base/callback_helpers.h" -#include "base/debug/stack_trace.h" -#elif defined(OS_LINUX) -// <syslog.h> defines a LOG_WARNING macro that could conflict with -// base::LOG_WARNING. -#include <syslog.h> -#undef LOG_WARNING -#endif - -#include <ostream> -#include <string> - -namespace logging { - -#if defined(OS_WIN) - -namespace { - -std::string* g_event_source_name = nullptr; -uint16_t g_category = 0; -uint32_t g_event_id = 0; - -} // namespace - -void SetEventSource(const std::string& name, - uint16_t category, - uint32_t event_id) { - DCHECK_EQ(nullptr, g_event_source_name); - g_event_source_name = new std::string(name); - g_category = category; - g_event_id = event_id; -} - -#endif // defined(OS_WIN) - -EventLogMessage::EventLogMessage(const char* file, - int line, - LogSeverity severity) - : log_message_(file, line, severity) { -} - -EventLogMessage::~EventLogMessage() { -#if defined(OS_WIN) - // If g_event_source_name is nullptr (which it is per default) SYSLOG will - // degrade gracefully to regular LOG. If you see this happening most probably - // you are using SYSLOG before you called SetEventSourceName. - if (g_event_source_name == nullptr) - return; - - HANDLE event_log_handle = - RegisterEventSourceA(nullptr, g_event_source_name->c_str()); - if (event_log_handle == nullptr) { - stream() << " !!NOT ADDED TO EVENTLOG!!"; - return; - } - - base::ScopedClosureRunner auto_deregister( - base::Bind(base::IgnoreResult(&DeregisterEventSource), event_log_handle)); - std::string message(log_message_.str()); - WORD log_type = EVENTLOG_ERROR_TYPE; - switch (log_message_.severity()) { - case LOG_INFO: - log_type = EVENTLOG_INFORMATION_TYPE; - break; - case LOG_WARNING: - log_type = EVENTLOG_WARNING_TYPE; - break; - case LOG_ERROR: - case LOG_FATAL: - // The price of getting the stack trace is not worth the hassle for - // non-error conditions. - base::debug::StackTrace trace; - message.append(trace.ToString()); - log_type = EVENTLOG_ERROR_TYPE; - break; - } - LPCSTR strings[1] = {message.data()}; - if (!ReportEventA(event_log_handle, log_type, g_category, g_event_id, nullptr, - 1, 0, strings, nullptr)) { - stream() << " !!NOT ADDED TO EVENTLOG!!"; - } -#elif defined(OS_LINUX) - const char kEventSource[] = "chrome"; - openlog(kEventSource, LOG_NOWAIT | LOG_PID, LOG_USER); - // We can't use the defined names for the logging severity from syslog.h - // because they collide with the names of our own severity levels. Therefore - // we use the actual values which of course do not match ours. - // See sys/syslog.h for reference. - int priority = 3; - switch (log_message_.severity()) { - case LOG_INFO: - priority = 6; - break; - case LOG_WARNING: - priority = 4; - break; - case LOG_ERROR: - priority = 3; - break; - case LOG_FATAL: - priority = 2; - break; - } - syslog(priority, "%s", log_message_.str().c_str()); - closelog(); -#endif // defined(OS_WIN) -} - -} // namespace logging
diff --git a/base/syslog_logging.h b/base/syslog_logging.h deleted file mode 100644 index 2c2ff55..0000000 --- a/base/syslog_logging.h +++ /dev/null
@@ -1,50 +0,0 @@ -// Copyright 2016 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 BASE_SYSLOG_LOGGING_H_ -#define BASE_SYSLOG_LOGGING_H_ - -#include <iosfwd> - -#include "base/logging.h" -#include "build_config.h" - -namespace logging { - -// Keep in mind that the syslog is always active regardless of the logging level -// and applied flags. Use only for important information that a system -// administrator might need to maintain the browser installation. -#define SYSLOG_STREAM(severity) \ - COMPACT_GOOGLE_LOG_EX_ ## severity(EventLogMessage).stream() -#define SYSLOG(severity) \ - SYSLOG_STREAM(severity) - -#if defined(OS_WIN) -// Sets the name, category and event id of the event source for logging to the -// Windows Event Log. Call this function once before using the SYSLOG macro or -// otherwise it will behave as a regular LOG macro. -void BASE_EXPORT SetEventSource(const std::string& name, - uint16_t category, - uint32_t event_id); -#endif // defined(OS_WIN) - -// Creates a formatted message on the system event log. That would be the -// Application Event log on Windows and the messages log file on POSIX systems. -class BASE_EXPORT EventLogMessage { - public: - EventLogMessage(const char* file, int line, LogSeverity severity); - - ~EventLogMessage(); - - std::ostream& stream() { return log_message_.stream(); } - - private: - LogMessage log_message_; - - DISALLOW_COPY_AND_ASSIGN(EventLogMessage); -}; - -} // namespace logging - -#endif // BASE_SYSLOG_LOGGING_H_
diff --git a/base/unguessable_token.cc b/base/unguessable_token.cc deleted file mode 100644 index 0d8aad3..0000000 --- a/base/unguessable_token.cc +++ /dev/null
@@ -1,41 +0,0 @@ -// Copyright 2016 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 "base/unguessable_token.h" - -#include "base/format_macros.h" -#include "base/rand_util.h" -#include "base/strings/stringprintf.h" - -namespace base { - -UnguessableToken::UnguessableToken(uint64_t high, uint64_t low) - : high_(high), low_(low) {} - -std::string UnguessableToken::ToString() const { - return base::StringPrintf("%016" PRIX64 "%016" PRIX64, high_, low_); -} - -// static -UnguessableToken UnguessableToken::Create() { - UnguessableToken token; - // Use base::RandBytes instead of crypto::RandBytes, because crypto calls the - // base version directly, and to prevent the dependency from base/ to crypto/. - base::RandBytes(&token, sizeof(token)); - return token; -} - -// static -UnguessableToken UnguessableToken::Deserialize(uint64_t high, uint64_t low) { - // Receiving a zeroed out UnguessableToken from another process means that it - // was never initialized via Create(). Treat this case as a security issue. - DCHECK(!(high == 0 && low == 0)); - return UnguessableToken(high, low); -} - -std::ostream& operator<<(std::ostream& out, const UnguessableToken& token) { - return out << "(" << token.ToString() << ")"; -} - -} // namespace base
diff --git a/base/unguessable_token.h b/base/unguessable_token.h deleted file mode 100644 index 6858e22..0000000 --- a/base/unguessable_token.h +++ /dev/null
@@ -1,110 +0,0 @@ -// Copyright 2016 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 BASE_UNGUESSABLE_TOKEN_H_ -#define BASE_UNGUESSABLE_TOKEN_H_ - -#include <stdint.h> -#include <string.h> -#include <iosfwd> -#include <tuple> - -#include "base/base_export.h" -#include "base/hash.h" -#include "base/logging.h" - -namespace base { - -struct UnguessableTokenHash; - -// A UnguessableToken is an 128-bit token generated from a cryptographically -// strong random source. It can be used as part of a larger aggregate type, -// or as an ID in and of itself. -// -// UnguessableToken can be used to implement "Capability-Based Security". -// In other words, UnguessableToken can be used when the resource associated -// with the ID needs to be protected against manipulation by other untrusted -// agents in the system, and there is no other convenient way to verify the -// authority of the agent to do so (because the resource is part of a table -// shared across processes, for instance). In such a scheme, knowledge of the -// token value in and of itself is sufficient proof of authority to carry out -// an operation against the associated resource. -// -// Use Create() for creating new UnguessableTokens. -// -// NOTE: It is illegal to send empty UnguessableTokens across processes, and -// sending/receiving empty tokens should be treated as a security issue. -// If there is a valid scenario for sending "no token" across processes, -// base::Optional should be used instead of an empty token. -class BASE_EXPORT UnguessableToken { - public: - // Create a unique UnguessableToken. - static UnguessableToken Create(); - - // Return a UnguessableToken built from the high/low bytes provided. - // It should only be used in deserialization scenarios. - // - // NOTE: If the deserialized token is empty, it means that it was never - // initialized via Create(). This is a security issue, and should be handled. - static UnguessableToken Deserialize(uint64_t high, uint64_t low); - - // Creates an empty UnguessableToken. - // Assign to it with Create() before using it. - constexpr UnguessableToken() = default; - - // NOTE: Serializing an empty UnguessableToken is an illegal operation. - uint64_t GetHighForSerialization() const { - DCHECK(!is_empty()); - return high_; - } - - // NOTE: Serializing an empty UnguessableToken is an illegal operation. - uint64_t GetLowForSerialization() const { - DCHECK(!is_empty()); - return low_; - } - - bool is_empty() const { return high_ == 0 && low_ == 0; } - - // Hex representation of the unguessable token. - std::string ToString() const; - - explicit operator bool() const { return !is_empty(); } - - bool operator<(const UnguessableToken& other) const { - return std::tie(high_, low_) < std::tie(other.high_, other.low_); - } - - bool operator==(const UnguessableToken& other) const { - return high_ == other.high_ && low_ == other.low_; - } - - bool operator!=(const UnguessableToken& other) const { - return !(*this == other); - } - - private: - friend struct UnguessableTokenHash; - UnguessableToken(uint64_t high, uint64_t low); - - // Note: Two uint64_t are used instead of uint8_t[16], in order to have a - // simpler ToString() and is_empty(). - uint64_t high_ = 0; - uint64_t low_ = 0; -}; - -BASE_EXPORT std::ostream& operator<<(std::ostream& out, - const UnguessableToken& token); - -// For use in std::unordered_map. -struct UnguessableTokenHash { - size_t operator()(const base::UnguessableToken& token) const { - DCHECK(token); - return base::HashInts64(token.high_, token.low_); - } -}; - -} // namespace base - -#endif // BASE_UNGUESSABLE_TOKEN_H_
diff --git a/base/value_conversions.cc b/base/value_conversions.cc deleted file mode 100644 index 7e3fd94..0000000 --- a/base/value_conversions.cc +++ /dev/null
@@ -1,99 +0,0 @@ -// 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 "base/value_conversions.h" - -#include <stdint.h> - -#include <algorithm> -#include <string> -#include <vector> - -#include "base/files/file_path.h" -#include "base/memory/ptr_util.h" -#include "base/strings/string_number_conversions.h" -#include "base/time/time.h" -#include "base/unguessable_token.h" -#include "base/values.h" - -namespace base { -namespace { -// Helper for serialize/deserialize UnguessableToken. -union UnguessableTokenRepresentation { - struct Field { - uint64_t high; - uint64_t low; - } field; - - uint8_t buffer[sizeof(Field)]; -}; -} // namespace - -// |Value| internally stores strings in UTF-8, so we have to convert from the -// system native code to UTF-8 and back. -std::unique_ptr<Value> CreateFilePathValue(const FilePath& in_value) { - return std::make_unique<Value>(in_value.AsUTF8Unsafe()); -} - -bool GetValueAsFilePath(const Value& value, FilePath* file_path) { - std::string str; - if (!value.GetAsString(&str)) - return false; - if (file_path) - *file_path = FilePath::FromUTF8Unsafe(str); - return true; -} - -// |Value| does not support 64-bit integers, and doubles do not have enough -// precision, so we store the 64-bit time value as a string instead. -std::unique_ptr<Value> CreateTimeDeltaValue(const TimeDelta& time) { - std::string string_value = base::Int64ToString(time.ToInternalValue()); - return std::make_unique<Value>(string_value); -} - -bool GetValueAsTimeDelta(const Value& value, TimeDelta* time) { - std::string str; - int64_t int_value; - if (!value.GetAsString(&str) || !base::StringToInt64(str, &int_value)) - return false; - if (time) - *time = TimeDelta::FromInternalValue(int_value); - return true; -} - -std::unique_ptr<Value> CreateUnguessableTokenValue( - const UnguessableToken& token) { - UnguessableTokenRepresentation representation; - representation.field.high = token.GetHighForSerialization(); - representation.field.low = token.GetLowForSerialization(); - - return std::make_unique<Value>( - HexEncode(representation.buffer, sizeof(representation.buffer))); -} - -bool GetValueAsUnguessableToken(const Value& value, UnguessableToken* token) { - if (!value.is_string()) { - return false; - } - - // TODO(dcheng|yucliu): Make a function that accepts non vector variant and - // reads a fixed number of bytes. - std::vector<uint8_t> high_low_bytes; - if (!HexStringToBytes(value.GetString(), &high_low_bytes)) { - return false; - } - - UnguessableTokenRepresentation representation; - if (high_low_bytes.size() != sizeof(representation.buffer)) { - return false; - } - - std::copy(high_low_bytes.begin(), high_low_bytes.end(), - std::begin(representation.buffer)); - *token = UnguessableToken::Deserialize(representation.field.high, - representation.field.low); - return true; -} - -} // namespace base
diff --git a/base/value_conversions.h b/base/value_conversions.h deleted file mode 100644 index bd095cd..0000000 --- a/base/value_conversions.h +++ /dev/null
@@ -1,35 +0,0 @@ -// 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 BASE_VALUE_CONVERSIONS_H_ -#define BASE_VALUE_CONVERSIONS_H_ - -// This file contains methods to convert things to a |Value| and back. - -#include <memory> -#include "base/base_export.h" - -namespace base { - -class FilePath; -class TimeDelta; -class UnguessableToken; -class Value; - -// The caller takes ownership of the returned value. -BASE_EXPORT std::unique_ptr<Value> CreateFilePathValue( - const FilePath& in_value); -BASE_EXPORT bool GetValueAsFilePath(const Value& value, FilePath* file_path); - -BASE_EXPORT std::unique_ptr<Value> CreateTimeDeltaValue(const TimeDelta& time); -BASE_EXPORT bool GetValueAsTimeDelta(const Value& value, TimeDelta* time); - -BASE_EXPORT std::unique_ptr<Value> CreateUnguessableTokenValue( - const UnguessableToken& token); -BASE_EXPORT bool GetValueAsUnguessableToken(const Value& value, - UnguessableToken* token); - -} // namespace base - -#endif // BASE_VALUE_CONVERSIONS_H_
diff --git a/base/version.cc b/base/version.cc deleted file mode 100644 index 3a54607..0000000 --- a/base/version.cc +++ /dev/null
@@ -1,194 +0,0 @@ -// 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 "base/version.h" - -#include <stddef.h> - -#include <algorithm> - -#include "base/logging.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" - -namespace base { - -namespace { - -// Parses the |numbers| vector representing the different numbers -// inside the version string and constructs a vector of valid integers. It stops -// when it reaches an invalid item (including the wildcard character). |parsed| -// is the resulting integer vector. Function returns true if all numbers were -// parsed successfully, false otherwise. -bool ParseVersionNumbers(const std::string& version_str, - std::vector<uint32_t>* parsed) { - std::vector<StringPiece> numbers = - SplitStringPiece(version_str, ".", KEEP_WHITESPACE, SPLIT_WANT_ALL); - if (numbers.empty()) - return false; - - for (auto it = numbers.begin(); it != numbers.end(); ++it) { - if (StartsWith(*it, "+", CompareCase::SENSITIVE)) - return false; - - unsigned int num; - if (!StringToUint(*it, &num)) - return false; - - // This throws out leading zeros for the first item only. - if (it == numbers.begin() && UintToString(num) != *it) - return false; - - // StringToUint returns unsigned int but Version fields are uint32_t. - static_assert(sizeof (uint32_t) == sizeof (unsigned int), - "uint32_t must be same as unsigned int"); - parsed->push_back(num); - } - return true; -} - -// Compares version components in |components1| with components in -// |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to, -// or greater than |components2|, respectively. -int CompareVersionComponents(const std::vector<uint32_t>& components1, - const std::vector<uint32_t>& components2) { - const size_t count = std::min(components1.size(), components2.size()); - for (size_t i = 0; i < count; ++i) { - if (components1[i] > components2[i]) - return 1; - if (components1[i] < components2[i]) - return -1; - } - if (components1.size() > components2.size()) { - for (size_t i = count; i < components1.size(); ++i) { - if (components1[i] > 0) - return 1; - } - } else if (components1.size() < components2.size()) { - for (size_t i = count; i < components2.size(); ++i) { - if (components2[i] > 0) - return -1; - } - } - return 0; -} - -} // namespace - -Version::Version() = default; - -Version::Version(const Version& other) = default; - -Version::~Version() = default; - -Version::Version(const std::string& version_str) { - std::vector<uint32_t> parsed; - if (!ParseVersionNumbers(version_str, &parsed)) - return; - - components_.swap(parsed); -} - -Version::Version(std::vector<uint32_t> components) - : components_(std::move(components)) {} - -bool Version::IsValid() const { - return (!components_.empty()); -} - -// static -bool Version::IsValidWildcardString(const std::string& wildcard_string) { - std::string version_string = wildcard_string; - if (EndsWith(version_string, ".*", CompareCase::SENSITIVE)) - version_string.resize(version_string.size() - 2); - - Version version(version_string); - return version.IsValid(); -} - -int Version::CompareToWildcardString(const std::string& wildcard_string) const { - DCHECK(IsValid()); - DCHECK(Version::IsValidWildcardString(wildcard_string)); - - // Default behavior if the string doesn't end with a wildcard. - if (!EndsWith(wildcard_string, ".*", CompareCase::SENSITIVE)) { - Version version(wildcard_string); - DCHECK(version.IsValid()); - return CompareTo(version); - } - - std::vector<uint32_t> parsed; - const bool success = ParseVersionNumbers( - wildcard_string.substr(0, wildcard_string.length() - 2), &parsed); - DCHECK(success); - const int comparison = CompareVersionComponents(components_, parsed); - // If the version is smaller than the wildcard version's |parsed| vector, - // then the wildcard has no effect (e.g. comparing 1.2.3 and 1.3.*) and the - // version is still smaller. Same logic for equality (e.g. comparing 1.2.2 to - // 1.2.2.* is 0 regardless of the wildcard). Under this logic, - // 1.2.0.0.0.0 compared to 1.2.* is 0. - if (comparison == -1 || comparison == 0) - return comparison; - - // Catch the case where the digits of |parsed| are found in |components_|, - // which means that the two are equal since |parsed| has a trailing "*". - // (e.g. 1.2.3 vs. 1.2.* will return 0). All other cases return 1 since - // components is greater (e.g. 3.2.3 vs 1.*). - DCHECK_GT(parsed.size(), 0UL); - const size_t min_num_comp = std::min(components_.size(), parsed.size()); - for (size_t i = 0; i < min_num_comp; ++i) { - if (components_[i] != parsed[i]) - return 1; - } - return 0; -} - -int Version::CompareTo(const Version& other) const { - DCHECK(IsValid()); - DCHECK(other.IsValid()); - return CompareVersionComponents(components_, other.components_); -} - -const std::string Version::GetString() const { - DCHECK(IsValid()); - std::string version_str; - size_t count = components_.size(); - for (size_t i = 0; i < count - 1; ++i) { - version_str.append(UintToString(components_[i])); - version_str.append("."); - } - version_str.append(UintToString(components_[count - 1])); - return version_str; -} - -bool operator==(const Version& v1, const Version& v2) { - return v1.CompareTo(v2) == 0; -} - -bool operator!=(const Version& v1, const Version& v2) { - return !(v1 == v2); -} - -bool operator<(const Version& v1, const Version& v2) { - return v1.CompareTo(v2) < 0; -} - -bool operator<=(const Version& v1, const Version& v2) { - return v1.CompareTo(v2) <= 0; -} - -bool operator>(const Version& v1, const Version& v2) { - return v1.CompareTo(v2) > 0; -} - -bool operator>=(const Version& v1, const Version& v2) { - return v1.CompareTo(v2) >= 0; -} - -std::ostream& operator<<(std::ostream& stream, const Version& v) { - return stream << v.GetString(); -} - -} // namespace base
diff --git a/base/version.h b/base/version.h deleted file mode 100644 index b3a0956..0000000 --- a/base/version.h +++ /dev/null
@@ -1,76 +0,0 @@ -// 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 BASE_VERSION_H_ -#define BASE_VERSION_H_ - -#include <stdint.h> - -#include <iosfwd> -#include <string> -#include <vector> - -#include "base/base_export.h" - -namespace base { - -// Version represents a dotted version number, like "1.2.3.4", supporting -// parsing and comparison. -class BASE_EXPORT Version { - public: - // The only thing you can legally do to a default constructed - // Version object is assign to it. - Version(); - - Version(const Version& other); - - // Initializes from a decimal dotted version number, like "0.1.1". - // Each component is limited to a uint16_t. Call IsValid() to learn - // the outcome. - explicit Version(const std::string& version_str); - - // Initializes from a vector of components, like {1, 2, 3, 4}. Call IsValid() - // to learn the outcome. - explicit Version(std::vector<uint32_t> components); - - ~Version(); - - // Returns true if the object contains a valid version number. - bool IsValid() const; - - // Returns true if the version wildcard string is valid. The version wildcard - // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" - // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard - // Version behavior (IsValid) if no wildcard is present. - static bool IsValidWildcardString(const std::string& wildcard_string); - - // Returns -1, 0, 1 for <, ==, >. - int CompareTo(const Version& other) const; - - // Given a valid version object, compare if a |wildcard_string| results in a - // newer version. This function will default to CompareTo if the string does - // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be - // true before using this function. - int CompareToWildcardString(const std::string& wildcard_string) const; - - // Return the string representation of this version. - const std::string GetString() const; - - const std::vector<uint32_t>& components() const { return components_; } - - private: - std::vector<uint32_t> components_; -}; - -BASE_EXPORT bool operator==(const Version& v1, const Version& v2); -BASE_EXPORT bool operator!=(const Version& v1, const Version& v2); -BASE_EXPORT bool operator<(const Version& v1, const Version& v2); -BASE_EXPORT bool operator<=(const Version& v1, const Version& v2); -BASE_EXPORT bool operator>(const Version& v1, const Version& v2); -BASE_EXPORT bool operator>=(const Version& v1, const Version& v2); -BASE_EXPORT std::ostream& operator<<(std::ostream& stream, const Version& v); - -} // namespace base - -#endif // BASE_VERSION_H_
diff --git a/build/gen.py b/build/gen.py index 95f8fe1..9e2ab8f 100755 --- a/build/gen.py +++ b/build/gen.py
@@ -342,7 +342,6 @@ 'base/time/time.cc', 'base/timer/elapsed_timer.cc', 'base/timer/timer.cc', - 'base/unguessable_token.cc', 'base/value_iterators.cc', 'base/values.cc', 'base/vlog.cc',