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

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

Issue 15746017: Move webkit/blob to new locations. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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 | « webkit/blob/mock_blob_url_request_context.h ('k') | webkit/blob/scoped_file.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/blob/mock_blob_url_request_context.h"
6
7 #include "webkit/blob/blob_data.h"
8 #include "webkit/blob/blob_storage_controller.h"
9 #include "webkit/blob/blob_url_request_job.h"
10
11 namespace webkit_blob {
12
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(
47 fileapi::FileSystemContext* file_system_context)
48 : blob_storage_controller_(new BlobStorageController) {
49 // Job factory owns the protocol handler.
50 job_factory_.SetProtocolHandler(
51 "blob", new MockBlobProtocolHandler(blob_storage_controller_.get(),
52 file_system_context));
53 set_job_factory(&job_factory_);
54 }
55
56 MockBlobURLRequestContext::~MockBlobURLRequestContext() {}
57
58 ScopedTextBlob::ScopedTextBlob(
59 const MockBlobURLRequestContext& request_context,
60 const GURL& blob_url,
61 const std::string& data)
62 : blob_url_(blob_url),
63 blob_storage_controller_(request_context.blob_storage_controller()) {
64 DCHECK(blob_storage_controller_);
65 scoped_refptr<BlobData> blob_data(new BlobData());
66 blob_data->AppendData(data);
67 blob_storage_controller_->AddFinishedBlob(blob_url_, blob_data);
68 }
69
70 ScopedTextBlob::~ScopedTextBlob() {
71 blob_storage_controller_->RemoveBlob(blob_url_);
72 }
73
74 } // namespace webkit_blob
OLDNEW
« no previous file with comments | « webkit/blob/mock_blob_url_request_context.h ('k') | webkit/blob/scoped_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698