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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 11103027: Support filesystem files from BlobURLRequestJob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 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
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 615 }
616 616
617 private: 617 private:
618 DownloadManager::DownloadVector* items_; 618 DownloadManager::DownloadVector* items_;
619 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller); 619 DISALLOW_COPY_AND_ASSIGN(ScopedItemVectorCanceller);
620 }; 620 };
621 621
622 class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { 622 class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
623 public: 623 public:
624 explicit TestProtocolHandler( 624 explicit TestProtocolHandler(
625 webkit_blob::BlobStorageController* blob_storage_controller) 625 webkit_blob::BlobStorageController* blob_storage_controller,
626 : blob_storage_controller_(blob_storage_controller) {} 626 fileapi::FileSystemContext* file_system_context)
627 : blob_storage_controller_(blob_storage_controller),
628 file_system_context_(file_system_context) {}
627 629
628 virtual ~TestProtocolHandler() {} 630 virtual ~TestProtocolHandler() {}
629 631
630 virtual net::URLRequestJob* MaybeCreateJob( 632 virtual net::URLRequestJob* MaybeCreateJob(
631 net::URLRequest* request, 633 net::URLRequest* request,
632 net::NetworkDelegate* network_delegate) const OVERRIDE { 634 net::NetworkDelegate* network_delegate) const OVERRIDE {
633 return new webkit_blob::BlobURLRequestJob( 635 return new webkit_blob::BlobURLRequestJob(
634 request, 636 request,
635 network_delegate, 637 network_delegate,
636 blob_storage_controller_->GetBlobDataFromUrl(request->url()), 638 blob_storage_controller_->GetBlobDataFromUrl(request->url()),
639 file_system_context_,
637 base::MessageLoopProxy::current()); 640 base::MessageLoopProxy::current());
638 } 641 }
639 642
640 private: 643 private:
641 webkit_blob::BlobStorageController* const blob_storage_controller_; 644 webkit_blob::BlobStorageController* const blob_storage_controller_;
645 fileapi::FileSystemContext* const file_system_context_;
642 646
643 DISALLOW_COPY_AND_ASSIGN(TestProtocolHandler); 647 DISALLOW_COPY_AND_ASSIGN(TestProtocolHandler);
644 }; 648 };
645 649
646 class TestURLRequestContext : public net::URLRequestContext { 650 class TestURLRequestContext : public net::URLRequestContext {
647 public: 651 public:
648 TestURLRequestContext() 652 explicit TestURLRequestContext(
653 fileapi::FileSystemContext* file_system_context)
649 : blob_storage_controller_(new webkit_blob::BlobStorageController) { 654 : blob_storage_controller_(new webkit_blob::BlobStorageController) {
650 // Job factory owns the protocol handler. 655 // Job factory owns the protocol handler.
651 job_factory_.SetProtocolHandler( 656 job_factory_.SetProtocolHandler(
652 "blob", new TestProtocolHandler(blob_storage_controller_.get())); 657 "blob", new TestProtocolHandler(blob_storage_controller_.get(),
658 file_system_context));
653 set_job_factory(&job_factory_); 659 set_job_factory(&job_factory_);
654 } 660 }
655 661
656 virtual ~TestURLRequestContext() {} 662 virtual ~TestURLRequestContext() {}
657 663
658 webkit_blob::BlobStorageController* blob_storage_controller() const { 664 webkit_blob::BlobStorageController* blob_storage_controller() const {
659 return blob_storage_controller_.get(); 665 return blob_storage_controller_.get();
660 } 666 }
661 667
662 private: 668 private:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 738 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
733 operation()->CreateFile(fileapi::FileSystemURL(GURL(root_ + filename_)), 739 operation()->CreateFile(fileapi::FileSystemURL(GURL(root_ + filename_)),
734 kExclusive, base::Bind( 740 kExclusive, base::Bind(
735 &HTML5FileWriter::CreateFileCallback, base::Unretained(this))); 741 &HTML5FileWriter::CreateFileCallback, base::Unretained(this)));
736 } 742 }
737 743
738 void CreateFileCallback(base::PlatformFileError result) { 744 void CreateFileCallback(base::PlatformFileError result) {
739 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 745 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
740 CHECK_EQ(base::PLATFORM_FILE_OK, result); 746 CHECK_EQ(base::PLATFORM_FILE_OK, result);
741 blob_data_->AppendData(payload_); 747 blob_data_->AppendData(payload_);
742 url_request_context_.reset(new TestURLRequestContext()); 748 url_request_context_.reset(new TestURLRequestContext(fs_));
743 url_request_context_->blob_storage_controller()->AddFinishedBlob( 749 url_request_context_->blob_storage_controller()->AddFinishedBlob(
744 blob_url(), blob_data_); 750 blob_url(), blob_data_);
745 operation()->Write( 751 operation()->Write(
746 url_request_context_.get(), 752 url_request_context_.get(),
747 fileapi::FileSystemURL(GURL(root_ + filename_)), 753 fileapi::FileSystemURL(GURL(root_ + filename_)),
748 blob_url(), 754 blob_url(),
749 0, // offset 755 0, // offset
750 base::Bind(&HTML5FileWriter::WriteCallback, base::Unretained(this))); 756 base::Bind(&HTML5FileWriter::WriteCallback, base::Unretained(this)));
751 } 757 }
752 758
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 " \"state\": {" 2082 " \"state\": {"
2077 " \"previous\": \"in_progress\"," 2083 " \"previous\": \"in_progress\","
2078 " \"current\": \"complete\"}}]", 2084 " \"current\": \"complete\"}}]",
2079 result_id, 2085 result_id,
2080 GetFilename("on_record.txt.crdownload").c_str(), 2086 GetFilename("on_record.txt.crdownload").c_str(),
2081 GetFilename("on_record.txt").c_str()))); 2087 GetFilename("on_record.txt").c_str())));
2082 std::string disk_data; 2088 std::string disk_data;
2083 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2089 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2084 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2090 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2085 } 2091 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/storage_partition_impl_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698