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 COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ | 5 #ifndef COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ |
6 #define COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ | 6 #define COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 class PnaclHostTest; | 25 class PnaclHostTest; |
26 class PnaclHostTestDisk; | 26 class PnaclHostTestDisk; |
27 class PnaclTranslationCache; | 27 class PnaclTranslationCache; |
28 | 28 |
29 // Shared state (translation cache) and common utilities (temp file creation) | 29 // Shared state (translation cache) and common utilities (temp file creation) |
30 // for all PNaCl translations. Unless otherwise specified, all methods should be | 30 // for all PNaCl translations. Unless otherwise specified, all methods should be |
31 // called on the IO thread. | 31 // called on the IO thread. |
32 class PnaclHost { | 32 class PnaclHost { |
33 public: | 33 public: |
34 typedef base::Callback<void(base::File)> TempFileCallback; | 34 typedef base::Callback<void(base::File)> TempFileCallback; |
35 typedef base::Callback<void(base::PlatformFile, bool is_hit)> NexeFdCallback; | 35 typedef base::Callback<void(const base::File&, bool is_hit)> NexeFdCallback; |
36 | 36 |
37 static PnaclHost* GetInstance(); | 37 static PnaclHost* GetInstance(); |
38 | 38 |
39 PnaclHost(); | 39 PnaclHost(); |
40 ~PnaclHost(); | 40 ~PnaclHost(); |
41 | 41 |
42 // Initialize cache backend. GetNexeFd will also initialize the backend if | 42 // Initialize cache backend. GetNexeFd will also initialize the backend if |
43 // necessary, but calling Init ahead of time will minimize the latency. | 43 // necessary, but calling Init ahead of time will minimize the latency. |
44 void Init(); | 44 void Init(); |
45 | 45 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 const base::Closure& callback); | 95 const base::Closure& callback); |
96 | 96 |
97 // Return the number of tracked translations or FD requests currently pending. | 97 // Return the number of tracked translations or FD requests currently pending. |
98 size_t pending_translations() { return pending_translations_.size(); } | 98 size_t pending_translations() { return pending_translations_.size(); } |
99 | 99 |
100 private: | 100 private: |
101 // PnaclHost is a singleton because there is only one translation cache, and | 101 // PnaclHost is a singleton because there is only one translation cache, and |
102 // so that the BrowsingDataRemover can clear it even if no translation has | 102 // so that the BrowsingDataRemover can clear it even if no translation has |
103 // ever been started. | 103 // ever been started. |
104 friend struct DefaultSingletonTraits<PnaclHost>; | 104 friend struct DefaultSingletonTraits<PnaclHost>; |
| 105 friend class FileProxy; |
105 friend class pnacl::PnaclHostTest; | 106 friend class pnacl::PnaclHostTest; |
106 friend class pnacl::PnaclHostTestDisk; | 107 friend class pnacl::PnaclHostTestDisk; |
107 enum CacheState { | 108 enum CacheState { |
108 CacheUninitialized, | 109 CacheUninitialized, |
109 CacheInitializing, | 110 CacheInitializing, |
110 CacheReady | 111 CacheReady |
111 }; | 112 }; |
112 class PendingTranslation { | 113 class PendingTranslation { |
113 public: | 114 public: |
114 PendingTranslation(); | 115 PendingTranslation(); |
115 ~PendingTranslation(); | 116 ~PendingTranslation(); |
116 base::ProcessHandle process_handle; | 117 base::ProcessHandle process_handle; |
117 int render_view_id; | 118 int render_view_id; |
118 base::PlatformFile nexe_fd; | 119 base::File* nexe_fd; |
119 bool got_nexe_fd; | 120 bool got_nexe_fd; |
120 bool got_cache_reply; | 121 bool got_cache_reply; |
121 bool got_cache_hit; | 122 bool got_cache_hit; |
122 bool is_incognito; | 123 bool is_incognito; |
123 scoped_refptr<net::DrainableIOBuffer> nexe_read_buffer; | 124 scoped_refptr<net::DrainableIOBuffer> nexe_read_buffer; |
124 NexeFdCallback callback; | 125 NexeFdCallback callback; |
125 std::string cache_key; | 126 std::string cache_key; |
126 nacl::PnaclCacheInfo cache_info; | 127 nacl::PnaclCacheInfo cache_info; |
127 }; | 128 }; |
128 | 129 |
(...skipping 13 matching lines...) Expand all Loading... |
142 const TranslationID& id); | 143 const TranslationID& id); |
143 void OnCacheQueryReturn(const TranslationID& id, | 144 void OnCacheQueryReturn(const TranslationID& id, |
144 int net_error, | 145 int net_error, |
145 scoped_refptr<net::DrainableIOBuffer> buffer); | 146 scoped_refptr<net::DrainableIOBuffer> buffer); |
146 void OnTempFileReturn(const TranslationID& id, base::File file); | 147 void OnTempFileReturn(const TranslationID& id, base::File file); |
147 void CheckCacheQueryReady(const PendingTranslationMap::iterator& entry); | 148 void CheckCacheQueryReady(const PendingTranslationMap::iterator& entry); |
148 | 149 |
149 // GetNexeFd miss path | 150 // GetNexeFd miss path |
150 void ReturnMiss(const PendingTranslationMap::iterator& entry); | 151 void ReturnMiss(const PendingTranslationMap::iterator& entry); |
151 static scoped_refptr<net::DrainableIOBuffer> CopyFileToBuffer( | 152 static scoped_refptr<net::DrainableIOBuffer> CopyFileToBuffer( |
152 base::PlatformFile fd); | 153 scoped_ptr<base::File> file); |
153 void StoreTranslatedNexe(TranslationID id, | 154 void StoreTranslatedNexe(TranslationID id, |
154 scoped_refptr<net::DrainableIOBuffer>); | 155 scoped_refptr<net::DrainableIOBuffer>); |
155 void OnTranslatedNexeStored(const TranslationID& id, int net_error); | 156 void OnTranslatedNexeStored(const TranslationID& id, int net_error); |
156 void RequeryMatchingTranslations(const std::string& key); | 157 void RequeryMatchingTranslations(const std::string& key); |
157 | 158 |
158 // GetNexeFd hit path | 159 // GetNexeFd hit path |
159 static int CopyBufferToFile(base::PlatformFile fd, | 160 void OnBufferCopiedToTempFile(const TranslationID& id, |
160 scoped_refptr<net::DrainableIOBuffer> buffer); | 161 scoped_ptr<base::File> file, |
161 void OnBufferCopiedToTempFile(const TranslationID& id, int file_error); | 162 int file_error); |
162 | 163 |
163 void OnEntriesDoomed(const base::Closure& callback, int net_error); | 164 void OnEntriesDoomed(const base::Closure& callback, int net_error); |
164 | 165 |
165 void DeInitIfSafe(); | 166 void DeInitIfSafe(); |
166 | 167 |
167 // Operations which are pending with the cache backend, which we should | 168 // Operations which are pending with the cache backend, which we should |
168 // wait for before destroying it (see comment on DeInitIfSafe). | 169 // wait for before destroying it (see comment on DeInitIfSafe). |
169 int pending_backend_operations_; | 170 int pending_backend_operations_; |
170 CacheState cache_state_; | 171 CacheState cache_state_; |
171 base::FilePath temp_dir_; | 172 base::FilePath temp_dir_; |
172 scoped_ptr<pnacl::PnaclTranslationCache> disk_cache_; | 173 scoped_ptr<pnacl::PnaclTranslationCache> disk_cache_; |
173 PendingTranslationMap pending_translations_; | 174 PendingTranslationMap pending_translations_; |
174 base::ThreadChecker thread_checker_; | 175 base::ThreadChecker thread_checker_; |
175 base::WeakPtrFactory<PnaclHost> weak_factory_; | 176 base::WeakPtrFactory<PnaclHost> weak_factory_; |
176 DISALLOW_COPY_AND_ASSIGN(PnaclHost); | 177 DISALLOW_COPY_AND_ASSIGN(PnaclHost); |
177 }; | 178 }; |
178 | 179 |
179 } // namespace pnacl | 180 } // namespace pnacl |
180 | 181 |
181 #endif // COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ | 182 #endif // COMPONENTS_NACL_BROWSER_PNACL_HOST_H_ |
OLD | NEW |