| 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 "components/nacl/browser/pnacl_host.h" | 5 #include "components/nacl/browser/pnacl_host.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 static const base::FilePath::CharType kTranslationCacheDirectoryName[] = | 28 static const base::FilePath::CharType kTranslationCacheDirectoryName[] = |
| 29 FILE_PATH_LITERAL("PnaclTranslationCache"); | 29 FILE_PATH_LITERAL("PnaclTranslationCache"); |
| 30 // Delay to wait for initialization of the cache backend | 30 // Delay to wait for initialization of the cache backend |
| 31 static const int kTranslationCacheInitializationDelayMs = 20; | 31 static const int kTranslationCacheInitializationDelayMs = 20; |
| 32 | 32 |
| 33 void CloseBaseFile(base::File file) { | 33 void CloseBaseFile(base::File file) { |
| 34 base::PostTaskWithTraits( | 34 base::PostTaskWithTraits( |
| 35 FROM_HERE, | 35 FROM_HERE, |
| 36 base::TaskTraits() | 36 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 37 .MayBlock() | 37 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, |
| 38 .WithPriority(base::TaskPriority::BACKGROUND) | |
| 39 .WithShutdownBehavior( | |
| 40 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | |
| 41 base::Bind([](base::File file) {}, Passed(std::move(file)))); | 38 base::Bind([](base::File file) {}, Passed(std::move(file)))); |
| 42 } | 39 } |
| 43 | 40 |
| 44 } // namespace | 41 } // namespace |
| 45 | 42 |
| 46 namespace pnacl { | 43 namespace pnacl { |
| 47 | 44 |
| 48 class FileProxy { | 45 class FileProxy { |
| 49 public: | 46 public: |
| 50 FileProxy(std::unique_ptr<base::File> file, PnaclHost* host); | 47 FileProxy(std::unique_ptr<base::File> file, PnaclHost* host); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 ReturnMiss(entry); | 372 ReturnMiss(entry); |
| 376 return; | 373 return; |
| 377 } | 374 } |
| 378 | 375 |
| 379 std::unique_ptr<base::File> file(pt->nexe_fd); | 376 std::unique_ptr<base::File> file(pt->nexe_fd); |
| 380 pt->nexe_fd = NULL; | 377 pt->nexe_fd = NULL; |
| 381 pt->got_nexe_fd = false; | 378 pt->got_nexe_fd = false; |
| 382 FileProxy* proxy(new FileProxy(std::move(file), this)); | 379 FileProxy* proxy(new FileProxy(std::move(file), this)); |
| 383 | 380 |
| 384 base::PostTaskWithTraitsAndReplyWithResult( | 381 base::PostTaskWithTraitsAndReplyWithResult( |
| 385 FROM_HERE, | 382 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 386 base::TaskTraits().MayBlock().WithPriority( | |
| 387 base::TaskPriority::BACKGROUND), | |
| 388 base::Bind(&FileProxy::Write, base::Unretained(proxy), | 383 base::Bind(&FileProxy::Write, base::Unretained(proxy), |
| 389 pt->nexe_read_buffer), | 384 pt->nexe_read_buffer), |
| 390 base::Bind(&FileProxy::WriteDone, base::Owned(proxy), entry->first)); | 385 base::Bind(&FileProxy::WriteDone, base::Owned(proxy), entry->first)); |
| 391 } | 386 } |
| 392 | 387 |
| 393 //////////////////// GetNexeFd miss path | 388 //////////////////// GetNexeFd miss path |
| 394 // Return the temp fd to the renderer, reporting a miss. | 389 // Return the temp fd to the renderer, reporting a miss. |
| 395 void PnaclHost::ReturnMiss(const PendingTranslationMap::iterator& entry) { | 390 void PnaclHost::ReturnMiss(const PendingTranslationMap::iterator& entry) { |
| 396 // Return the fd | 391 // Return the fd |
| 397 PendingTranslation* pt = &entry->second; | 392 PendingTranslation* pt = &entry->second; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // translations. | 445 // translations. |
| 451 if (!entry->second.got_nexe_fd || !entry->second.got_cache_reply || | 446 if (!entry->second.got_nexe_fd || !entry->second.got_cache_reply || |
| 452 !success || !TranslationMayBeCached(entry)) { | 447 !success || !TranslationMayBeCached(entry)) { |
| 453 store_nexe = false; | 448 store_nexe = false; |
| 454 } else { | 449 } else { |
| 455 std::unique_ptr<base::File> file(entry->second.nexe_fd); | 450 std::unique_ptr<base::File> file(entry->second.nexe_fd); |
| 456 entry->second.nexe_fd = NULL; | 451 entry->second.nexe_fd = NULL; |
| 457 entry->second.got_nexe_fd = false; | 452 entry->second.got_nexe_fd = false; |
| 458 | 453 |
| 459 base::PostTaskWithTraitsAndReplyWithResult( | 454 base::PostTaskWithTraitsAndReplyWithResult( |
| 460 FROM_HERE, | 455 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 461 base::TaskTraits().MayBlock().WithPriority( | |
| 462 base::TaskPriority::BACKGROUND), | |
| 463 base::Bind(&PnaclHost::CopyFileToBuffer, Passed(&file)), | 456 base::Bind(&PnaclHost::CopyFileToBuffer, Passed(&file)), |
| 464 base::Bind(&PnaclHost::StoreTranslatedNexe, base::Unretained(this), | 457 base::Bind(&PnaclHost::StoreTranslatedNexe, base::Unretained(this), |
| 465 id)); | 458 id)); |
| 466 } | 459 } |
| 467 | 460 |
| 468 if (!store_nexe) { | 461 if (!store_nexe) { |
| 469 // If store_nexe is true, the fd will be closed by CopyFileToBuffer. | 462 // If store_nexe is true, the fd will be closed by CopyFileToBuffer. |
| 470 if (entry->second.got_nexe_fd) { | 463 if (entry->second.got_nexe_fd) { |
| 471 std::unique_ptr<base::File> file(entry->second.nexe_fd); | 464 std::unique_ptr<base::File> file(entry->second.nexe_fd); |
| 472 entry->second.nexe_fd = NULL; | 465 entry->second.nexe_fd = NULL; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 DCHECK(pending_backend_operations_ >= 0); | 643 DCHECK(pending_backend_operations_ >= 0); |
| 651 if (pending_translations_.empty() && | 644 if (pending_translations_.empty() && |
| 652 pending_backend_operations_ <= 0 && | 645 pending_backend_operations_ <= 0 && |
| 653 cache_state_ == CacheReady) { | 646 cache_state_ == CacheReady) { |
| 654 cache_state_ = CacheUninitialized; | 647 cache_state_ = CacheUninitialized; |
| 655 disk_cache_.reset(); | 648 disk_cache_.reset(); |
| 656 } | 649 } |
| 657 } | 650 } |
| 658 | 651 |
| 659 } // namespace pnacl | 652 } // namespace pnacl |
| OLD | NEW |