OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 void ActivateProcess(pid_t pid) { | 231 void ActivateProcess(pid_t pid) { |
232 ProcessSerialNumber process; | 232 ProcessSerialNumber process; |
233 OSStatus status = GetProcessForPID(pid, &process); | 233 OSStatus status = GetProcessForPID(pid, &process); |
234 if (status == noErr) { | 234 if (status == noErr) { |
235 SetFrontProcess(&process); | 235 SetFrontProcess(&process); |
236 } else { | 236 } else { |
237 LOG(WARNING) << "Unable to get process for pid " << pid; | 237 LOG(WARNING) << "Unable to get process for pid " << pid; |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) { | 241 bool SetFileBackupExclusion(const FilePath& file_path) { |
242 NSString* filePath = | 242 NSString* filePath = |
243 [NSString stringWithUTF8String:file_path.value().c_str()]; | 243 [NSString stringWithUTF8String:file_path.value().c_str()]; |
244 | 244 NSURL* url = [NSURL fileURLWithPath:filePath]; |
245 // If being asked to exclude something in a tmp directory, just lie and say it | 245 // When excludeByPath is true the application must be running with root |
246 // was done. TimeMachine will already ignore tmp directories. This keeps the | 246 // privileges (admin for 10.6 and earlier) but the URL does not have to |
247 // temporary profiles used by unittests from being added to the exclude list. | 247 // already exist. When excludeByPath is false the URL must already exist but |
248 // Otherwise, as /Library/Preferences/com.apple.TimeMachine.plist grows the | 248 // can be used in non-root (or admin as above) mode. We use false so that |
249 // bots slow down due to reading/writing all the temporary profiles used over | 249 // non-root (or admin) users don't get their TimeMachine drive filled up with |
250 // time. | 250 // unnecessary backups. |
251 | 251 OSStatus os_err = CSBackupSetItemExcluded((CFURLRef)url, true, false); |
Mark Mentovai
2011/05/25 19:19:06
Instead of CFURLRef, use NSToCFCast from "base/mac
mrossetti
2011/05/25 21:12:31
Done.
| |
252 NSString* tmpDir = NSTemporaryDirectory(); | 252 if (os_err != noErr) { |
253 // Make sure the temp dir is terminated with a slash | 253 LOG(WARNING) << "Failed to set backup exclusion for file '" |
254 if (tmpDir && ![tmpDir hasSuffix:@"/"]) | 254 << file_path.value().c_str() << "' with error " |
255 tmpDir = [tmpDir stringByAppendingString:@"/"]; | 255 << os_err << " (" << GetMacOSStatusErrorString(os_err) |
256 // '/var' is a link to '/private/var', make sure to check both forms. | 256 << ": " << GetMacOSStatusCommentString(os_err) |
257 NSString* privateTmpDir = nil; | 257 << "). Continuing."; |
258 if ([tmpDir hasPrefix:@"/var/"]) | |
259 privateTmpDir = [@"/private" stringByAppendingString:tmpDir]; | |
260 | |
261 if ((tmpDir && [filePath hasPrefix:tmpDir]) || | |
262 (privateTmpDir && [filePath hasPrefix:privateTmpDir]) || | |
263 [filePath hasPrefix:@"/tmp/"] || | |
264 [filePath hasPrefix:@"/var/tmp/"] || | |
265 [filePath hasPrefix:@"/private/tmp/"] || | |
266 [filePath hasPrefix:@"/private/var/tmp/"]) { | |
267 return true; | |
268 } | 258 } |
269 | 259 return os_err == noErr; |
270 NSURL* url = [NSURL fileURLWithPath:filePath]; | |
271 // Note that we always set CSBackupSetItemExcluded's excludeByPath param | |
272 // to true. This prevents a problem with toggling the setting: if the file | |
273 // is excluded with excludeByPath set to true then excludeByPath must | |
274 // also be true when un-excluding the file, otherwise the un-excluding | |
275 // will be ignored. | |
276 bool success = | |
277 CSBackupSetItemExcluded((CFURLRef)url, exclude, true) == noErr; | |
278 if (!success) | |
279 LOG(WARNING) << "Failed to set backup exclusion for file '" | |
280 << file_path.value().c_str() << "'. Continuing."; | |
281 return success; | |
282 } | 260 } |
283 | 261 |
284 void SetProcessName(CFStringRef process_name) { | 262 void SetProcessName(CFStringRef process_name) { |
285 if (!process_name || CFStringGetLength(process_name) == 0) { | 263 if (!process_name || CFStringGetLength(process_name) == 0) { |
286 NOTREACHED() << "SetProcessName given bad name."; | 264 NOTREACHED() << "SetProcessName given bad name."; |
287 return; | 265 return; |
288 } | 266 } |
289 | 267 |
290 if (![NSThread isMainThread]) { | 268 if (![NSThread isMainThread]) { |
291 NOTREACHED() << "Should only set process name from main thread."; | 269 NOTREACHED() << "Should only set process name from main thread."; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); | 453 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); |
476 if (!item.get()) { | 454 if (!item.get()) { |
477 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; | 455 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; |
478 return false; | 456 return false; |
479 } | 457 } |
480 return IsHiddenLoginItem(item); | 458 return IsHiddenLoginItem(item); |
481 } | 459 } |
482 | 460 |
483 } // namespace mac | 461 } // namespace mac |
484 } // namespace base | 462 } // namespace base |
OLD | NEW |