diff options
author | erikchen <erikchen@chromium.org> | 2016-03-01 13:38:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-01 21:40:13 +0000 |
commit | 83e8f856e711121c3b196726877450fbbbec0761 (patch) | |
tree | 4c293003896828932f8274ac7305da7187fa7047 /base/mac/mac_logging.mm | |
parent | 1ffb363a1e011a850a4fbaa1f06a2cd318955a9b (diff) | |
download | chromium_src-83e8f856e711121c3b196726877450fbbbec0761.zip chromium_src-83e8f856e711121c3b196726877450fbbbec0761.tar.gz chromium_src-83e8f856e711121c3b196726877450fbbbec0761.tar.bz2 |
Use a non-deprecated method to get a string from an OSStatus error.
The functions GetMacOSStatusErrorString() and GetMacOSStatusCommentString() have
been deprecated since OSX 10.8. The official replacement is NSError.
BUG=547071
Review URL: https://codereview.chromium.org/1753523002
Cr-Commit-Position: refs/heads/master@{#378564}
Diffstat (limited to 'base/mac/mac_logging.mm')
-rw-r--r-- | base/mac/mac_logging.mm | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/base/mac/mac_logging.mm b/base/mac/mac_logging.mm new file mode 100644 index 0000000..381ad30 --- /dev/null +++ b/base/mac/mac_logging.mm @@ -0,0 +1,47 @@ +// 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/mac/mac_logging.h" + +#import <Foundation/Foundation.h> + +#include <iomanip> + +#include "build/build_config.h" + +#if !defined(OS_IOS) +#include <CoreServices/CoreServices.h> +#endif + +namespace logging { + +std::string DescriptionFromOSStatus(OSStatus err) { + NSError* error = + [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; + return error.description.UTF8String; +} + +OSStatusLogMessage::OSStatusLogMessage(const char* file_path, + int line, + LogSeverity severity, + OSStatus status) + : LogMessage(file_path, line, severity), + status_(status) { +} + +OSStatusLogMessage::~OSStatusLogMessage() { +#if defined(OS_IOS) + // TODO(ios): Consider using NSError with NSOSStatusErrorDomain to try to + // get a description of the failure. + stream() << ": " << status_; +#else + stream() << ": " + << DescriptionFromOSStatus(status_) + << " (" + << status_ + << ")"; +#endif +} + +} // namespace logging |