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

Side by Side Diff: webkit/blob/mock_blob_url_request_context.cc

Issue 11416382: ********** Content tests with blob hacking. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 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
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 "webkit/blob/mock_blob_url_request_context.h" 5 #include "webkit/blob/mock_blob_url_request_context.h"
6 6
7 #include "webkit/blob/blob_data.h" 7 #include "webkit/blob/blob_data.h"
8 #include "webkit/blob/blob_storage_controller.h" 8 #include "webkit/blob/blob_storage_context.h"
9 #include "webkit/blob/blob_url_request_job.h" 9 #include "webkit/blob/blob_url_request_job.h"
10 #include "webkit/blob/blob_url_request_job_factory.h"
10 11
11 namespace webkit_blob { 12 namespace webkit_blob {
12 13
13 namespace {
14
15 class MockBlobProtocolHandler
16 : public net::URLRequestJobFactory::ProtocolHandler {
17 public:
18 explicit MockBlobProtocolHandler(
19 BlobStorageController* blob_storage_controller,
20 fileapi::FileSystemContext* file_system_context)
21 : blob_storage_controller_(blob_storage_controller),
22 file_system_context_(file_system_context) {}
23
24 virtual ~MockBlobProtocolHandler() {}
25
26 virtual net::URLRequestJob* MaybeCreateJob(
27 net::URLRequest* request,
28 net::NetworkDelegate* network_delegate) const OVERRIDE {
29 return new BlobURLRequestJob(
30 request,
31 network_delegate,
32 blob_storage_controller_->GetBlobDataFromUrl(request->url()),
33 file_system_context_,
34 base::MessageLoopProxy::current());
35 }
36
37 private:
38 webkit_blob::BlobStorageController* const blob_storage_controller_;
39 fileapi::FileSystemContext* const file_system_context_;
40
41 DISALLOW_COPY_AND_ASSIGN(MockBlobProtocolHandler);
42 };
43
44 } // namespace
45
46 MockBlobURLRequestContext::MockBlobURLRequestContext( 14 MockBlobURLRequestContext::MockBlobURLRequestContext(
47 fileapi::FileSystemContext* file_system_context) 15 fileapi::FileSystemContext* file_system_context)
48 : blob_storage_controller_(new BlobStorageController) { 16 : blob_storage_context_(new BlobStorageContext) {
49 // Job factory owns the protocol handler. 17 // Job factory owns the protocol handler.
50 job_factory_.SetProtocolHandler( 18 job_factory_.SetProtocolHandler(
51 "blob", new MockBlobProtocolHandler(blob_storage_controller_.get(), 19 "blob", new BlobProtocolHandler(blob_storage_context_.get(),
52 file_system_context)); 20 file_system_context,
21 base::MessageLoopProxy::current()));
53 set_job_factory(&job_factory_); 22 set_job_factory(&job_factory_);
54 } 23 }
55 24
56 MockBlobURLRequestContext::~MockBlobURLRequestContext() {} 25 MockBlobURLRequestContext::~MockBlobURLRequestContext() {}
57 26
58 ScopedTextBlob::ScopedTextBlob( 27 ScopedTextBlob::ScopedTextBlob(
59 const MockBlobURLRequestContext& request_context, 28 const MockBlobURLRequestContext& request_context,
60 const GURL& blob_url, 29 const std::string& blob_id,
61 const std::string& data) 30 const std::string& data)
62 : blob_url_(blob_url), 31 : blob_id_(blob_id),
63 blob_storage_controller_(request_context.blob_storage_controller()) { 32 blob_storage_context_(request_context.blob_storage_context()) {
64 DCHECK(blob_storage_controller_); 33 DCHECK(blob_storage_context_);
65 scoped_refptr<BlobData> blob_data(new BlobData()); 34 scoped_refptr<BlobData> blob_data(new BlobData(blob_id_));
66 blob_data->AppendData(data); 35 if (!data.empty())
67 blob_storage_controller_->AddFinishedBlob(blob_url_, blob_data); 36 blob_data->AppendData(data);
37 blob_storage_context_->AddFinishedBlob(blob_data);
68 } 38 }
69 39
70 ScopedTextBlob::~ScopedTextBlob() { 40 ScopedTextBlob::~ScopedTextBlob() {
71 blob_storage_controller_->RemoveBlob(blob_url_); 41 blob_storage_context_->DecrementBlobRefCount(blob_id_);
42 }
43
44 scoped_ptr<BlobDataHandle> ScopedTextBlob::GetBlobDataHandle() {
45 return blob_storage_context_->GetBlobDataFromUUID(blob_id_);
72 } 46 }
73 47
74 } // namespace webkit_blob 48 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/mock_blob_url_request_context.h ('k') | webkit/fileapi/local_file_system_operation_write_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698