| 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 #ifndef CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ | 5 #ifndef CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ |
| 6 #define CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ | 6 #define CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "net/base/cache_type.h" | 13 #include "net/base/cache_type.h" |
| 14 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class MessageLoopProxy; | 16 class MessageLoopProxy; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace disk_cache { | 19 namespace disk_cache { |
| 20 class Backend; | 20 class Backend; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace pnacl_cache { | 23 namespace pnacl_cache { |
| 24 typedef base::Callback<void(int)> CompletionCallback; | 24 typedef base::Callback<void(int)> CompletionCallback; |
| 25 class PNaClTranslationCacheEntry; | 25 class PnaclTranslationCacheEntry; |
| 26 extern const int kMaxMemCacheSize; | 26 extern const int kMaxMemCacheSize; |
| 27 | 27 |
| 28 class PNaClTranslationCache | 28 class PnaclTranslationCache |
| 29 : public base::SupportsWeakPtr<PNaClTranslationCache> { | 29 : public base::SupportsWeakPtr<PnaclTranslationCache> { |
| 30 public: | 30 public: |
| 31 PNaClTranslationCache(); | 31 PnaclTranslationCache(); |
| 32 virtual ~PNaClTranslationCache(); | 32 virtual ~PnaclTranslationCache(); |
| 33 | 33 |
| 34 // Initialize the translation cache in |cache_dir| (or in memory if | 34 // Initialize the translation cache in |cache_dir| (or in memory if |
| 35 // |in_memory| is true). Call |callback| with a 0 argument on sucess and | 35 // |in_memory| is true). Call |callback| with a 0 argument on sucess and |
| 36 // <0 otherwise. | 36 // <0 otherwise. |
| 37 int InitCache(const base::FilePath& cache_dir, | 37 int InitCache(const base::FilePath& cache_dir, |
| 38 bool in_memory, | 38 bool in_memory, |
| 39 const CompletionCallback& callback); | 39 const CompletionCallback& callback); |
| 40 | 40 |
| 41 // Store the nexe in the translation cache. | 41 // Store the nexe in the translation cache. |
| 42 void StoreNexe(const std::string& key, const std::string& nexe); | 42 void StoreNexe(const std::string& key, const std::string& nexe); |
| 43 | 43 |
| 44 // Store the nexe in the translation cache, and call |callback| with | 44 // Store the nexe in the translation cache, and call |callback| with |
| 45 // the result. The result passed to the callback is 0 on success and | 45 // the result. The result passed to the callback is 0 on success and |
| 46 // <0 otherwise. | 46 // <0 otherwise. |
| 47 void StoreNexe(const std::string& key, | 47 void StoreNexe(const std::string& key, |
| 48 const std::string& nexe, | 48 const std::string& nexe, |
| 49 const CompletionCallback& callback); | 49 const CompletionCallback& callback); |
| 50 | 50 |
| 51 // Retrieve the nexe from the translation cache. Write the data into |nexe| | 51 // Retrieve the nexe from the translation cache. Write the data into |nexe| |
| 52 // and call |callback| with the result (0 on success and <0 otherwise) | 52 // and call |callback| with the result (0 on success and <0 otherwise) |
| 53 void GetNexe(const std::string& key, | 53 void GetNexe(const std::string& key, |
| 54 std::string* nexe, | 54 std::string* nexe, |
| 55 const CompletionCallback& callback); | 55 const CompletionCallback& callback); |
| 56 | 56 |
| 57 // Return the number of entries in the cache backend. | 57 // Return the number of entries in the cache backend. |
| 58 int Size(); | 58 int Size(); |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 friend class PNaClTranslationCacheEntry; | 61 friend class PnaclTranslationCacheEntry; |
| 62 // PNaClTranslationCacheEntry should only use the | 62 // PnaclTranslationCacheEntry should only use the |
| 63 // OpComplete and backend methods on PNaClTranslationCache. | 63 // OpComplete and backend methods on PnaclTranslationCache. |
| 64 void OpComplete(PNaClTranslationCacheEntry* entry); | 64 void OpComplete(PnaclTranslationCacheEntry* entry); |
| 65 disk_cache::Backend* backend() { return disk_cache_; } | 65 disk_cache::Backend* backend() { return disk_cache_; } |
| 66 | 66 |
| 67 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, | 67 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, |
| 68 int cache_size, | 68 int cache_size, |
| 69 const CompletionCallback& callback); | 69 const CompletionCallback& callback); |
| 70 | 70 |
| 71 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); | 71 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); |
| 72 | 72 |
| 73 int Init(net::CacheType, | 73 int Init(net::CacheType, |
| 74 const base::FilePath& directory, | 74 const base::FilePath& directory, |
| 75 int cache_size, | 75 int cache_size, |
| 76 const CompletionCallback& callback); | 76 const CompletionCallback& callback); |
| 77 | 77 |
| 78 void OnCreateBackendComplete(int rv); | 78 void OnCreateBackendComplete(int rv); |
| 79 | 79 |
| 80 disk_cache::Backend* disk_cache_; | 80 disk_cache::Backend* disk_cache_; |
| 81 CompletionCallback init_callback_; | 81 CompletionCallback init_callback_; |
| 82 bool in_memory_; | 82 bool in_memory_; |
| 83 std::map<void*, scoped_refptr<PNaClTranslationCacheEntry> > open_entries_; | 83 std::map<void*, scoped_refptr<PnaclTranslationCacheEntry> > open_entries_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(PNaClTranslationCache); | 85 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationCache); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace pnacl_cache | 88 } // namespace pnacl_cache |
| 89 | 89 |
| 90 #endif // CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ | 90 #endif // CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ |
| OLD | NEW |