Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: base/mac/mac_util.mm

Issue 9235084: Add OSSTATUS_LOG API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/mac/mac_util.h" 5 #include "base/mac/mac_util.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <string.h> 8 #include <string.h>
9 #include <sys/utsname.h> 9 #include <sys/utsname.h>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/bundle_locations.h" 13 #include "base/mac/bundle_locations.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/mac/mac_logging.h"
15 #include "base/mac/scoped_cftyperef.h" 16 #include "base/mac/scoped_cftyperef.h"
16 #include "base/memory/scoped_nsobject.h" 17 #include "base/memory/scoped_nsobject.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/string_piece.h" 19 #include "base/string_piece.h"
19 #include "base/sys_string_conversions.h" 20 #include "base/sys_string_conversions.h"
20 21
21 namespace base { 22 namespace base {
22 namespace mac { 23 namespace mac {
23 24
24 namespace { 25 namespace {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return !methodImplemented || 212 return !methodImplemented ||
212 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; 213 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)];
213 } 214 }
214 215
215 void ActivateProcess(pid_t pid) { 216 void ActivateProcess(pid_t pid) {
216 ProcessSerialNumber process; 217 ProcessSerialNumber process;
217 OSStatus status = GetProcessForPID(pid, &process); 218 OSStatus status = GetProcessForPID(pid, &process);
218 if (status == noErr) { 219 if (status == noErr) {
219 SetFrontProcess(&process); 220 SetFrontProcess(&process);
220 } else { 221 } else {
221 DLOG(WARNING) << "Unable to get process for pid " << pid; 222 OSSTATUS_DLOG(WARNING, status) << "Unable to get process for pid " << pid;
222 } 223 }
223 } 224 }
224 225
225 bool AmIForeground() { 226 bool AmIForeground() {
226 ProcessSerialNumber foreground_psn = { 0 }; 227 ProcessSerialNumber foreground_psn = { 0 };
227 OSErr err = GetFrontProcess(&foreground_psn); 228 OSErr err = GetFrontProcess(&foreground_psn);
228 if (err != noErr) { 229 if (err != noErr) {
229 DLOG(WARNING) << "GetFrontProcess: " << err; 230 OSSTATUS_DLOG(WARNING, err) << "GetFrontProcess";
230 return false; 231 return false;
231 } 232 }
232 233
233 ProcessSerialNumber my_psn = { 0, kCurrentProcess }; 234 ProcessSerialNumber my_psn = { 0, kCurrentProcess };
234 235
235 Boolean result = FALSE; 236 Boolean result = FALSE;
236 err = SameProcess(&foreground_psn, &my_psn, &result); 237 err = SameProcess(&foreground_psn, &my_psn, &result);
237 if (err != noErr) { 238 if (err != noErr) {
238 DLOG(WARNING) << "SameProcess: " << err; 239 OSSTATUS_DLOG(WARNING, err) << "SameProcess";
239 return false; 240 return false;
240 } 241 }
241 242
242 return result; 243 return result;
243 } 244 }
244 245
245 bool SetFileBackupExclusion(const FilePath& file_path) { 246 bool SetFileBackupExclusion(const FilePath& file_path) {
246 NSString* file_path_ns = 247 NSString* file_path_ns =
247 [NSString stringWithUTF8String:file_path.value().c_str()]; 248 [NSString stringWithUTF8String:file_path.value().c_str()];
248 NSURL* file_url = [NSURL fileURLWithPath:file_path_ns]; 249 NSURL* file_url = [NSURL fileURLWithPath:file_path_ns];
249 250
250 // When excludeByPath is true the application must be running with root 251 // When excludeByPath is true the application must be running with root
251 // privileges (admin for 10.6 and earlier) but the URL does not have to 252 // privileges (admin for 10.6 and earlier) but the URL does not have to
252 // already exist. When excludeByPath is false the URL must already exist but 253 // already exist. When excludeByPath is false the URL must already exist but
253 // can be used in non-root (or admin as above) mode. We use false so that 254 // can be used in non-root (or admin as above) mode. We use false so that
254 // non-root (or admin) users don't get their TimeMachine drive filled up with 255 // non-root (or admin) users don't get their TimeMachine drive filled up with
255 // unnecessary backups. 256 // unnecessary backups.
256 OSStatus os_err = 257 OSStatus os_err =
257 CSBackupSetItemExcluded(base::mac::NSToCFCast(file_url), TRUE, FALSE); 258 CSBackupSetItemExcluded(base::mac::NSToCFCast(file_url), TRUE, FALSE);
258 if (os_err != noErr) { 259 if (os_err != noErr) {
259 DLOG(WARNING) << "Failed to set backup exclusion for file '" 260 OSSTATUS_DLOG(WARNING, os_err)
260 << file_path.value().c_str() << "' with error " 261 << "Failed to set backup exclusion for file '"
261 << os_err << " (" << GetMacOSStatusErrorString(os_err) 262 << file_path.value().c_str() << "'";
262 << ": " << GetMacOSStatusCommentString(os_err)
263 << "). Continuing.";
264 } 263 }
265 return os_err == noErr; 264 return os_err == noErr;
266 } 265 }
267 266
268 void SetProcessName(CFStringRef process_name) { 267 void SetProcessName(CFStringRef process_name) {
269 if (!process_name || CFStringGetLength(process_name) == 0) { 268 if (!process_name || CFStringGetLength(process_name) == 0) {
270 NOTREACHED() << "SetProcessName given bad name."; 269 NOTREACHED() << "SetProcessName given bad name.";
271 return; 270 return;
272 } 271 }
273 272
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 343 }
345 344
346 PrivateLSASN asn = ls_get_current_application_asn_func(); 345 PrivateLSASN asn = ls_get_current_application_asn_func();
347 // Constant used by WebKit; what exactly it means is unknown. 346 // Constant used by WebKit; what exactly it means is unknown.
348 const int magic_session_constant = -2; 347 const int magic_session_constant = -2;
349 OSErr err = 348 OSErr err =
350 ls_set_application_information_item_func(magic_session_constant, asn, 349 ls_set_application_information_item_func(magic_session_constant, asn,
351 ls_display_name_key, 350 ls_display_name_key,
352 process_name, 351 process_name,
353 NULL /* optional out param */); 352 NULL /* optional out param */);
354 DLOG_IF(ERROR, err) << "Call to set process name failed, err " << err; 353 OSSTATUS_DLOG_IF(ERROR, err != noErr, err)
354 << "Call to set process name failed";
355 } 355 }
356 356
357 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do 357 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do
358 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle 358 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle
359 // converting a PDF-backed NSImage into a CGImageRef. This function will 359 // converting a PDF-backed NSImage into a CGImageRef. This function will
360 // rasterize the PDF into a bitmap CGImage. The caller is responsible for 360 // rasterize the PDF into a bitmap CGImage. The caller is responsible for
361 // releasing the return value. 361 // releasing the return value.
362 CGImageRef CopyNSImageToCGImage(NSImage* image) { 362 CGImageRef CopyNSImageToCGImage(NSImage* image) {
363 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef . 363 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef .
364 NSSize size = [image size]; 364 NSSize size = [image size];
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 #endif 617 #endif
618 618
619 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7) 619 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7)
620 bool IsOSLaterThanLion() { 620 bool IsOSLaterThanLion() {
621 return MacOSXMinorVersion() > LION_MINOR_VERSION; 621 return MacOSXMinorVersion() > LION_MINOR_VERSION;
622 } 622 }
623 #endif 623 #endif
624 624
625 } // namespace mac 625 } // namespace mac
626 } // namespace base 626 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698