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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_options.cc

Issue 16569002: Use HTTP response headers for PNaCl caching instead of bitcode hash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify tst Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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 "native_client/src/trusted/plugin/pnacl_options.h" 5 #include "native_client/src/trusted/plugin/pnacl_options.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <vector> 8 #include <vector>
9 9
10 #include "native_client/src/include/nacl_string.h" 10 #include "native_client/src/include/nacl_string.h"
11 11
12 namespace {
13
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) {
Derek Schuff 2013/06/07 21:38:04 while (
jvoung (off chromium) 2013/06/07 23:46:25 Done.
19 str = str.replace(replace_pos, 1, replacement);
20 replace_pos = str.find_first_of(bad_chars);
21 }
22 return str;
23 }
24
25 } // namespace
26
12 namespace plugin { 27 namespace plugin {
13 28
14 // Default to -O0 for now. 29 // Default to -O0 for now.
15 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(0) { } 30 PnaclOptions::PnaclOptions() : translate_(false), opt_level_(0) { }
16 31
17 PnaclOptions::~PnaclOptions() { 32 PnaclOptions::~PnaclOptions() {
18 } 33 }
19 34
20 nacl::string PnaclOptions::GetCacheKey() { 35 nacl::string PnaclOptions::GetCacheKey() const {
21 // TODO(jvoung): We need to read the PNaCl translator's manifest 36 // TODO(jvoung): We need to read the PNaCl translator's manifest
22 // to grab the NaCl / PNaCl ABI version too. 37 // to grab the NaCl / PNaCl ABI version too.
23 nacl::stringstream ss; 38 nacl::stringstream ss;
24 // Cast opt_level_ as int so that it doesn't think it's a char. 39 // Cast opt_level_ as int so that it doesn't think it's a char.
25 ss << "-O:" << static_cast<int>(opt_level_) 40 ss << "-O:" << static_cast<int>(opt_level_)
26 << ";flags:" << experimental_flags_ 41 << ";flags:" << experimental_flags_
27 << ";bitcode_hash:" << bitcode_hash_; 42 << ";cache_validators:" << cache_validators_;
28 return ss.str(); 43 // HTML5 FileSystem-based cache does not some characters which may appear
Derek Schuff 2013/06/07 21:38:04 does not some?
jvoung (off chromium) 2013/06/07 23:46:25 Done.
44 // in URLs, ETags, or Last-Modified times. Once we move to our own
45 // cache-backend, hopefully it will be more tolerant of various cache
46 // key values.
47 // See: http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#naming-restri ctions
48 nacl::string key = ss.str();
49 key = ReplaceBadFSChars(key, "/", "_FWDSLASH_");
50 key = ReplaceBadFSChars(key, "\\", "_BCKSLASH_");
51 key = ReplaceBadFSChars(key, "\0", "_NULL_");
52 return key;
29 } 53 }
30 54
31 void PnaclOptions::set_opt_level(int8_t l) { 55 void PnaclOptions::set_opt_level(int8_t l) {
32 if (l < 0) { 56 if (l < 0) {
33 opt_level_ = 0; 57 opt_level_ = 0;
34 return; 58 return;
35 } 59 }
36 if (l > 3) { 60 if (l > 3) {
37 opt_level_ = 3; 61 opt_level_ = 3;
38 return; 62 return;
39 } 63 }
40 opt_level_ = l; 64 opt_level_ = l;
41 } 65 }
42 66
43 std::vector<char> PnaclOptions::GetOptCommandline() { 67 std::vector<char> PnaclOptions::GetOptCommandline() const {
44 std::vector<char> result; 68 std::vector<char> result;
45 std::vector<nacl::string> tokens; 69 std::vector<nacl::string> tokens;
46 70
47 // Split the experimental_flags_ + the -On along whitespace. 71 // Split the experimental_flags_ + the -On along whitespace.
48 // Mostly a copy of "base/string_util.h", but avoid importing 72 // Mostly a copy of "base/string_util.h", but avoid importing
49 // base into the PPAPI plugin for now. 73 // base into the PPAPI plugin for now.
50 nacl::string delim(" "); 74 nacl::string delim(" ");
51 nacl::string str = experimental_flags_; 75 nacl::string str = experimental_flags_;
52 76
53 if (opt_level_ != -1) { 77 if (opt_level_ != -1) {
(...skipping 19 matching lines...) Expand all
73 nacl::string t = tokens[i]; 97 nacl::string t = tokens[i];
74 result.reserve(result.size() + t.size()); 98 result.reserve(result.size() + t.size());
75 std::copy(t.begin(), t.end(), std::back_inserter(result)); 99 std::copy(t.begin(), t.end(), std::back_inserter(result));
76 result.push_back('\x00'); 100 result.push_back('\x00');
77 } 101 }
78 102
79 return result; 103 return result;
80 } 104 }
81 105
82 } // namespace plugin 106 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698