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 #include "pnacl_translation_resource_host.h" | 5 #include "pnacl_translation_resource_host.h" |
6 | 6 |
7 #include "components/nacl/common/nacl_host_messages.h" | 7 #include "components/nacl/common/nacl_host_messages.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 DCHECK(pending_cache_requests_.count(instance) == 0); | 122 DCHECK(pending_cache_requests_.count(instance) == 0); |
123 channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance, | 123 channel_->Send(new NaClHostMsg_ReportTranslationFinished(instance, |
124 PP_ToBool(success))); | 124 PP_ToBool(success))); |
125 } | 125 } |
126 | 126 |
127 void PnaclTranslationResourceHost::OnNexeTempFileReply( | 127 void PnaclTranslationResourceHost::OnNexeTempFileReply( |
128 PP_Instance instance, | 128 PP_Instance instance, |
129 bool is_hit, | 129 bool is_hit, |
130 IPC::PlatformFileForTransit file) { | 130 IPC::PlatformFileForTransit file) { |
131 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 131 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
| 132 base::File base_file = IPC::PlatformFileForTransitToFile(file); |
132 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); | 133 CacheRequestInfoMap::iterator it = pending_cache_requests_.find(instance); |
133 int32_t status = PP_ERROR_FAILED; | 134 int32_t status = PP_ERROR_FAILED; |
134 // Handle the expected successful case first. | 135 // Handle the expected successful case first. |
135 if (it != pending_cache_requests_.end() && | 136 if (it != pending_cache_requests_.end() && base_file.IsValid() && |
136 !(file == IPC::InvalidPlatformFileForTransit()) && | |
137 TrackedCallback::IsPending(it->second.callback)) { | 137 TrackedCallback::IsPending(it->second.callback)) { |
138 *it->second.is_hit = PP_FromBool(is_hit); | 138 *it->second.is_hit = PP_FromBool(is_hit); |
139 *it->second.file_handle = IPC::PlatformFileForTransitToPlatformFile(file); | 139 *it->second.file_handle = base_file.TakePlatformFile(); |
140 status = PP_OK; | 140 status = PP_OK; |
141 } | 141 } |
142 if (it == pending_cache_requests_.end()) { | 142 if (it == pending_cache_requests_.end()) { |
143 DLOG(ERROR) << "Could not find pending request for reply"; | 143 DLOG(ERROR) << "Could not find pending request for reply"; |
144 } else { | 144 } else { |
145 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 145 PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
146 FROM_HERE, | 146 FROM_HERE, |
147 base::Bind(&TrackedCallback::Run, it->second.callback, status)); | 147 base::Bind(&TrackedCallback::Run, it->second.callback, status)); |
148 pending_cache_requests_.erase(it); | 148 pending_cache_requests_.erase(it); |
149 } | 149 } |
150 if (file == IPC::InvalidPlatformFileForTransit()) { | 150 if (!base_file.IsValid()) { |
151 DLOG(ERROR) << "Got invalid platformfilefortransit"; | 151 DLOG(ERROR) << "Got invalid platformfilefortransit"; |
152 } else if (status != PP_OK) { | |
153 base::ClosePlatformFile(IPC::PlatformFileForTransitToPlatformFile(file)); | |
154 } | 152 } |
155 } | 153 } |
156 | 154 |
157 void PnaclTranslationResourceHost::CleanupCacheRequests() { | 155 void PnaclTranslationResourceHost::CleanupCacheRequests() { |
158 DCHECK(io_message_loop_->BelongsToCurrentThread()); | 156 DCHECK(io_message_loop_->BelongsToCurrentThread()); |
159 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); | 157 for (CacheRequestInfoMap::iterator it = pending_cache_requests_.begin(); |
160 it != pending_cache_requests_.end(); | 158 it != pending_cache_requests_.end(); |
161 ++it) { | 159 ++it) { |
162 it->second.callback->PostAbort(); | 160 it->second.callback->PostAbort(); |
163 } | 161 } |
164 pending_cache_requests_.clear(); | 162 pending_cache_requests_.clear(); |
165 } | 163 } |
OLD | NEW |