diff options
author | nduca@google.com <nduca@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 01:15:30 +0000 |
---|---|---|
committer | nduca@google.com <nduca@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 01:15:30 +0000 |
commit | 4a0141bbf9e39c67ea759dd7e565a6c615673761 (patch) | |
tree | 57264504dfd822dc30eae1b9ebdeaeead858405d /chrome/browser/nacl_host/nacl_process_host.cc | |
parent | 43cfea7b76f709f6b76db6930af4294d5ac15827 (diff) | |
download | chromium_src-4a0141bbf9e39c67ea759dd7e565a6c615673761.zip chromium_src-4a0141bbf9e39c67ea759dd7e565a6c615673761.tar.gz chromium_src-4a0141bbf9e39c67ea759dd7e565a6c615673761.tar.bz2 |
Reland - Create a database for NaCl validation caching that is shared between processes.
Originally reverted in 129077 due to perf regression. Followup commit will fix up expectations.
http://chromegw.corp.google.com/i/chromium/builders/Linux%20x64/builds/25780
This change primarily entails creating a SyncChannel between sel_ldr and the
browser. Queries to the database could be made from any thread inside sel_ldr,
so the query mechanism needs to be thread safe.
This feature is currently disabled by default, and requires an environment
variable to enable. A few changes need to be made before this features is safe
and can be enabled, such as making sure each installation has a unique,
crypographically secure key.
BUG= http://code.google.com/p/nativeclient/issues/detail?id=2515
TEST= Run NaCl w/ NACL_VALIDATION_CACHE=1
Review URL: http://codereview.chromium.org/9796006
TBR=ncbray@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9808113
TBR=nduca@google.com
Review URL: https://chromiumcodereview.appspot.com/9860020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/nacl_host/nacl_process_host.cc')
-rw-r--r-- | chrome/browser/nacl_host/nacl_process_host.cc | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc index e493752..c4c602e 100644 --- a/chrome/browser/nacl_host/nacl_process_host.cc +++ b/chrome/browser/nacl_host/nacl_process_host.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/command_line.h" +#include "base/memory/mru_cache.h" #include "base/memory/singleton.h" #include "base/path_service.h" #include "base/string_util.h" @@ -195,16 +196,27 @@ class NaClBrowser { // Path to IRT. Available even before IRT is loaded. const FilePath& GetIrtFilePath(); + // Is the validation signature in the database? + bool QueryKnownToValidate(const std::string& signature); + + // Put the validation signature in the database. + void SetKnownToValidate(const std::string& signature); + private: base::PlatformFile irt_platform_file_; FilePath irt_filepath_; + typedef base::HashingMRUCache<std::string, bool> ValidationCacheType; + ValidationCacheType validation_cache_; + friend struct DefaultSingletonTraits<NaClBrowser>; NaClBrowser() : irt_platform_file_(base::kInvalidPlatformFileValue), - irt_filepath_() { + irt_filepath_(), + // For the moment, choose an arbitrary cache size. + validation_cache_(200) { InitIrtFilePath(); } @@ -843,7 +855,42 @@ void NaClProcessHost::SendStart(base::PlatformFile irt_file) { internal_->sockets_for_sel_ldr.clear(); } +bool NaClBrowser::QueryKnownToValidate(const std::string& signature) { + ValidationCacheType::iterator iter = validation_cache_.Get(signature); + if (iter == validation_cache_.end()) { + // Not found. + return false; + } else { + return iter->second; + } +} + +void NaClBrowser::SetKnownToValidate(const std::string& signature) { + validation_cache_.Put(signature, true); +} + +void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature, + bool* result) { + *result = NaClBrowser::GetInstance()->QueryKnownToValidate(signature); +} + +void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { + NaClBrowser::GetInstance()->SetKnownToValidate(signature); +} + +// Needed to handle sync messages in OnMessageRecieved. +bool NaClProcessHost::Send(IPC::Message* msg) { + return process_->Send(msg); +} + bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { - NOTREACHED() << "Invalid message with type = " << msg.type(); - return false; + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) + IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, + OnQueryKnownToValidate) + IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, + OnSetKnownToValidate) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; } |