Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/nacl_host/pnacl_translation_cache.h

Issue 16232011: Add PNaCl translation cache based on Chrome disk_cache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build, disable_nacl=1, clang build Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_
6 #define CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_
7
8 #include <map>
9
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h"
13 #include "net/base/cache_type.h"
14
15 namespace base {
16 class MessageLoopProxy;
17 }
18
19 namespace disk_cache {
20 class Backend;
21 }
22
23 namespace pnacl_cache {
24 typedef base::Callback<void(int)> CompletionCallback;
25 class PNaClTranslationCacheWriteEntry;
26 extern const int kMaxMemCacheSize;
27
28 class PNaClTranslationCache
29 : public base::SupportsWeakPtr<PNaClTranslationCache> {
30 public:
31 PNaClTranslationCache();
32 virtual ~PNaClTranslationCache();
33
34 // Initialize the translation cache in cache_dir (or in memory if in_memory
35 // is true). Call callback with a 0 argument on sucess and <0 otherwise.
36 int InitCache(const base::FilePath& cache_dir,
37 bool in_memory,
38 const CompletionCallback& callback);
39
40 // Store the nexe in the translation cache.
41 void StoreNexe(const std::string& key, const std::string& nexe);
42 // Store the nexe in the translation cache, and call the callback with
43 // the result. The result passed to the callback is 0 on success and
44 // <0 otherwise.
45 void StoreNexe(const std::string& key,
46 const std::string& nexe,
47 const CompletionCallback& callback);
48 // Retrieve the nexe from the translation cache. (Not implemented yet.)
49 int GetNexe(const std::string& key,
50 std::string* nexe,
51 const CompletionCallback& callback);
52 // Return the number of entries in the cache backend.
53 int Size();
54
55 private:
56 friend class PNaClTranslationCacheWriteEntry;
57 // PNaClTranslationCacheWriteEntry should only use the
58 // WriteComplete and backend methods on PNaClTranslationCache.
59 void WriteComplete(PNaClTranslationCacheWriteEntry* entry);
60 disk_cache::Backend* backend() { return disk_cache_; }
61
62 int InitWithDiskBackend(const base::FilePath& disk_cache_dir,
63 int cache_size,
64 const CompletionCallback& callback);
65
66 int InitWithMemBackend(int cache_size, const CompletionCallback& callback);
67
68 int Init(net::CacheType,
69 const base::FilePath& directory,
70 int cache_size,
71 const CompletionCallback& callback);
72
73 void OnCreateBackendComplete(int rv);
74
75 disk_cache::Backend* disk_cache_;
76 CompletionCallback init_callback_;
77 bool in_memory_;
78 std::map<void*, scoped_refptr<PNaClTranslationCacheWriteEntry> >
79 write_entries_;
80
81 DISALLOW_COPY_AND_ASSIGN(PNaClTranslationCache);
82 };
83
84 } // namespace pnacl_cache
85
86 #endif // CHROME_BROWSER_NACL_HOST_PNACL_TRANSLATION_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698