| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/nacl_host/nacl_browser.h" | 5 #include "chrome/browser/nacl_host/nacl_browser.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 11 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/chrome_paths_internal.h" | 15 #include "chrome/common/chrome_paths_internal.h" |
| 16 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 // An arbitrary delay to coalesce multiple writes to the cache. | 21 // An arbitrary delay to coalesce multiple writes to the cache. |
| 20 const int kValidationCacheCoalescingTimeMS = 6000; | 22 const int kValidationCacheCoalescingTimeMS = 6000; |
| 21 const char kValidationCacheSequenceName[] = "NaClValidationCache"; | 23 const char kValidationCacheSequenceName[] = "NaClValidationCache"; |
| 22 const FilePath::CharType kValidationCacheFileName[] = | 24 const FilePath::CharType kValidationCacheFileName[] = |
| 23 FILE_PATH_LITERAL("nacl_validation_cache.bin"); | 25 FILE_PATH_LITERAL("nacl_validation_cache.bin"); |
| 24 | 26 |
| 25 const bool kValidationCacheEnabledByDefault = true; | 27 const bool kValidationCacheEnabledByDefault = true; |
| 26 | 28 |
| 27 enum ValidationCacheStatus { | 29 enum ValidationCacheStatus { |
| 28 CACHE_MISS = 0, | 30 CACHE_MISS = 0, |
| 29 CACHE_HIT, | 31 CACHE_HIT, |
| 30 CACHE_MAX | 32 CACHE_MAX |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 // Determine the name of the IRT file based on the architecture. | 35 const FilePath::StringType NaClIrtName() { |
| 34 #define NACL_IRT_FILE_NAME(arch_string) \ | 36 FilePath::StringType irt_name; |
| 35 (FILE_PATH_LITERAL("nacl_irt_") \ | 37 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 36 FILE_PATH_LITERAL(arch_string) \ | 38 switches::kEnableNaClIPCProxy)) |
| 37 FILE_PATH_LITERAL(".nexe")) | 39 irt_name.append(FILE_PATH_LITERAL("nacl_ipc_irt_")); |
| 40 else |
| 41 irt_name.append(FILE_PATH_LITERAL("nacl_irt_")); |
| 38 | 42 |
| 39 const FilePath::StringType NaClIrtName() { | |
| 40 #if defined(ARCH_CPU_X86_FAMILY) | 43 #if defined(ARCH_CPU_X86_FAMILY) |
| 41 #if defined(ARCH_CPU_X86_64) | 44 #if defined(ARCH_CPU_X86_64) |
| 42 bool is64 = true; | 45 bool is64 = true; |
| 43 #elif defined(OS_WIN) | 46 #elif defined(OS_WIN) |
| 44 bool is64 = (base::win::OSInfo::GetInstance()->wow64_status() == | 47 bool is64 = (base::win::OSInfo::GetInstance()->wow64_status() == |
| 45 base::win::OSInfo::WOW64_ENABLED); | 48 base::win::OSInfo::WOW64_ENABLED); |
| 46 #else | 49 #else |
| 47 bool is64 = false; | 50 bool is64 = false; |
| 48 #endif | 51 #endif |
| 49 return is64 ? NACL_IRT_FILE_NAME("x86_64") : NACL_IRT_FILE_NAME("x86_32"); | 52 if (is64) |
| 53 irt_name.append(FILE_PATH_LITERAL("x86_64")); |
| 54 else |
| 55 irt_name.append(FILE_PATH_LITERAL("x86_32")); |
| 56 |
| 50 #elif defined(ARCH_CPU_ARMEL) | 57 #elif defined(ARCH_CPU_ARMEL) |
| 51 // TODO(mcgrathr): Eventually we'll need to distinguish arm32 vs thumb2. | 58 // TODO(mcgrathr): Eventually we'll need to distinguish arm32 vs thumb2. |
| 52 // That may need to be based on the actual nexe rather than a static | 59 // That may need to be based on the actual nexe rather than a static |
| 53 // choice, which would require substantial refactoring. | 60 // choice, which would require substantial refactoring. |
| 54 return NACL_IRT_FILE_NAME("arm"); | 61 irt_name.append(FILE_PATH_LITERAL("arm")); |
| 55 #else | 62 #else |
| 56 #error Add support for your architecture to NaCl IRT file selection | 63 #error Add support for your architecture to NaCl IRT file selection |
| 57 #endif | 64 #endif |
| 65 irt_name.append(FILE_PATH_LITERAL(".nexe")); |
| 66 return irt_name; |
| 58 } | 67 } |
| 59 | 68 |
| 60 bool CheckEnvVar(const char* name, bool default_value) { | 69 bool CheckEnvVar(const char* name, bool default_value) { |
| 61 bool result = default_value; | 70 bool result = default_value; |
| 62 const char* var = getenv(name); | 71 const char* var = getenv(name); |
| 63 if (var && strlen(var) > 0) { | 72 if (var && strlen(var) > 0) { |
| 64 result = var[0] != '0'; | 73 result = var[0] != '0'; |
| 65 } | 74 } |
| 66 return result; | 75 return result; |
| 67 } | 76 } |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // because it can degrade the responsiveness of the browser. | 397 // because it can degrade the responsiveness of the browser. |
| 389 // The task is sequenced so that multiple writes happen in order. | 398 // The task is sequenced so that multiple writes happen in order. |
| 390 content::BrowserThread::PostBlockingPoolSequencedTask( | 399 content::BrowserThread::PostBlockingPoolSequencedTask( |
| 391 kValidationCacheSequenceName, | 400 kValidationCacheSequenceName, |
| 392 FROM_HERE, | 401 FROM_HERE, |
| 393 base::Bind(WriteCache, validation_cache_file_path_, | 402 base::Bind(WriteCache, validation_cache_file_path_, |
| 394 base::Owned(pickle))); | 403 base::Owned(pickle))); |
| 395 } | 404 } |
| 396 validation_cache_is_modified_ = false; | 405 validation_cache_is_modified_ = false; |
| 397 } | 406 } |
| OLD | NEW |