diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 15:21:51 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 15:21:51 +0000 |
commit | ff1e64e3fb5cbdece0420d4b499472dd694d232a (patch) | |
tree | 420113784bae6bfa8acee9a0ed6c6cd22197e60a /content/browser/net | |
parent | d936cb8830a51cd79232bce5544716d9fb7e494b (diff) | |
download | chromium_src-ff1e64e3fb5cbdece0420d4b499472dd694d232a.zip chromium_src-ff1e64e3fb5cbdece0420d4b499472dd694d232a.tar.gz chromium_src-ff1e64e3fb5cbdece0420d4b499472dd694d232a.tar.bz2 |
Remove resource_request_info_impl.h dependency from chrome. This also makes blob/file system work in content based browsers.
I also moved the appcache/blob/cache developer urls to content so that they work in content_shell. This simplifies the Content API since the static blob/filesystem getters in ResourceContext are now not needed.
BUG=98716
Review URL: https://chromiumcodereview.appspot.com/9834039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/net')
-rw-r--r-- | content/browser/net/view_blob_internals_job_factory.cc | 25 | ||||
-rw-r--r-- | content/browser/net/view_blob_internals_job_factory.h | 27 | ||||
-rw-r--r-- | content/browser/net/view_http_cache_job_factory.cc | 202 | ||||
-rw-r--r-- | content/browser/net/view_http_cache_job_factory.h | 22 |
4 files changed, 276 insertions, 0 deletions
diff --git a/content/browser/net/view_blob_internals_job_factory.cc b/content/browser/net/view_blob_internals_job_factory.cc new file mode 100644 index 0000000..32dbd99 --- /dev/null +++ b/content/browser/net/view_blob_internals_job_factory.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/net/view_blob_internals_job_factory.h" + +#include "base/memory/scoped_ptr.h" +#include "base/string_util.h" +#include "content/public/common/url_constants.h" +#include "net/url_request/url_request.h" +#include "webkit/blob/view_blob_internals_job.h" + +// static. +bool ViewBlobInternalsJobFactory::IsSupportedURL(const GURL& url) { + return url.SchemeIs(chrome::kChromeUIScheme) && + url.host() == chrome::kChromeUIBlobInternalsHost; +} + +// static. +net::URLRequestJob* ViewBlobInternalsJobFactory::CreateJobForRequest( + net::URLRequest* request, + webkit_blob::BlobStorageController* blob_storage_controller) { + return new webkit_blob::ViewBlobInternalsJob( + request, blob_storage_controller); +} diff --git a/content/browser/net/view_blob_internals_job_factory.h b/content/browser/net/view_blob_internals_job_factory.h new file mode 100644 index 0000000..11eb48f --- /dev/null +++ b/content/browser/net/view_blob_internals_job_factory.h @@ -0,0 +1,27 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ +#define CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ +#pragma once + +namespace net { +class URLRequest; +class URLRequestJob; +} // namespace net +namespace webkit_blob { +class BlobStorageController; +} // webkit_blob + +class GURL; + +class ViewBlobInternalsJobFactory { + public: + static bool IsSupportedURL(const GURL& url); + static net::URLRequestJob* CreateJobForRequest( + net::URLRequest* request, + webkit_blob::BlobStorageController* blob_storage_controller); +}; + +#endif // CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ diff --git a/content/browser/net/view_http_cache_job_factory.cc b/content/browser/net/view_http_cache_job_factory.cc new file mode 100644 index 0000000..738524f --- /dev/null +++ b/content/browser/net/view_http_cache_job_factory.cc @@ -0,0 +1,202 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/net/view_http_cache_job_factory.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/callback.h" +#include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" +#include "base/message_loop.h" +#include "base/string_util.h" +#include "content/public/common/url_constants.h" +#include "net/base/completion_callback.h" +#include "net/base/net_errors.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_simple_job.h" +#include "net/url_request/view_cache_helper.h" + +namespace { + +// A job subclass that dumps an HTTP cache entry. +class ViewHttpCacheJob : public net::URLRequestJob { + public: + explicit ViewHttpCacheJob(net::URLRequest* request) + : net::URLRequestJob(request), + core_(new Core), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST( + callback_(base::Bind(&ViewHttpCacheJob::OnStartCompleted, + base::Unretained(this)))) { + } + + // net::URLRequestJob implementation. + virtual void Start() OVERRIDE; + virtual void Kill() OVERRIDE; + virtual bool GetMimeType(std::string* mime_type) const OVERRIDE{ + return core_->GetMimeType(mime_type); + } + virtual bool GetCharset(std::string* charset) OVERRIDE{ + return core_->GetCharset(charset); + } + virtual bool ReadRawData(net::IOBuffer* buf, + int buf_size, int *bytes_read) OVERRIDE{ + return core_->ReadRawData(buf, buf_size, bytes_read); + } + + private: + class Core : public base::RefCounted<Core> { + public: + Core() + : data_offset_(0), + ALLOW_THIS_IN_INITIALIZER_LIST(callback_( + base::Bind(&Core::OnIOComplete, this))) { + } + + int Start(const net::URLRequest& request, const base::Closure& callback); + + // Prevents it from invoking its callback. It will self-delete. + void Orphan() { + user_callback_.Reset(); + } + + bool GetMimeType(std::string* mime_type) const; + bool GetCharset(std::string* charset); + bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); + + private: + friend class base::RefCounted<Core>; + + ~Core() {} + + // Called when ViewCacheHelper completes the operation. + void OnIOComplete(int result); + + std::string data_; + int data_offset_; + net::ViewCacheHelper cache_helper_; + net::CompletionCallback callback_; + base::Closure user_callback_; + + DISALLOW_COPY_AND_ASSIGN(Core); + }; + + ~ViewHttpCacheJob() {} + + void StartAsync(); + void OnStartCompleted(); + + scoped_refptr<Core> core_; + base::WeakPtrFactory<ViewHttpCacheJob> weak_factory_; + base::Closure callback_; + + DISALLOW_COPY_AND_ASSIGN(ViewHttpCacheJob); +}; + +void ViewHttpCacheJob::Start() { + MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ViewHttpCacheJob::StartAsync, weak_factory_.GetWeakPtr())); +} + +void ViewHttpCacheJob::Kill() { + weak_factory_.InvalidateWeakPtrs(); + if (core_) { + core_->Orphan(); + core_ = NULL; + } + net::URLRequestJob::Kill(); +} + +void ViewHttpCacheJob::StartAsync() { + DCHECK(request()); + + if (!request()) + return; + + int rv = core_->Start(*request(), callback_); + if (rv != net::ERR_IO_PENDING) { + DCHECK_EQ(net::OK, rv); + OnStartCompleted(); + } +} + +void ViewHttpCacheJob::OnStartCompleted() { + NotifyHeadersComplete(); +} + +int ViewHttpCacheJob::Core::Start(const net::URLRequest& request, + const base::Closure& callback) { + DCHECK(!callback.is_null()); + DCHECK(user_callback_.is_null()); + + AddRef(); // Released on OnIOComplete(). + std::string cache_key = + request.url().spec().substr(strlen(chrome::kChromeUINetworkViewCacheURL)); + + int rv; + if (cache_key.empty()) { + rv = cache_helper_.GetContentsHTML(request.context(), + chrome::kChromeUINetworkViewCacheURL, + &data_, callback_); + } else { + rv = cache_helper_.GetEntryInfoHTML(cache_key, request.context(), + &data_, callback_); + } + + if (rv == net::ERR_IO_PENDING) + user_callback_ = callback; + + return rv; +} + +bool ViewHttpCacheJob::Core::GetMimeType(std::string* mime_type) const { + mime_type->assign("text/html"); + return true; +} + +bool ViewHttpCacheJob::Core::GetCharset(std::string* charset) { + charset->assign("UTF-8"); + return true; +} + +bool ViewHttpCacheJob::Core::ReadRawData(net::IOBuffer* buf, + int buf_size, + int* bytes_read) { + DCHECK(bytes_read); + int remaining = static_cast<int>(data_.size()) - data_offset_; + if (buf_size > remaining) + buf_size = remaining; + memcpy(buf->data(), data_.data() + data_offset_, buf_size); + data_offset_ += buf_size; + *bytes_read = buf_size; + return true; +} + +void ViewHttpCacheJob::Core::OnIOComplete(int result) { + DCHECK_EQ(net::OK, result); + + if (!user_callback_.is_null()) + user_callback_.Run(); + + // We may be holding the last reference to this job. Do not access |this| + // after Release(). + Release(); // Acquired on Start(). +} + +} // namespace. + +// Static. +bool ViewHttpCacheJobFactory::IsSupportedURL(const GURL& url) { + return url.SchemeIs(chrome::kChromeUIScheme) && + url.host() == chrome::kChromeUINetworkViewCacheHost; +} + +// Static. +net::URLRequestJob* ViewHttpCacheJobFactory::CreateJobForRequest( + net::URLRequest* request) { + return new ViewHttpCacheJob(request); +} diff --git a/content/browser/net/view_http_cache_job_factory.h b/content/browser/net/view_http_cache_job_factory.h new file mode 100644 index 0000000..5e0c322 --- /dev/null +++ b/content/browser/net/view_http_cache_job_factory.h @@ -0,0 +1,22 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ +#define CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ +#pragma once + +namespace net { +class URLRequest; +class URLRequestJob; +} // namespace net + +class GURL; + +class ViewHttpCacheJobFactory { + public: + static bool IsSupportedURL(const GURL& url); + static net::URLRequestJob* CreateJobForRequest(net::URLRequest* request); +}; + +#endif // CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ |