Chromium Code Reviews| 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 nacl { | |
| 24 struct PnaclCacheInfo; | |
| 25 } | |
| 26 | |
| 27 namespace net { | |
| 28 class DrainableIOBuffer; | |
| 29 } | |
| 30 | |
| 23 namespace pnacl { | 31 namespace pnacl { |
| 24 typedef base::Callback<void(int)> CompletionCallback; | 32 typedef base::Callback<void(int)> CompletionCallback; |
| 33 typedef base::Callback<void(int, scoped_refptr<net::DrainableIOBuffer>)> | |
| 34 NexeCallback; | |
|
jvoung (off chromium)
2013/07/30 22:51:39
Could this be named something like GetNexeCallback
Derek Schuff
2013/07/31 00:04:16
Done.
| |
| 25 class PnaclTranslationCacheEntry; | 35 class PnaclTranslationCacheEntry; |
| 26 extern const int kMaxMemCacheSize; | 36 extern const int kMaxMemCacheSize; |
| 27 | 37 |
| 28 class PnaclTranslationCache | 38 class PnaclTranslationCache |
| 29 : public base::SupportsWeakPtr<PnaclTranslationCache> { | 39 : public base::SupportsWeakPtr<PnaclTranslationCache> { |
| 30 public: | 40 public: |
| 31 PnaclTranslationCache(); | 41 PnaclTranslationCache(); |
| 32 virtual ~PnaclTranslationCache(); | 42 virtual ~PnaclTranslationCache(); |
| 33 | 43 |
| 34 // Initialize the translation cache in |cache_dir| (or in memory if | 44 // 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 | 45 // |in_memory| is true). Call |callback| with a 0 argument on sucess and |
| 36 // <0 otherwise. | 46 // <0 otherwise. |
| 37 int InitCache(const base::FilePath& cache_dir, | 47 int InitCache(const base::FilePath& cache_dir, |
| 38 bool in_memory, | 48 bool in_memory, |
| 39 const CompletionCallback& callback); | 49 const CompletionCallback& callback); |
| 40 | 50 |
| 41 // Store the nexe in the translation cache. | 51 // Store the nexe in the translation cache. A reference to |nexe_data| is |
| 42 void StoreNexe(const std::string& key, const std::string& nexe); | 52 // held until completion or cancellation. |
| 53 void StoreNexe(const std::string& key, net::DrainableIOBuffer* nexe_data); | |
| 43 | 54 |
| 44 // Store the nexe in the translation cache, and call |callback| with | 55 // 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 | 56 // the result. The result passed to the callback is 0 on success and |
| 46 // <0 otherwise. | 57 // <0 otherwise. A reference to |nexe_data| is held until completion |
| 58 // or cancellation. | |
| 47 void StoreNexe(const std::string& key, | 59 void StoreNexe(const std::string& key, |
| 48 const std::string& nexe, | 60 net::DrainableIOBuffer* nexe_data, |
| 49 const CompletionCallback& callback); | 61 const CompletionCallback& callback); |
| 50 | 62 |
| 51 // Retrieve the nexe from the translation cache. Write the data into |nexe| | 63 // 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) | 64 // and call |callback|, passing a result code (0 on success and <0 otherwise), |
| 53 void GetNexe(const std::string& key, | 65 // and a DrainableIOBuffer with the data. |
| 54 std::string* nexe, | 66 void GetNexe(const std::string& key, const NexeCallback& callback); |
| 55 const CompletionCallback& callback); | |
| 56 | 67 |
| 57 // Return the number of entries in the cache backend. | 68 // Return the number of entries in the cache backend. |
| 58 int Size(); | 69 int Size(); |
| 59 | 70 |
| 71 // Return the cache key for |info| | |
| 72 static std::string GetKey(const nacl::PnaclCacheInfo& info); | |
| 73 | |
| 60 private: | 74 private: |
| 61 friend class PnaclTranslationCacheEntry; | 75 friend class PnaclTranslationCacheEntry; |
| 76 friend class PnaclTranslationCacheTest; | |
| 62 // PnaclTranslationCacheEntry should only use the | 77 // PnaclTranslationCacheEntry should only use the |
| 63 // OpComplete and backend methods on PnaclTranslationCache. | 78 // OpComplete and backend methods on PnaclTranslationCache. |
| 64 void OpComplete(PnaclTranslationCacheEntry* entry); | 79 void OpComplete(PnaclTranslationCacheEntry* entry); |
| 65 disk_cache::Backend* backend() { return disk_cache_; } | 80 disk_cache::Backend* backend() { return disk_cache_; } |
| 66 | 81 |
| 67 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, | 82 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, |
| 68 int cache_size, | 83 int cache_size, |
| 69 const CompletionCallback& callback); | 84 const CompletionCallback& callback); |
| 70 | 85 |
| 71 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); | 86 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); |
| 72 | 87 |
| 73 int Init(net::CacheType, | 88 int Init(net::CacheType, |
| 74 const base::FilePath& directory, | 89 const base::FilePath& directory, |
| 75 int cache_size, | 90 int cache_size, |
| 76 const CompletionCallback& callback); | 91 const CompletionCallback& callback); |
| 77 | 92 |
| 78 void OnCreateBackendComplete(int rv); | 93 void OnCreateBackendComplete(int rv); |
| 79 | 94 |
| 80 disk_cache::Backend* disk_cache_; | 95 disk_cache::Backend* disk_cache_; |
| 81 CompletionCallback init_callback_; | 96 CompletionCallback init_callback_; |
| 82 bool in_memory_; | 97 bool in_memory_; |
| 83 std::map<void*, scoped_refptr<PnaclTranslationCacheEntry> > open_entries_; | 98 std::map<void*, scoped_refptr<PnaclTranslationCacheEntry> > open_entries_; |
| 84 | 99 |
| 85 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationCache); | 100 DISALLOW_COPY_AND_ASSIGN(PnaclTranslationCache); |
| 86 }; | 101 }; |
| 87 | 102 |
| 88 } // namespace pnacl | 103 } // namespace pnacl |
| 89 | 104 |
| 90 #endif // CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ | 105 #endif // CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_ |
| OLD | NEW |