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

Side by Side Diff: chrome/plugin/plugin_main_mac.mm

Issue 3043018: base: Add UnSetEnv function to EnvVarGetter API. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chrome_application_mac.h" 5 #include "base/chrome_application_mac.h"
6 #include "base/env_var.h"
7 #include "base/scoped_ptr.h"
6 #include "base/string_util.h" 8 #include "base/string_util.h"
7 #include "chrome/common/plugin_carbon_interpose_constants_mac.h" 9 #include "chrome/common/plugin_carbon_interpose_constants_mac.h"
8 #include "chrome/plugin/plugin_interpose_util_mac.h" 10 #include "chrome/plugin/plugin_interpose_util_mac.h"
9 11
10 #if !defined(__LP64__) 12 #if !defined(__LP64__)
11 void TrimInterposeEnvironment() { 13 void TrimInterposeEnvironment() {
12 const char* interpose_list = 14 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
13 getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey); 15
14 if (!interpose_list) { 16 std::string interpose_list;
17 if (!env->GetEnv(plugin_interpose_strings::kDYLDInsertLibrariesKey,
18 &interpose_list)) {
15 NOTREACHED() << "No interposing libraries set"; 19 NOTREACHED() << "No interposing libraries set";
16 return; 20 return;
17 } 21 }
18 22
19 // The list is a :-separated list of paths. Because we append our interpose 23 // The list is a :-separated list of paths. Because we append our interpose
20 // library just before forking in plugin_process_host.cc, the only cases we 24 // library just before forking in plugin_process_host.cc, the only cases we
21 // need to handle are: 25 // need to handle are:
22 // 1) The whole string is "<kInterposeLibraryPath>", so just clear it, or 26 // 1) The whole string is "<kInterposeLibraryPath>", so just clear it, or
23 // 2) ":<kInterposeLibraryPath>" is the end of the string, so trim and re-set. 27 // 2) ":<kInterposeLibraryPath>" is the end of the string, so trim and re-set.
24 int suffix_offset = strlen(interpose_list) - 28 int suffix_offset = strlen(interpose_list.c_str()) -
viettrungluu 2010/07/31 01:50:02 No, don't do strlen(foo.c_str()). std::string has
25 strlen(plugin_interpose_strings::kInterposeLibraryPath); 29 strlen(plugin_interpose_strings::kInterposeLibraryPath);
30
26 if (suffix_offset == 0 && 31 if (suffix_offset == 0 &&
27 strcmp(interpose_list, 32 strcmp(interpose_list.c_str(),
28 plugin_interpose_strings::kInterposeLibraryPath) == 0) { 33 plugin_interpose_strings::kInterposeLibraryPath) == 0) {
29 unsetenv(plugin_interpose_strings::kDYLDInsertLibrariesKey); 34 env->UnSetEnv(plugin_interpose_strings::kDYLDInsertLibrariesKey);
30 } else if (suffix_offset > 0 && interpose_list[suffix_offset - 1] == ':' && 35 } else if (suffix_offset > 0 && interpose_list[suffix_offset - 1] == ':' &&
31 strcmp(interpose_list + suffix_offset, 36 strcmp(interpose_list.c_str() + suffix_offset,
viettrungluu 2010/07/31 01:50:02 You shouldn't do foo.c_str() + n either. There's a
32 plugin_interpose_strings::kInterposeLibraryPath) == 0) { 37 plugin_interpose_strings::kInterposeLibraryPath) == 0) {
33 std::string trimmed_list = 38 std::string trimmed_list = interpose_list.substr(0, suffix_offset - 1);
34 std::string(interpose_list).substr(0, suffix_offset - 1); 39 env->SetEnv(plugin_interpose_strings::kDYLDInsertLibrariesKey,
35 setenv(plugin_interpose_strings::kDYLDInsertLibrariesKey, 40 trimmed_list.c_str());
36 trimmed_list.c_str(), 1);
37 } else { 41 } else {
38 NOTREACHED() << "Missing Carbon interposing library"; 42 NOTREACHED() << "Missing Carbon interposing library";
39 } 43 }
40 } 44 }
41 #endif 45 #endif
42 46
43 void InitializeChromeApplication() { 47 void InitializeChromeApplication() {
44 [CrApplication sharedApplication]; 48 [CrApplication sharedApplication];
45 49
46 mac_plugin_interposing::SetUpCocoaInterposing(); 50 mac_plugin_interposing::SetUpCocoaInterposing();
47 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698