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

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

Issue 7069021: Non-path Time Machine Exclusions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « base/mac/mac_util.h ('k') | base/mac/mac_util_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/mac/foundation_util.h"
11 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/scoped_nsobject.h" 13 #include "base/memory/scoped_nsobject.h"
13 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
14 15
15 namespace base { 16 namespace base {
16 namespace mac { 17 namespace mac {
17 18
18 namespace { 19 namespace {
19 20
20 // The current count of outstanding requests for full screen mode from browser 21 // The current count of outstanding requests for full screen mode from browser
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 void ActivateProcess(pid_t pid) { 232 void ActivateProcess(pid_t pid) {
232 ProcessSerialNumber process; 233 ProcessSerialNumber process;
233 OSStatus status = GetProcessForPID(pid, &process); 234 OSStatus status = GetProcessForPID(pid, &process);
234 if (status == noErr) { 235 if (status == noErr) {
235 SetFrontProcess(&process); 236 SetFrontProcess(&process);
236 } else { 237 } else {
237 LOG(WARNING) << "Unable to get process for pid " << pid; 238 LOG(WARNING) << "Unable to get process for pid " << pid;
238 } 239 }
239 } 240 }
240 241
241 bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) { 242 bool SetFileBackupExclusion(const FilePath& file_path) {
242 NSString* filePath = 243 NSString* filePath =
243 [NSString stringWithUTF8String:file_path.value().c_str()]; 244 [NSString stringWithUTF8String:file_path.value().c_str()];
244 245 NSURL* url = [NSURL fileURLWithPath:filePath];
245 // If being asked to exclude something in a tmp directory, just lie and say it 246 // Do a pre-emptive unexclude by-path since by-path exclusions may have been
246 // was done. TimeMachine will already ignore tmp directories. This keeps the 247 // performed on this file in the past.
247 // temporary profiles used by unittests from being added to the exclude list. 248 CSBackupSetItemExcluded(base::mac::NSToCFCast(url), FALSE, TRUE);
248 // Otherwise, as /Library/Preferences/com.apple.TimeMachine.plist grows the 249 // When excludeByPath is true the application must be running with root
249 // bots slow down due to reading/writing all the temporary profiles used over 250 // privileges (admin for 10.6 and earlier) but the URL does not have to
250 // time. 251 // already exist. When excludeByPath is false the URL must already exist but
251 252 // can be used in non-root (or admin as above) mode. We use false so that
252 NSString* tmpDir = NSTemporaryDirectory(); 253 // non-root (or admin) users don't get their TimeMachine drive filled up with
253 // Make sure the temp dir is terminated with a slash 254 // unnecessary backups.
254 if (tmpDir && ![tmpDir hasSuffix:@"/"]) 255 OSStatus os_err =
255 tmpDir = [tmpDir stringByAppendingString:@"/"]; 256 CSBackupSetItemExcluded(base::mac::NSToCFCast(url), TRUE, FALSE);
256 // '/var' is a link to '/private/var', make sure to check both forms. 257 if (os_err != noErr) {
257 NSString* privateTmpDir = nil; 258 LOG(WARNING) << "Failed to set backup exclusion for file '"
258 if ([tmpDir hasPrefix:@"/var/"]) 259 << file_path.value().c_str() << "' with error "
259 privateTmpDir = [@"/private" stringByAppendingString:tmpDir]; 260 << os_err << " (" << GetMacOSStatusErrorString(os_err)
260 261 << ": " << GetMacOSStatusCommentString(os_err)
261 if ((tmpDir && [filePath hasPrefix:tmpDir]) || 262 << "). Continuing.";
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 } 263 }
269 264 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 } 265 }
283 266
284 void SetProcessName(CFStringRef process_name) { 267 void SetProcessName(CFStringRef process_name) {
285 if (!process_name || CFStringGetLength(process_name) == 0) { 268 if (!process_name || CFStringGetLength(process_name) == 0) {
286 NOTREACHED() << "SetProcessName given bad name."; 269 NOTREACHED() << "SetProcessName given bad name.";
287 return; 270 return;
288 } 271 }
289 272
290 if (![NSThread isMainThread]) { 273 if (![NSThread isMainThread]) {
291 NOTREACHED() << "Should only set process name from main thread."; 274 NOTREACHED() << "Should only set process name from main thread.";
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); 458 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
476 if (!item.get()) { 459 if (!item.get()) {
477 LOG(ERROR) << "Process launched at Login but can't access Login Item List."; 460 LOG(ERROR) << "Process launched at Login but can't access Login Item List.";
478 return false; 461 return false;
479 } 462 }
480 return IsHiddenLoginItem(item); 463 return IsHiddenLoginItem(item);
481 } 464 }
482 465
483 } // namespace mac 466 } // namespace mac
484 } // namespace base 467 } // namespace base
OLDNEW
« no previous file with comments | « base/mac/mac_util.h ('k') | base/mac/mac_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698