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

Side by Side Diff: chrome/common/service_process_util_mac.mm

Issue 16917011: mac: Replace base::mac::ScopedCFTypeRef with base::ScopedCFTypeRef. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with fixed off-by-1 in git-clang-format Created 7 years, 6 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 | « chrome/common/multi_process_lock_mac.cc ('k') | chrome/common/service_process_util_posix.h » ('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) 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 "chrome/common/service_process_util_posix.h" 5 #include "chrome/common/service_process_util_posix.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #include <launch.h> 8 #include <launch.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return @"ServiceProcessSocket"; 60 return @"ServiceProcessSocket";
61 } 61 }
62 62
63 bool GetParentFSRef(const FSRef& child, FSRef* parent) { 63 bool GetParentFSRef(const FSRef& child, FSRef* parent) {
64 return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr; 64 return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr;
65 } 65 }
66 66
67 bool RemoveFromLaunchd() { 67 bool RemoveFromLaunchd() {
68 // We're killing a file. 68 // We're killing a file.
69 base::ThreadRestrictions::AssertIOAllowed(); 69 base::ThreadRestrictions::AssertIOAllowed();
70 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName()); 70 base::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
71 return Launchd::GetInstance()->DeletePlist(Launchd::User, 71 return Launchd::GetInstance()->DeletePlist(Launchd::User,
72 Launchd::Agent, 72 Launchd::Agent,
73 name); 73 name);
74 } 74 }
75 75
76 class ExecFilePathWatcherCallback { 76 class ExecFilePathWatcherCallback {
77 public: 77 public:
78 ExecFilePathWatcherCallback() {} 78 ExecFilePathWatcherCallback() {}
79 ~ExecFilePathWatcherCallback() {} 79 ~ExecFilePathWatcherCallback() {}
80 80
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return reinterpret_cast<CFDictionaryRef>(launchd_plist); 288 return reinterpret_cast<CFDictionaryRef>(launchd_plist);
289 } 289 }
290 290
291 // Writes the launchd property list into the user's LaunchAgents directory, 291 // Writes the launchd property list into the user's LaunchAgents directory,
292 // creating that directory if needed. This will cause the service process to be 292 // creating that directory if needed. This will cause the service process to be
293 // auto launched on the next user login. 293 // auto launched on the next user login.
294 bool ServiceProcessState::AddToAutoRun() { 294 bool ServiceProcessState::AddToAutoRun() {
295 // We're creating directories and writing a file. 295 // We're creating directories and writing a file.
296 base::ThreadRestrictions::AssertIOAllowed(); 296 base::ThreadRestrictions::AssertIOAllowed();
297 DCHECK(autorun_command_line_.get()); 297 DCHECK(autorun_command_line_.get());
298 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName()); 298 base::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
299 base::mac::ScopedCFTypeRef<CFDictionaryRef> plist( 299 base::ScopedCFTypeRef<CFDictionaryRef> plist(
300 CreateServiceProcessLaunchdPlist(autorun_command_line_.get(), true)); 300 CreateServiceProcessLaunchdPlist(autorun_command_line_.get(), true));
301 return Launchd::GetInstance()->WritePlistToFile(Launchd::User, 301 return Launchd::GetInstance()->WritePlistToFile(Launchd::User,
302 Launchd::Agent, 302 Launchd::Agent,
303 name, 303 name,
304 plist); 304 plist);
305 } 305 }
306 306
307 bool ServiceProcessState::RemoveFromAutoRun() { 307 bool ServiceProcessState::RemoveFromAutoRun() {
308 return RemoveFromLaunchd(); 308 return RemoveFromLaunchd();
309 } 309 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 bool needs_shutdown = false; 351 bool needs_shutdown = false;
352 bool needs_restart = false; 352 bool needs_restart = false;
353 bool good_bundle = false; 353 bool good_bundle = false;
354 354
355 FSRef macos_fsref; 355 FSRef macos_fsref;
356 if (GetParentFSRef(executable_fsref_, &macos_fsref)) { 356 if (GetParentFSRef(executable_fsref_, &macos_fsref)) {
357 FSRef contents_fsref; 357 FSRef contents_fsref;
358 if (GetParentFSRef(macos_fsref, &contents_fsref)) { 358 if (GetParentFSRef(macos_fsref, &contents_fsref)) {
359 FSRef bundle_fsref; 359 FSRef bundle_fsref;
360 if (GetParentFSRef(contents_fsref, &bundle_fsref)) { 360 if (GetParentFSRef(contents_fsref, &bundle_fsref)) {
361 base::mac::ScopedCFTypeRef<CFURLRef> bundle_url( 361 base::ScopedCFTypeRef<CFURLRef> bundle_url(
362 CFURLCreateFromFSRef(kCFAllocatorDefault, &bundle_fsref)); 362 CFURLCreateFromFSRef(kCFAllocatorDefault, &bundle_fsref));
363 if (bundle_url.get()) { 363 if (bundle_url.get()) {
364 base::mac::ScopedCFTypeRef<CFBundleRef> bundle( 364 base::ScopedCFTypeRef<CFBundleRef> bundle(
365 CFBundleCreate(kCFAllocatorDefault, bundle_url)); 365 CFBundleCreate(kCFAllocatorDefault, bundle_url));
366 // Check to see if the bundle still has a minimal structure. 366 // Check to see if the bundle still has a minimal structure.
367 good_bundle = CFBundleGetIdentifier(bundle) != NULL; 367 good_bundle = CFBundleGetIdentifier(bundle) != NULL;
368 } 368 }
369 } 369 }
370 } 370 }
371 } 371 }
372 if (!good_bundle) { 372 if (!good_bundle) {
373 needs_shutdown = true; 373 needs_shutdown = true;
374 } else { 374 } else {
(...skipping 12 matching lines...) Expand all
387 was_moved = false; 387 was_moved = false;
388 } 388 }
389 } 389 }
390 if (was_moved) { 390 if (was_moved) {
391 needs_restart = true; 391 needs_restart = true;
392 } 392 }
393 } 393 }
394 } 394 }
395 if (needs_shutdown || needs_restart) { 395 if (needs_shutdown || needs_restart) {
396 // First deal with the plist. 396 // First deal with the plist.
397 base::mac::ScopedCFTypeRef<CFStringRef> name( 397 base::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
398 CopyServiceProcessLaunchDName());
399 if (needs_restart) { 398 if (needs_restart) {
400 base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> plist( 399 base::ScopedCFTypeRef<CFMutableDictionaryRef> plist(
401 Launchd::GetInstance()->CreatePlistFromFile(Launchd::User, 400 Launchd::GetInstance()->CreatePlistFromFile(
402 Launchd::Agent, 401 Launchd::User, Launchd::Agent, name));
403 name));
404 if (plist.get()) { 402 if (plist.get()) {
405 NSMutableDictionary* ns_plist = base::mac::CFToNSCast(plist); 403 NSMutableDictionary* ns_plist = base::mac::CFToNSCast(plist);
406 std::string new_path = base::mac::PathFromFSRef(executable_fsref_); 404 std::string new_path = base::mac::PathFromFSRef(executable_fsref_);
407 NSString* ns_new_path = base::SysUTF8ToNSString(new_path); 405 NSString* ns_new_path = base::SysUTF8ToNSString(new_path);
408 [ns_plist setObject:ns_new_path forKey:@ LAUNCH_JOBKEY_PROGRAM]; 406 [ns_plist setObject:ns_new_path forKey:@ LAUNCH_JOBKEY_PROGRAM];
409 scoped_nsobject<NSMutableArray> args( 407 scoped_nsobject<NSMutableArray> args(
410 [[ns_plist objectForKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS] 408 [[ns_plist objectForKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS]
411 mutableCopy]); 409 mutableCopy]);
412 [args replaceObjectAtIndex:0 withObject:ns_new_path]; 410 [args replaceObjectAtIndex:0 withObject:ns_new_path];
413 [ns_plist setObject:args forKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS]; 411 [ns_plist setObject:args forKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS];
(...skipping 24 matching lines...) Expand all
438 session_type)) { 436 session_type)) {
439 DLOG(ERROR) << "RestartLaunchdJob"; 437 DLOG(ERROR) << "RestartLaunchdJob";
440 needs_shutdown = true; 438 needs_shutdown = true;
441 } 439 }
442 } 440 }
443 if (needs_shutdown) { 441 if (needs_shutdown) {
444 CFStringRef label = 442 CFStringRef label =
445 base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); 443 base::mac::NSToCFCast(GetServiceProcessLaunchDLabel());
446 CFErrorRef err = NULL; 444 CFErrorRef err = NULL;
447 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { 445 if (!Launchd::GetInstance()->RemoveJob(label, &err)) {
448 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err); 446 base::ScopedCFTypeRef<CFErrorRef> scoped_err(err);
449 DLOG(ERROR) << "RemoveJob " << err; 447 DLOG(ERROR) << "RemoveJob " << err;
450 // Exiting with zero, so launchd doesn't restart the process. 448 // Exiting with zero, so launchd doesn't restart the process.
451 exit(0); 449 exit(0);
452 } 450 }
453 } 451 }
454 } 452 }
455 } 453 }
OLDNEW
« no previous file with comments | « chrome/common/multi_process_lock_mac.cc ('k') | chrome/common/service_process_util_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698