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 PNaClTranslationCacheWriteEntry; | 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. (Not implemented yet.) | 51 // Retrieve the nexe from the translation cache. Write the data into |nexe| |
52 int GetNexe(const std::string& key, | 52 // and call |callback| with the result (0 on success and <0 otherwise) |
53 std::string* nexe, | 53 void GetNexe(const std::string& key, |
54 const CompletionCallback& callback); | 54 std::string* nexe, |
55 const CompletionCallback& callback); | |
55 | 56 |
56 // Return the number of entries in the cache backend. | 57 // Return the number of entries in the cache backend. |
57 int Size(); | 58 int Size(); |
58 | 59 |
59 private: | 60 private: |
60 friend class PNaClTranslationCacheWriteEntry; | 61 friend class PNaClTranslationCacheEntry; |
61 // PNaClTranslationCacheWriteEntry should only use the | 62 // PNaClTranslationCacheEntry should only use the |
62 // WriteComplete and backend methods on PNaClTranslationCache. | 63 // OpComplete and backend methods on PNaClTranslationCache. |
63 void WriteComplete(PNaClTranslationCacheWriteEntry* entry); | 64 void OpComplete(PNaClTranslationCacheEntry* entry); |
64 disk_cache::Backend* backend() { return disk_cache_; } | 65 disk_cache::Backend* backend() { return disk_cache_; } |
65 | 66 |
66 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, | 67 int InitWithDiskBackend(const base::FilePath& disk_cache_dir, |
67 int cache_size, | 68 int cache_size, |
68 const CompletionCallback& callback); | 69 const CompletionCallback& callback); |
69 | 70 |
70 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); | 71 int InitWithMemBackend(int cache_size, const CompletionCallback& callback); |
71 | 72 |
72 int Init(net::CacheType, | 73 int Init(net::CacheType, |
73 const base::FilePath& directory, | 74 const base::FilePath& directory, |
74 int cache_size, | 75 int cache_size, |
75 const CompletionCallback& callback); | 76 const CompletionCallback& callback); |
76 | 77 |
77 void OnCreateBackendComplete(int rv); | 78 void OnCreateBackendComplete(int rv); |
78 | 79 |
79 disk_cache::Backend* disk_cache_; | 80 disk_cache::Backend* disk_cache_; |
80 CompletionCallback init_callback_; | 81 CompletionCallback init_callback_; |
81 bool in_memory_; | 82 bool in_memory_; |
82 std::map<void*, scoped_refptr<PNaClTranslationCacheWriteEntry> > | 83 std::map<void*, scoped_refptr<PNaClTranslationCacheEntry> > write_entries_; |
jvoung (off chromium)
2013/06/05 00:42:28
Should probably rename this from write_entries to
Derek Schuff
2013/06/05 05:01:59
Done.
| |
83 write_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 |