OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/nacl/browser/nacl_browser.h" | 5 #include "components/nacl/browser/nacl_browser.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_proxy.h" | 9 #include "base/files/file_proxy.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace { | 21 namespace { |
22 | 22 |
23 // An arbitrary delay to coalesce multiple writes to the cache. | 23 // An arbitrary delay to coalesce multiple writes to the cache. |
24 const int kValidationCacheCoalescingTimeMS = 6000; | 24 const int kValidationCacheCoalescingTimeMS = 6000; |
25 const char kValidationCacheSequenceName[] = "NaClValidationCache"; | 25 const char kValidationCacheSequenceName[] = "NaClValidationCache"; |
26 const base::FilePath::CharType kValidationCacheFileName[] = | 26 const base::FilePath::CharType kValidationCacheFileName[] = |
27 FILE_PATH_LITERAL("nacl_validation_cache.bin"); | 27 FILE_PATH_LITERAL("nacl_validation_cache.bin"); |
28 | 28 |
29 const bool kValidationCacheEnabledByDefault = true; | 29 const bool kValidationCacheEnabledByDefault = true; |
30 | 30 |
31 enum ValidationCacheStatus { | |
32 CACHE_MISS = 0, | |
33 CACHE_HIT, | |
34 CACHE_MAX | |
35 }; | |
36 | |
37 // Keep the cache bounded to an arbitrary size. If it's too small, useful | 31 // Keep the cache bounded to an arbitrary size. If it's too small, useful |
38 // entries could be evicted when multiple .nexes are loaded at once. On the | 32 // entries could be evicted when multiple .nexes are loaded at once. On the |
39 // other hand, entries are not always claimed (and hence removed), so the size | 33 // other hand, entries are not always claimed (and hence removed), so the size |
40 // of the cache will likely saturate at its maximum size. | 34 // of the cache will likely saturate at its maximum size. |
41 // Entries may not be claimed for two main reasons. 1) the NaCl process could | 35 // Entries may not be claimed for two main reasons. 1) the NaCl process could |
42 // be killed while it is loading. 2) the trusted NaCl plugin opens files using | 36 // be killed while it is loading. 2) the trusted NaCl plugin opens files using |
43 // the code path but doesn't resolve them. | 37 // the code path but doesn't resolve them. |
44 // TODO(ncbray) don't cache files that the plugin will not resolve. | 38 // TODO(ncbray) don't cache files that the plugin will not resolve. |
45 const int kFilePathCacheSize = 100; | 39 const int kFilePathCacheSize = 100; |
46 | 40 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 pickle->size()); | 87 pickle->size()); |
94 } | 88 } |
95 | 89 |
96 void RemoveCache(const base::FilePath& filename, | 90 void RemoveCache(const base::FilePath& filename, |
97 const base::Closure& callback) { | 91 const base::Closure& callback) { |
98 base::DeleteFile(filename, false); | 92 base::DeleteFile(filename, false); |
99 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, | 93 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, |
100 callback); | 94 callback); |
101 } | 95 } |
102 | 96 |
103 void LogCacheQuery(ValidationCacheStatus status) { | 97 void LogCacheQuery(nacl::NaClBrowser::ValidationCacheStatus status) { |
104 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Query", status, CACHE_MAX); | 98 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Query", status, |
| 99 nacl::NaClBrowser::CACHE_MAX); |
105 } | 100 } |
106 | 101 |
107 void LogCacheSet(ValidationCacheStatus status) { | 102 void LogCacheSet(nacl::NaClBrowser::ValidationCacheStatus status) { |
108 // Bucket zero is reserved for future use. | 103 // Bucket zero is reserved for future use. |
109 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, CACHE_MAX); | 104 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, |
| 105 nacl::NaClBrowser::CACHE_MAX); |
110 } | 106 } |
111 | 107 |
112 // Crash throttling parameters. | 108 // Crash throttling parameters. |
113 const size_t kMaxCrashesPerInterval = 3; | 109 const size_t kMaxCrashesPerInterval = 3; |
114 const int64 kCrashesIntervalInSeconds = 120; | 110 const int64 kCrashesIntervalInSeconds = 120; |
115 | 111 |
116 } // namespace | 112 } // namespace |
117 | 113 |
118 namespace nacl { | 114 namespace nacl { |
119 | 115 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 bool NaClBrowser::IsThrottled() { | 554 bool NaClBrowser::IsThrottled() { |
559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 555 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
560 if (crash_times_.size() != kMaxCrashesPerInterval) { | 556 if (crash_times_.size() != kMaxCrashesPerInterval) { |
561 return false; | 557 return false; |
562 } | 558 } |
563 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); | 559 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); |
564 return delta.InSeconds() <= kCrashesIntervalInSeconds; | 560 return delta.InSeconds() <= kCrashesIntervalInSeconds; |
565 } | 561 } |
566 | 562 |
567 } // namespace nacl | 563 } // namespace nacl |
OLD | NEW |