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

Side by Side Diff: chrome/browser/mac/dock.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) 2011 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 #import "chrome/browser/mac/dock.h" 5 #import "chrome/browser/mac/dock.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h> 7 #include <ApplicationServices/ApplicationServices.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <CoreFoundation/CoreFoundation.h> 9 #include <CoreFoundation/CoreFoundation.h>
10 #include <signal.h> 10 #include <signal.h>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/mac/mac_logging.h"
13 #include "base/mac/mac_util.h" 14 #include "base/mac/mac_util.h"
14 #include "base/mac/scoped_cftyperef.h" 15 #include "base/mac/scoped_cftyperef.h"
15 #include "base/mac/scoped_nsautorelease_pool.h" 16 #include "base/mac/scoped_nsautorelease_pool.h"
16 #include "base/sys_string_conversions.h" 17 #include "base/sys_string_conversions.h"
17 #include "chrome/browser/mac/launchd.h" 18 #include "chrome/browser/mac/launchd.h"
18 19
19 namespace dock { 20 namespace dock {
20 namespace { 21 namespace {
21 22
22 NSString* const kDockTileDataKey = @"tile-data"; 23 NSString* const kDockTileDataKey = @"tile-data";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // subsequent call to GetNextProcess, or if the Process Manager's internal 80 // subsequent call to GetNextProcess, or if the Process Manager's internal
80 // order of processes changes? Tolerate the race by allowing failure. Since 81 // order of processes changes? Tolerate the race by allowing failure. Since
81 // this function is only used on Leopard to find the Dock process so that it 82 // this function is only used on Leopard to find the Dock process so that it
82 // can be restarted, the worst that can happen here is that the Dock won't 83 // can be restarted, the worst that can happen here is that the Dock won't
83 // be restarted. 84 // be restarted.
84 ProcessSerialNumber psn = {0, kNoProcess}; 85 ProcessSerialNumber psn = {0, kNoProcess};
85 OSStatus status; 86 OSStatus status;
86 while ((status = GetNextProcess(&psn)) == noErr) { 87 while ((status = GetNextProcess(&psn)) == noErr) {
87 pid_t process_pid; 88 pid_t process_pid;
88 if ((status = GetProcessPID(&psn, &process_pid)) != noErr) { 89 if ((status = GetProcessPID(&psn, &process_pid)) != noErr) {
89 LOG(ERROR) << "GetProcessPID: " << status; 90 OSSTATUS_LOG(ERROR, status) << "GetProcessPID";
90 continue; 91 continue;
91 } 92 }
92 93
93 base::mac::ScopedCFTypeRef<CFDictionaryRef> process_dictionary( 94 base::mac::ScopedCFTypeRef<CFDictionaryRef> process_dictionary(
94 ProcessInformationCopyDictionary(&psn, 95 ProcessInformationCopyDictionary(&psn,
95 kProcessDictionaryIncludeAllInformationMask)); 96 kProcessDictionaryIncludeAllInformationMask));
96 if (!process_dictionary.get()) { 97 if (!process_dictionary.get()) {
97 LOG(ERROR) << "ProcessInformationCopyDictionary"; 98 LOG(ERROR) << "ProcessInformationCopyDictionary";
98 continue; 99 continue;
99 } 100 }
100 101
101 CFStringRef process_bundle_id_cf = static_cast<CFStringRef>( 102 CFStringRef process_bundle_id_cf = base::mac::CFCast<CFStringRef>(
102 CFDictionaryGetValue(process_dictionary, kCFBundleIdentifierKey)); 103 CFDictionaryGetValue(process_dictionary, kCFBundleIdentifierKey));
103 if (!process_bundle_id_cf) { 104 if (!process_bundle_id_cf) {
104 // Not all processes have a bundle ID. 105 // Not all processes have a bundle ID.
105 continue; 106 continue;
106 } else if (CFGetTypeID(process_bundle_id_cf) != CFStringGetTypeID()) {
107 LOG(ERROR) << "process_bundle_id_cf not CFStringRef";
108 continue;
109 } 107 }
110 108
111 std::string process_bundle_id = 109 std::string process_bundle_id =
112 base::SysCFStringRefToUTF8(process_bundle_id_cf); 110 base::SysCFStringRefToUTF8(process_bundle_id_cf);
113 if (process_bundle_id == bundle_id) { 111 if (process_bundle_id == bundle_id) {
114 // Found it! 112 // Found it!
115 return process_pid; 113 return process_pid;
116 } 114 }
117 } 115 }
118 116
119 // status will be procNotFound (-600) if the process wasn't found. 117 // status will be procNotFound (-600) if the process wasn't found.
120 LOG(ERROR) << "GetNextProcess: " << status; 118 OSSTATUS_LOG(ERROR, status) << "GetNextProcess";
121 119
122 return -1; 120 return -1;
123 } 121 }
124 122
125 // Restart the Dock process by sending it a SIGHUP. 123 // Restart the Dock process by sending it a SIGHUP.
126 void Restart() { 124 void Restart() {
127 pid_t pid; 125 pid_t pid;
128 126
129 if (base::mac::IsOSSnowLeopardOrLater()) { 127 if (base::mac::IsOSSnowLeopardOrLater()) {
130 // Doing this via launchd using the proper job label is the safest way to 128 // Doing this via launchd using the proper job label is the safest way to
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 344 }
347 345
348 // Rewrite the plist. 346 // Rewrite the plist.
349 [dock_plist setObject:persistent_apps forKey:kDockPersistentAppsKey]; 347 [dock_plist setObject:persistent_apps forKey:kDockPersistentAppsKey];
350 [user_defaults setPersistentDomain:dock_plist forName:kDockDomain]; 348 [user_defaults setPersistentDomain:dock_plist forName:kDockDomain];
351 349
352 Restart(); 350 Restart();
353 } 351 }
354 352
355 } // namespace dock 353 } // namespace dock
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698