diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 16:03:49 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 16:03:49 +0000 |
commit | 540c149788ab214c1fac850961c78445d17177a1 (patch) | |
tree | abad68f7436c1ed2061d95dc0f32c4ff292bc4b1 | |
parent | f18f2d29e4b5b88f251c52b3137df6ef8ac6843f (diff) | |
download | chromium_src-540c149788ab214c1fac850961c78445d17177a1.zip chromium_src-540c149788ab214c1fac850961c78445d17177a1.tar.gz chromium_src-540c149788ab214c1fac850961c78445d17177a1.tar.bz2 |
Add a dummy URL request handler.
This metadata request just returns a dummy string for the "metadata" scheme.
This doesn't do anything yet.
Review URL: http://codereview.chromium.org/149490
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20489 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 2 | ||||
-rw-r--r-- | chrome/browser/net/metadata_url_request.cc | 96 | ||||
-rw-r--r-- | chrome/browser/net/metadata_url_request.h | 10 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
4 files changed, 110 insertions, 0 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 4c742a2..d03a8d4 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -34,6 +34,7 @@ #include "chrome/browser/first_run.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" +#include "chrome/browser/net/metadata_url_request.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/process_singleton.h" @@ -660,6 +661,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // chrome-extension:// URLs. RegisterURLRequestChromeJob(); RegisterExtensionProtocols(); + RegisterMetadataURLRequestHandler(); // In unittest mode, this will do nothing. In normal mode, this will create // the global GoogleURLTracker instance, which will promptly go to sleep for diff --git a/chrome/browser/net/metadata_url_request.cc b/chrome/browser/net/metadata_url_request.cc new file mode 100644 index 0000000..d901746 --- /dev/null +++ b/chrome/browser/net/metadata_url_request.cc @@ -0,0 +1,96 @@ +// Copyright (c) 2009 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 "chrome/browser/net/metadata_url_request.h" + +#include "base/message_loop.h" +#include "build/build_config.h" +#include "googleurl/src/url_util.h" +#include "net/base/io_buffer.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_job.h" + +namespace { + +const char kMetadataScheme[] = "metadata"; + +class MetadataRequestHandler : public URLRequestJob { + public: + explicit MetadataRequestHandler(URLRequest* request); + ~MetadataRequestHandler(); + + static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); + + // URLRequestJob implementation. + virtual void Start(); + virtual void Kill(); + virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); + virtual bool GetMimeType(std::string* mime_type) const; + + private: + void StartAsync(); + + int data_offset_; + + DISALLOW_COPY_AND_ASSIGN(MetadataRequestHandler); +}; + +MetadataRequestHandler::MetadataRequestHandler(URLRequest* request) + : URLRequestJob(request), + data_offset_(0) { +} + +MetadataRequestHandler::~MetadataRequestHandler() { +} + +URLRequestJob* MetadataRequestHandler::Factory(URLRequest* request, + const std::string& scheme) { + return new MetadataRequestHandler(request); +} + +void MetadataRequestHandler::Start() { + // Start reading asynchronously so that all error reporting and data + // callbacks happen as they would for network requests. + MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( + this, &MetadataRequestHandler::StartAsync)); +} + +void MetadataRequestHandler::Kill() { +} + +bool MetadataRequestHandler::ReadRawData(net::IOBuffer* buf, int buf_size, + int *bytes_read) { + std::string fake_result = "{ \"foo\": 3.14 }"; + + int remaining = static_cast<int>(fake_result.size()) - data_offset_; + if (buf_size > remaining) + buf_size = remaining; + if (buf_size > 0) { + memcpy(buf->data(), &fake_result[data_offset_], buf_size); + data_offset_ += buf_size; + } + *bytes_read = buf_size; + return true; +} + +bool MetadataRequestHandler::GetMimeType(std::string* mime_type) const { + *mime_type = "application/json"; + return true; +} + +void MetadataRequestHandler::StartAsync() { + NotifyHeadersComplete(); +} + +} // namespace + +void RegisterMetadataURLRequestHandler() { + // This is currently unfinished. It will eventually provide metadata + // but currently just returns a dummy stub string. +#if defined(OS_CHROMEOS) + URLRequest::RegisterProtocolFactory(kMetadataScheme, + &MetadataRequestHandler::Factory); + url_util::AddStandardScheme(kMetadataScheme); +#endif +} diff --git a/chrome/browser/net/metadata_url_request.h b/chrome/browser/net/metadata_url_request.h new file mode 100644 index 0000000..047fa15 --- /dev/null +++ b/chrome/browser/net/metadata_url_request.h @@ -0,0 +1,10 @@ +// Copyright (c) 2009 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 CHROME_BROWSER_NET_METADATA_URL_REQUEST_H_ +#define CHROME_BROWSER_NET_METADATA_URL_REQUEST_H_ + +void RegisterMetadataURLRequestHandler(); + +#endif // CHROME_BROWSER_NET_METADATA_URL_REQUEST_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 58faf97..376c683 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1236,6 +1236,8 @@ 'browser/net/dns_host_info.h', 'browser/net/dns_master.cc', 'browser/net/dns_master.h', + 'browser/net/metadata_url_request.cc', + 'browser/net/metadata_url_request.h', 'browser/net/referrer.cc', 'browser/net/referrer.h', 'browser/net/resolve_proxy_msg_helper.cc', |