OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 file_stream_ = NULL; | 424 file_stream_ = NULL; |
425 deletable_file_ = NULL; | 425 deletable_file_ = NULL; |
426 loader_.reset(); | 426 loader_.reset(); |
427 } | 427 } |
428 | 428 |
429 virtual scoped_ptr<ResourceHandler> WrapResourceHandler( | 429 virtual scoped_ptr<ResourceHandler> WrapResourceHandler( |
430 scoped_ptr<ResourceHandlerStub> leaf_handler, | 430 scoped_ptr<ResourceHandlerStub> leaf_handler, |
431 net::URLRequest* request) OVERRIDE { | 431 net::URLRequest* request) OVERRIDE { |
432 // Make a temporary file. | 432 // Make a temporary file. |
433 CHECK(base::CreateTemporaryFile(&temp_path_)); | 433 CHECK(base::CreateTemporaryFile(&temp_path_)); |
434 base::PlatformFile platform_file = | 434 int flags = base::File::FLAG_WRITE | base::File::FLAG_TEMPORARY | |
435 base::CreatePlatformFile(temp_path_, | 435 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_ASYNC; |
436 base::PLATFORM_FILE_WRITE | | 436 base::File file(temp_path_, flags); |
437 base::PLATFORM_FILE_TEMPORARY | | 437 CHECK(file.IsValid()); |
438 base::PLATFORM_FILE_CREATE_ALWAYS | | |
439 base::PLATFORM_FILE_ASYNC, | |
440 NULL, NULL); | |
441 CHECK_NE(base::kInvalidPlatformFileValue, platform_file); | |
442 | 438 |
443 // Create mock file streams and a ShareableFileReference. | 439 // Create mock file streams and a ShareableFileReference. |
444 scoped_ptr<net::testing::MockFileStream> file_stream( | 440 scoped_ptr<net::testing::MockFileStream> file_stream( |
445 new net::testing::MockFileStream( | 441 new net::testing::MockFileStream(file.Pass(), NULL, |
446 platform_file, | 442 base::MessageLoopProxy::current())); |
447 base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC, | |
448 NULL, base::MessageLoopProxy::current())); | |
449 file_stream_ = file_stream.get(); | 443 file_stream_ = file_stream.get(); |
450 deletable_file_ = ShareableFileReference::GetOrCreate( | 444 deletable_file_ = ShareableFileReference::GetOrCreate( |
451 temp_path_, | 445 temp_path_, |
452 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | 446 ShareableFileReference::DELETE_ON_FINAL_RELEASE, |
453 BrowserThread::GetMessageLoopProxyForThread( | 447 BrowserThread::GetMessageLoopProxyForThread( |
454 BrowserThread::FILE).get()); | 448 BrowserThread::FILE).get()); |
455 | 449 |
456 // Inject them into the handler. | 450 // Inject them into the handler. |
457 scoped_ptr<RedirectToFileResourceHandler> handler( | 451 scoped_ptr<RedirectToFileResourceHandler> handler( |
458 new RedirectToFileResourceHandler( | 452 new RedirectToFileResourceHandler( |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents)); | 647 ASSERT_TRUE(base::ReadFileToString(temp_path(), &contents)); |
654 EXPECT_EQ(test_data(), contents); | 648 EXPECT_EQ(test_data(), contents); |
655 | 649 |
656 // Release the loader. The file should be gone now. | 650 // Release the loader. The file should be gone now. |
657 ReleaseLoader(); | 651 ReleaseLoader(); |
658 base::RunLoop().RunUntilIdle(); | 652 base::RunLoop().RunUntilIdle(); |
659 EXPECT_FALSE(base::PathExists(temp_path())); | 653 EXPECT_FALSE(base::PathExists(temp_path())); |
660 } | 654 } |
661 | 655 |
662 } // namespace content | 656 } // namespace content |
OLD | NEW |