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

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

Issue 9131016: Cloud Print Policy - service side enforcement, Mac browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address nit + REBASE Created 8 years, 11 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 #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>
11 11
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ns_path = [ns_path stringByReplacingOccurrencesOfString:@" " 53 ns_path = [ns_path stringByReplacingOccurrencesOfString:@" "
54 withString:@"_"]; 54 withString:@"_"];
55 label = [label stringByAppendingString:ns_path]; 55 label = [label stringByAppendingString:ns_path];
56 return label; 56 return label;
57 } 57 }
58 58
59 NSString* GetServiceProcessLaunchDSocketKey() { 59 NSString* GetServiceProcessLaunchDSocketKey() {
60 return @"ServiceProcessSocket"; 60 return @"ServiceProcessSocket";
61 } 61 }
62 62
63 NSString* GetServiceProcessLaunchDSocketEnvVar() {
64 NSString *label = GetServiceProcessLaunchDLabel();
65 NSString *env_var = [label stringByReplacingOccurrencesOfString:@"."
66 withString:@"_"];
67 env_var = [env_var stringByAppendingString:@"_SOCKET"];
68 env_var = [env_var uppercaseString];
69 return env_var;
70 }
71
72 bool GetParentFSRef(const FSRef& child, FSRef* parent) { 63 bool GetParentFSRef(const FSRef& child, FSRef* parent) {
73 return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr; 64 return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr;
74 } 65 }
75 66
76 bool RemoveFromLaunchd() { 67 bool RemoveFromLaunchd() {
77 // We're killing a file. 68 // We're killing a file.
78 base::ThreadRestrictions::AssertIOAllowed(); 69 base::ThreadRestrictions::AssertIOAllowed();
79 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName()); 70 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName());
80 return Launchd::GetInstance()->DeletePlist(Launchd::User, 71 return Launchd::GetInstance()->DeletePlist(Launchd::User,
81 Launchd::Agent, 72 Launchd::Agent,
82 name); 73 name);
83 } 74 }
84 75
85 class ExecFilePathWatcherDelegate : public FilePathWatcher::Delegate { 76 class ExecFilePathWatcherDelegate : public FilePathWatcher::Delegate {
86 public: 77 public:
87 ExecFilePathWatcherDelegate() { } 78 ExecFilePathWatcherDelegate() { }
88 virtual ~ExecFilePathWatcherDelegate() { } 79 virtual ~ExecFilePathWatcherDelegate() { }
89 80
90 bool Init(const FilePath& path); 81 bool Init(const FilePath& path);
91 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; 82 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
92 83
93 private: 84 private:
94 FSRef executable_fsref_; 85 FSRef executable_fsref_;
95 }; 86 };
96 87
97 } // namespace 88 } // namespace
98 89
90 NSString* GetServiceProcessLaunchDSocketEnvVar() {
91 NSString *label = GetServiceProcessLaunchDLabel();
92 NSString *env_var = [label stringByReplacingOccurrencesOfString:@"."
93 withString:@"_"];
94 env_var = [env_var stringByAppendingString:@"_SOCKET"];
95 env_var = [env_var uppercaseString];
96 return env_var;
97 }
98
99 // Gets the name of the service process IPC channel. 99 // Gets the name of the service process IPC channel.
100 IPC::ChannelHandle GetServiceProcessChannel() { 100 IPC::ChannelHandle GetServiceProcessChannel() {
101 base::mac::ScopedNSAutoreleasePool pool; 101 base::mac::ScopedNSAutoreleasePool pool;
102 std::string socket_path; 102 std::string socket_path;
103 scoped_nsobject<NSDictionary> dictionary( 103 scoped_nsobject<NSDictionary> dictionary(
104 base::mac::CFToNSCast(Launchd::GetInstance()->CopyExports())); 104 base::mac::CFToNSCast(Launchd::GetInstance()->CopyExports()));
105 NSString *ns_socket_path = 105 NSString *ns_socket_path =
106 [dictionary objectForKey:GetServiceProcessLaunchDSocketEnvVar()]; 106 [dictionary objectForKey:GetServiceProcessLaunchDSocketEnvVar()];
107 if (ns_socket_path) { 107 if (ns_socket_path) {
108 socket_path = base::SysNSStringToUTF8(ns_socket_path); 108 socket_path = base::SysNSStringToUTF8(ns_socket_path);
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 CFErrorRef err = NULL; 436 CFErrorRef err = NULL;
437 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { 437 if (!Launchd::GetInstance()->RemoveJob(label, &err)) {
438 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err); 438 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err);
439 DLOG(ERROR) << "RemoveJob " << err; 439 DLOG(ERROR) << "RemoveJob " << err;
440 // Exiting with zero, so launchd doesn't restart the process. 440 // Exiting with zero, so launchd doesn't restart the process.
441 exit(0); 441 exit(0);
442 } 442 }
443 } 443 }
444 } 444 }
445 } 445 }
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_linux.cc ('k') | chrome/common/service_process_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698