Home | History | Annotate | Download | only in net
      1 // Copyright (c) 2010 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 "chrome/browser/net/blob_url_request_job_factory.h"
      6 
      7 #include "chrome/browser/net/chrome_url_request_context.h"
      8 #include "chrome/common/url_constants.h"
      9 #include "content/browser/browser_thread.h"
     10 #include "content/browser/chrome_blob_storage_context.h"
     11 #include "content/browser/renderer_host/resource_dispatcher_host.h"
     12 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
     13 #include "webkit/blob/blob_storage_controller.h"
     14 #include "webkit/blob/blob_url_request_job.h"
     15 
     16 namespace {
     17 
     18 net::URLRequestJob* BlobURLRequestJobFactory(net::URLRequest* request,
     19                                              const std::string& scheme) {
     20   scoped_refptr<webkit_blob::BlobData> data;
     21   ResourceDispatcherHostRequestInfo* info =
     22       ResourceDispatcherHost::InfoForRequest(request);
     23   if (info) {
     24     // Resource dispatcher host already looked up the blob data.
     25     data = info->requested_blob_data();
     26   } else {
     27     // This request is not coming thru resource dispatcher host.
     28     data  = static_cast<ChromeURLRequestContext*>(request->context())->
     29         blob_storage_context()->
     30             controller()->GetBlobDataFromUrl(request->url());
     31   }
     32   return new webkit_blob::BlobURLRequestJob(
     33       request, data,
     34       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
     35 }
     36 
     37 }
     38 
     39 void RegisterBlobURLRequestJobFactory() {
     40   net::URLRequest::RegisterProtocolFactory(chrome::kBlobScheme,
     41                                       &BlobURLRequestJobFactory);
     42 }
     43