cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / native_client / src / trusted / plugin / pnacl_options.cc
blob0e684bb58e15f9ddef53ff21df317f6381b74663
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"
7 #include <iterator>
8 #include <vector>
10 #include "native_client/src/include/nacl_string.h"
12 namespace {
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);
22 return str;
25 } // namespace
27 namespace plugin {
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
44 // key values.
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_");
50 return key;
53 void PnaclOptions::set_opt_level(int32_t l) {
54 if (l <= 0) {
55 opt_level_ = 0;
56 return;
58 // Currently only allow 0 or 2, since that is what we test.
59 opt_level_ = 2;
62 std::vector<char> PnaclOptions::GetOptCommandline() const {
63 std::vector<char> result;
64 nacl::string str;
66 nacl::stringstream ss;
67 ss << "-O" << opt_level_;
68 str = ss.str();
70 std::copy(str.begin(), str.end(), std::back_inserter(result));
71 result.push_back('\x00');
73 return result;
76 } // namespace plugin