1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_options.h"
10 #include "native_client/src/include/nacl_string.h"
14 nacl::string
ReplaceBadFSChars(nacl::string str
,
15 const nacl::string
& bad_chars
,
16 const nacl::string
& replacement
) {
17 size_t replace_pos
= str
.find_first_of(bad_chars
);
18 while (replace_pos
!= nacl::string::npos
) {
19 str
= str
.replace(replace_pos
, 1, replacement
);
20 replace_pos
= str
.find_first_of(bad_chars
);
29 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(2) { }
31 PnaclOptions::~PnaclOptions() {
34 nacl::string
PnaclOptions::GetCacheKey() const {
35 // TODO(jvoung): We need to read the PNaCl translator's manifest
36 // to grab the NaCl / PNaCl ABI version too.
37 nacl::stringstream ss
;
38 // Cast opt_level_ as int so that it doesn't think it's a char.
39 ss
<< "-O:" << static_cast<int>(opt_level_
)
40 << ";cache_validators:" << cache_validators_
;
41 // HTML5 FileSystem-based cache does not allow some characters which
42 // may appear in URLs, ETags, or Last-Modified times. Once we move to
43 // our own cache-backend, it will be more tolerant of various cache
45 // See: http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restrictions
46 nacl::string key
= ss
.str();
47 key
= ReplaceBadFSChars(key
, "/", "_FWDSLASH_");
48 key
= ReplaceBadFSChars(key
, "\\", "_BCKSLASH_");
49 key
= ReplaceBadFSChars(key
, "\0", "_NULL_");
53 void PnaclOptions::set_opt_level(int32_t l
) {
58 // Currently only allow 0 or 2, since that is what we test.
62 std::vector
<char> PnaclOptions::GetOptCommandline() const {
63 std::vector
<char> result
;
66 nacl::stringstream ss
;
67 ss
<< "-O" << opt_level_
;
70 std::copy(str
.begin(), str
.end(), std::back_inserter(result
));
71 result
.push_back('\x00');