summaryrefslogtreecommitdiffstats
path: root/sandbox/src/process_policy_test.cc
diff options
context:
space:
mode:
authornsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-23 21:57:10 +0000
committernsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-23 21:57:10 +0000
commite26092ee0313c209ecfc13adf4015d55a4eb38db (patch)
tree7d339472915c816af4b06096ba35eb6d5f1bbd2b /sandbox/src/process_policy_test.cc
parent3b296845029d75743c4c434486cc55e5df196687 (diff)
downloadchromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.zip
chromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.tar.gz
chromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.tar.bz2
Move a function from controller.cc to sandbox_utils.cc in
preparation for the refactoring. Review URL: http://codereview.chromium.org/16225 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/src/process_policy_test.cc')
-rw-r--r--sandbox/src/process_policy_test.cc37
1 files changed, 5 insertions, 32 deletions
diff --git a/sandbox/src/process_policy_test.cc b/sandbox/src/process_policy_test.cc
index a156c6e..f3011b7 100644
--- a/sandbox/src/process_policy_test.cc
+++ b/sandbox/src/process_policy_test.cc
@@ -5,44 +5,16 @@
#include <string>
#include <memory>
-#include "base/scoped_handle.h"
+#include "base/scoped_handle_win.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "sandbox/src/sandbox.h"
#include "sandbox/src/sandbox_policy.h"
#include "sandbox/src/sandbox_factory.h"
+#include "sandbox/src/sandbox_utils.h"
#include "sandbox/tests/common/controller.h"
namespace {
-// The next 2 functions are copied from base\string_util.h and have been
-// slighty modified because we don't want to depend on ICU.
-template <class char_type>
-inline char_type* WriteInto(
- std::basic_string<char_type, std::char_traits<char_type>,
- std::allocator<char_type> >* str,
- size_t length_including_null) {
- str->reserve(length_including_null);
- str->resize(length_including_null - 1);
- return &((*str)[0]);
-}
-
-std::string WideToMultiByte(const std::wstring& wide) {
- if (wide.length() == 0)
- return std::string();
-
- // compute the length of the buffer we'll need
- int charcount = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1,
- NULL, 0, NULL, NULL);
- if (charcount == 0)
- return std::string();
-
- std::string mb;
- WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1,
- WriteInto(&mb, charcount), charcount, NULL, NULL);
-
- return mb;
-}
-
// While the shell API provides better calls than this home brew function
// we use GetSystemWindowsDirectoryW which does not query the registry so
// it is safe to use after revert.
@@ -93,9 +65,10 @@ sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe,
STARTUPINFOA sia = {sizeof(sia)};
sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED;
+ std::string narrow_cmd_line = sandbox::WideToMultiByte(cmd_line);
if (!::CreateProcessA(
- exe_name ? WideToMultiByte(exe_name).c_str() : NULL,
- cmd_line ? const_cast<char*>(WideToMultiByte(cmd_line).c_str()) : NULL,
+ exe_name ? sandbox::WideToMultiByte(exe_name).c_str() : NULL,
+ cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL,
NULL, NULL, FALSE, 0, NULL, NULL, &sia, &pi)) {
DWORD last_error = GetLastError();
if ((ERROR_NOT_ENOUGH_QUOTA == last_error) ||