Skip to content

Commit 280c58a

Browse files
Avi DrissmanChromium LUCI CQ
authored andcommitted
Move OSStatus logging to base/apple
Bug: 1444927 Change-Id: I7e2df7c3e235711071050f1663127eb12439535c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4780399 Reviewed-by: Mark Mentovai <[email protected]> Auto-Submit: Avi Drissman <[email protected]> Owners-Override: Avi Drissman <[email protected]> Commit-Queue: Avi Drissman <[email protected]> Cr-Commit-Position: refs/heads/main@{#1184197}
1 parent 5baac5c commit 280c58a

File tree

51 files changed

+84
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+84
-100
lines changed

base/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,8 @@ component("base") {
19531953
"apple/call_with_eh_frame_asm.S",
19541954
"apple/dispatch_source_mach.cc",
19551955
"apple/dispatch_source_mach.h",
1956+
"apple/osstatus_logging.h",
1957+
"apple/osstatus_logging.mm",
19561958
"apple/owned_objc.h",
19571959
"apple/owned_objc.mm",
19581960
"apple/scoped_cffiledescriptorref.h",
@@ -1964,8 +1966,6 @@ component("base") {
19641966
"files/file_util_apple.mm",
19651967
"mac/foundation_util.h",
19661968
"mac/foundation_util.mm",
1967-
"mac/mac_logging.h",
1968-
"mac/mac_logging.mm",
19691969
"mac/mach_logging.cc",
19701970
"mac/mach_logging.h",
19711971
"mac/scoped_mach_port.cc",

base/mac/mac_logging.h renamed to base/apple/osstatus_logging.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef BASE_MAC_MAC_LOGGING_H_
6-
#define BASE_MAC_MAC_LOGGING_H_
5+
#ifndef BASE_APPLE_OSSTATUS_LOGGING_H_
6+
#define BASE_APPLE_OSSTATUS_LOGGING_H_
77

88
#include <string>
99

@@ -17,7 +17,7 @@
1717
#include <libkern/OSTypes.h>
1818
#endif
1919

20-
// Use the OSSTATUS_LOG family to log messages related to errors in Mac OS X
20+
// Use the OSSTATUS_LOG family to log messages related to errors in macOS/iOS
2121
// system routines that report status via an OSStatus or OSErr value. It is
2222
// similar to the PLOG family which operates on errno, but because there is no
2323
// global (or thread-local) OSStatus or OSErr value, the specific error must
@@ -30,7 +30,7 @@
3030

3131
namespace logging {
3232

33-
// Returns a UTF8 description from an OS X Status error.
33+
// Returns a UTF8 description from an OSStatus/OSErr value.
3434
BASE_EXPORT std::string DescriptionFromOSStatus(OSStatus err);
3535

3636
class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage {
@@ -58,44 +58,44 @@ class BASE_EXPORT OSStatusLogMessage : public logging::LogMessage {
5858
#endif
5959

6060
#define OSSTATUS_LOG_STREAM(severity, status) \
61-
COMPACT_GOOGLE_LOG_EX_ ## severity(OSStatusLogMessage, status).stream()
62-
#define OSSTATUS_VLOG_STREAM(verbose_level, status) \
63-
logging::OSStatusLogMessage(__FILE__, __LINE__, \
64-
-verbose_level, status).stream()
61+
COMPACT_GOOGLE_LOG_EX_##severity(OSStatusLogMessage, status).stream()
62+
#define OSSTATUS_VLOG_STREAM(verbose_level, status) \
63+
logging::OSStatusLogMessage(__FILE__, __LINE__, -verbose_level, status) \
64+
.stream()
6565

6666
#define OSSTATUS_LOG(severity, status) \
67-
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), LOG_IS_ON(severity))
67+
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), LOG_IS_ON(severity))
6868
#define OSSTATUS_LOG_IF(severity, condition, status) \
69-
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
70-
LOG_IS_ON(severity) && (condition))
69+
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
70+
LOG_IS_ON(severity) && (condition))
7171

72-
#define OSSTATUS_VLOG(verbose_level, status) \
73-
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
74-
VLOG_IS_ON(verbose_level))
72+
#define OSSTATUS_VLOG(verbose_level, status) \
73+
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
74+
VLOG_IS_ON(verbose_level))
7575
#define OSSTATUS_VLOG_IF(verbose_level, condition, status) \
76-
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
77-
VLOG_IS_ON(verbose_level) && (condition))
76+
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
77+
VLOG_IS_ON(verbose_level) && (condition))
7878

79-
#define OSSTATUS_CHECK(condition, status) \
80-
LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), !(condition)) \
81-
<< "Check failed: " # condition << ". "
79+
#define OSSTATUS_CHECK(condition, status) \
80+
LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), !(condition)) \
81+
<< "Check failed: " #condition << ". "
8282

8383
#define OSSTATUS_DLOG(severity, status) \
84-
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), DLOG_IS_ON(severity))
84+
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), DLOG_IS_ON(severity))
8585
#define OSSTATUS_DLOG_IF(severity, condition, status) \
86-
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
87-
DLOG_IS_ON(severity) && (condition))
86+
LAZY_STREAM(OSSTATUS_LOG_STREAM(severity, status), \
87+
DLOG_IS_ON(severity) && (condition))
8888

89-
#define OSSTATUS_DVLOG(verbose_level, status) \
90-
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
91-
MAC_DVLOG_IS_ON(verbose_level))
89+
#define OSSTATUS_DVLOG(verbose_level, status) \
90+
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
91+
MAC_DVLOG_IS_ON(verbose_level))
9292
#define OSSTATUS_DVLOG_IF(verbose_level, condition, status) \
93-
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
94-
MAC_DVLOG_IS_ON(verbose_level) && (condition))
93+
LAZY_STREAM(OSSTATUS_VLOG_STREAM(verbose_level, status), \
94+
MAC_DVLOG_IS_ON(verbose_level) && (condition))
9595

9696
#define OSSTATUS_DCHECK(condition, status) \
9797
LAZY_STREAM(OSSTATUS_LOG_STREAM(FATAL, status), \
9898
DCHECK_IS_ON() && !(condition)) \
9999
<< "Check failed: " #condition << ". "
100100

101-
#endif // BASE_MAC_MAC_LOGGING_H_
101+
#endif // BASE_APPLE_OSSTATUS_LOGGING_H_

base/mac/mac_logging.mm renamed to base/apple/osstatus_logging.mm

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,30 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#include "base/mac/mac_logging.h"
5+
#include "base/apple/osstatus_logging.h"
66

77
#import <Foundation/Foundation.h>
88

99
#include <iomanip>
1010

11-
#include "build/build_config.h"
12-
13-
#if !BUILDFLAG(IS_IOS)
14-
#include <CoreServices/CoreServices.h>
15-
#endif
16-
1711
namespace logging {
1812

1913
std::string DescriptionFromOSStatus(OSStatus err) {
20-
NSError* error =
21-
[NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil];
14+
NSError* error = [NSError errorWithDomain:NSOSStatusErrorDomain
15+
code:err
16+
userInfo:nil];
2217
return error.description.UTF8String;
2318
}
2419

2520
OSStatusLogMessage::OSStatusLogMessage(const char* file_path,
2621
int line,
2722
LogSeverity severity,
2823
OSStatus status)
29-
: LogMessage(file_path, line, severity),
30-
status_(status) {
31-
}
24+
: LogMessage(file_path, line, severity), status_(status) {}
3225

3326
OSStatusLogMessage::~OSStatusLogMessage() {
34-
#if BUILDFLAG(IS_IOS)
35-
// TODO(crbug.com/546375): Consider using NSError with NSOSStatusErrorDomain
36-
// to try to get a description of the failure.
37-
stream() << ": " << status_;
38-
#else
39-
stream() << ": "
40-
<< DescriptionFromOSStatus(status_)
41-
<< " ("
42-
<< status_
27+
stream() << ": " << DescriptionFromOSStatus(status_) << " (" << status_
4328
<< ")";
44-
#endif
4529
}
4630

4731
} // namespace logging

base/mac/authorization_util.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <string>
1212

1313
#include "base/apple/bundle_locations.h"
14+
#include "base/apple/osstatus_logging.h"
1415
#include "base/logging.h"
1516
#include "base/mac/foundation_util.h"
16-
#include "base/mac/mac_logging.h"
1717
#include "base/mac/scoped_authorizationref.h"
1818
#include "base/posix/eintr_wrapper.h"
1919
#include "base/strings/string_number_conversions.h"

base/mac/foundation_util.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#include <vector>
1212

1313
#include "base/apple/bundle_locations.h"
14+
#include "base/apple/osstatus_logging.h"
1415
#include "base/containers/adapters.h"
1516
#include "base/files/file_path.h"
1617
#include "base/logging.h"
17-
#include "base/mac/mac_logging.h"
1818
#include "base/notreached.h"
1919
#include "base/numerics/checked_math.h"
2020
#include "base/numerics/safe_conversions.h"

base/mac/mac_util.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
#include "base/apple/bridging.h"
1919
#include "base/apple/bundle_locations.h"
20+
#include "base/apple/osstatus_logging.h"
2021
#include "base/files/file_path.h"
2122
#include "base/logging.h"
2223
#include "base/mac/foundation_util.h"
23-
#include "base/mac/mac_logging.h"
2424
#include "base/mac/scoped_aedesc.h"
2525
#include "base/mac/scoped_cftyperef.h"
2626
#include "base/mac/scoped_ioobject.h"

chrome/app_shim/chrome_main_app_mode_mac.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "base/allocator/early_zone_registration_apple.h"
1515
#include "base/apple/bundle_locations.h"
16+
#include "base/apple/osstatus_logging.h"
1617
#include "base/at_exit.h"
1718
#include "base/base_switches.h"
1819
#include "base/check.h"
@@ -21,7 +22,6 @@
2122
#include "base/files/file_path.h"
2223
#include "base/files/file_util.h"
2324
#include "base/functional/bind.h"
24-
#include "base/mac/mac_logging.h"
2525
#include "base/message_loop/message_pump_type.h"
2626
#include "base/run_loop.h"
2727
#include "base/strings/sys_string_conversions.h"

chrome/browser/apps/app_shim/app_shim_manager_mac.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "apps/app_lifetime_monitor_factory.h"
1414
#include "base/apple/bundle_locations.h"
15+
#include "base/apple/osstatus_logging.h"
1516
#include "base/barrier_closure.h"
1617
#include "base/debug/dump_without_crashing.h"
1718
#include "base/feature_list.h"
@@ -22,7 +23,6 @@
2223
#include "base/hash/sha1.h"
2324
#include "base/logging.h"
2425
#include "base/mac/foundation_util.h"
25-
#include "base/mac/mac_logging.h"
2626
#include "base/memory/raw_ptr.h"
2727
#include "base/no_destructor.h"
2828
#include "base/strings/stringprintf.h"

chrome/browser/mac/install_from_dmg.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
#include "base/apple/bridging.h"
2323
#include "base/apple/bundle_locations.h"
24+
#include "base/apple/osstatus_logging.h"
2425
#include "base/auto_reset.h"
2526
#include "base/command_line.h"
2627
#include "base/files/file_path.h"
2728
#include "base/logging.h"
2829
#include "base/mac/authorization_util.h"
2930
#include "base/mac/foundation_util.h"
30-
#include "base/mac/mac_logging.h"
3131
#include "base/mac/mac_util.h"
3232
#include "base/mac/mach_logging.h"
3333
#include "base/mac/scoped_authorizationref.h"

chrome/browser/mac/keystone_glue.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
#include "base/apple/bridging.h"
1515
#include "base/apple/bundle_locations.h"
16+
#include "base/apple/osstatus_logging.h"
1617
#include "base/file_version_info.h"
1718
#include "base/functional/bind.h"
1819
#include "base/location.h"
1920
#include "base/logging.h"
2021
#include "base/mac/authorization_util.h"
2122
#include "base/mac/foundation_util.h"
22-
#include "base/mac/mac_logging.h"
2323
#include "base/memory/ref_counted.h"
2424
#include "base/no_destructor.h"
2525
#include "base/strings/string_number_conversions.h"

0 commit comments

Comments
 (0)