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

Side by Side Diff: base/mac_util.mm

Issue 333008: Mac: Implement about:memory. (Closed)
Patch Set: Merged ToT. Created 11 years, 1 month 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
« no previous file with comments | « base/mac_util.h ('k') | base/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) 2008-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008-2009 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_util.h" 5 #include "base/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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void ActivateProcess(pid_t pid) { 181 void ActivateProcess(pid_t pid) {
182 ProcessSerialNumber process; 182 ProcessSerialNumber process;
183 OSStatus status = GetProcessForPID(pid, &process); 183 OSStatus status = GetProcessForPID(pid, &process);
184 if (status == noErr) { 184 if (status == noErr) {
185 SetFrontProcess(&process); 185 SetFrontProcess(&process);
186 } else { 186 } else {
187 LOG(WARNING) << "Unable to get process for pid " << pid; 187 LOG(WARNING) << "Unable to get process for pid " << pid;
188 } 188 }
189 } 189 }
190 190
191 // Takes a path to an (executable) binary and tries to provide the path to an
192 // application bundle containing it. It takes the outermost bundle that it can
193 // find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app").
194 // |exec_name| - path to the binary
195 // returns - path to the application bundle, or empty on error
196 FilePath GetAppBundlePath(const FilePath& exec_name) {
197 const char kExt[] = ".app";
198 const size_t kExtLength = arraysize(kExt) - 1;
199
200 // Split the path into components.
201 std::vector<std::string> components;
202 exec_name.GetComponents(&components);
203
204 // It's an error if we don't get any components.
205 if (!components.size())
206 return FilePath();
207
208 // Don't prepend '/' to the first component.
209 std::vector<std::string>::const_iterator it = components.begin();
210 std::string bundle_name = *it;
211 DCHECK(it->length() > 0);
212 // If the first component ends in ".app", we're already done.
213 if (it->length() > kExtLength &&
214 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
215 return FilePath(bundle_name);
216
217 // The first component may be "/" or "//", etc. Only append '/' if it doesn't
218 // already end in '/'.
219 if (bundle_name[bundle_name.length() - 1] != '/')
220 bundle_name += '/';
221
222 // Go through the remaining components.
223 for (++it; it != components.end(); ++it) {
224 DCHECK(it->length() > 0);
225
226 bundle_name += *it;
227
228 // If the current component ends in ".app", we're done.
229 if (it->length() > kExtLength &&
230 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
231 return FilePath(bundle_name);
232
233 // Separate this component from the next one.
234 bundle_name += '/';
235 }
236
237 return FilePath();
238 }
239
191 } // namespace mac_util 240 } // namespace mac_util
OLDNEW
« no previous file with comments | « base/mac_util.h ('k') | base/mac_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698