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

Unified Diff: content/common/sandbox_mac.mm

Issue 2581743002: Remove unnecessary NSString conversions in sandbox_mac.mm. (Closed)
Patch Set: Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/sandbox_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/sandbox_mac.mm
diff --git a/content/common/sandbox_mac.mm b/content/common/sandbox_mac.mm
index 9994f45136f3b244104e39ad990abda67b9ad8e7..ccfe86710257cc93502372c147b2c2ac4f940e46 100644
--- a/content/common/sandbox_mac.mm
+++ b/content/common/sandbox_mac.mm
@@ -359,8 +359,8 @@ void Sandbox::SandboxWarmup(int sandbox_type) {
}
// Load the appropriate template for the given sandbox type.
-// Returns the template as an NSString or nil on error.
-NSString* LoadSandboxTemplate(int sandbox_type) {
+// Returns the template as a string or an empty string on error.
+std::string LoadSandboxTemplate(int sandbox_type) {
// We use a custom sandbox definition to lock things down as tightly as
// possible.
int sandbox_profile_resource_id = -1;
@@ -390,7 +390,7 @@ NSString* LoadSandboxTemplate(int sandbox_type) {
if (sandbox_definition.empty()) {
LOG(FATAL) << "Failed to load the sandbox profile (resource id "
<< sandbox_profile_resource_id << ")";
- return nil;
+ return std::string();
}
base::StringPiece common_sandbox_definition =
@@ -398,21 +398,13 @@ NSString* LoadSandboxTemplate(int sandbox_type) {
IDR_COMMON_SANDBOX_PROFILE, ui::SCALE_FACTOR_NONE);
if (common_sandbox_definition.empty()) {
LOG(FATAL) << "Failed to load the common sandbox profile";
- return nil;
+ return std::string();
}
- base::scoped_nsobject<NSString> common_sandbox_prefix_data(
- [[NSString alloc] initWithBytes:common_sandbox_definition.data()
- length:common_sandbox_definition.length()
- encoding:NSUTF8StringEncoding]);
-
- base::scoped_nsobject<NSString> sandbox_data(
- [[NSString alloc] initWithBytes:sandbox_definition.data()
- length:sandbox_definition.length()
- encoding:NSUTF8StringEncoding]);
-
// Prefix sandbox_data with common_sandbox_prefix_data.
- return [common_sandbox_prefix_data stringByAppendingString:sandbox_data];
+ std::string sandbox_profile = common_sandbox_definition.as_string();
+ sandbox_definition.AppendToString(&sandbox_profile);
+ return sandbox_profile;
}
// Turns on the OS X sandbox for this process.
@@ -428,12 +420,12 @@ bool Sandbox::EnableSandbox(int sandbox_type,
<< "Only SANDBOX_TYPE_UTILITY allows a custom directory parameter.";
}
- NSString* sandbox_data = LoadSandboxTemplate(sandbox_type);
- if (!sandbox_data) {
+ std::string sandbox_data = LoadSandboxTemplate(sandbox_type);
+ if (sandbox_data.empty()) {
return false;
}
- SandboxCompiler compiler([sandbox_data UTF8String]);
+ SandboxCompiler compiler(sandbox_data);
if (!allowed_dir.empty()) {
// Add the sandbox parameters necessary to access the given directory.
« no previous file with comments | « content/common/sandbox_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698