| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/net/metadata_url_request.h" | 5 #include "chrome/browser/net/metadata_url_request.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/parsers/metadata_parser_manager.h" | 10 #include "chrome/browser/parsers/metadata_parser_manager.h" |
| 11 #include "chrome/browser/parsers/metadata_parser.h" | 11 #include "chrome/browser/parsers/metadata_parser.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_job.h" | 16 #include "net/url_request/url_request_job.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class MetadataRequestHandler : public net::URLRequestJob { | 20 class MetadataRequestHandler : public net::URLRequestJob { |
| 21 public: | 21 public: |
| 22 explicit MetadataRequestHandler(URLRequest* request); | 22 explicit MetadataRequestHandler(net::URLRequest* request); |
| 23 | 23 |
| 24 static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); | 24 static URLRequestJob* Factory(net::URLRequest* request, |
| 25 const std::string& scheme); |
| 25 | 26 |
| 26 // URLRequestJob implementation. | 27 // URLRequestJob implementation. |
| 27 virtual void Start(); | 28 virtual void Start(); |
| 28 virtual void Kill(); | 29 virtual void Kill(); |
| 29 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 30 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
| 30 virtual bool GetMimeType(std::string* mime_type) const; | 31 virtual bool GetMimeType(std::string* mime_type) const; |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 ~MetadataRequestHandler(); | 34 ~MetadataRequestHandler(); |
| 34 | 35 |
| 35 void StartAsync(); | 36 void StartAsync(); |
| 36 std::string result_; | 37 std::string result_; |
| 37 bool parsed; | 38 bool parsed; |
| 38 int data_offset_; | 39 int data_offset_; |
| 39 DISALLOW_COPY_AND_ASSIGN(MetadataRequestHandler); | 40 DISALLOW_COPY_AND_ASSIGN(MetadataRequestHandler); |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 MetadataRequestHandler::MetadataRequestHandler(URLRequest* request) | 43 MetadataRequestHandler::MetadataRequestHandler(net::URLRequest* request) |
| 43 : URLRequestJob(request), | 44 : URLRequestJob(request), |
| 44 data_offset_(0) { | 45 data_offset_(0) { |
| 45 parsed = false; | 46 parsed = false; |
| 46 } | 47 } |
| 47 | 48 |
| 48 MetadataRequestHandler::~MetadataRequestHandler() { | 49 MetadataRequestHandler::~MetadataRequestHandler() { |
| 49 } | 50 } |
| 50 | 51 |
| 51 URLRequestJob* MetadataRequestHandler::Factory(URLRequest* request, | 52 URLRequestJob* MetadataRequestHandler::Factory(net::URLRequest* request, |
| 52 const std::string& scheme) { | 53 const std::string& scheme) { |
| 53 return new MetadataRequestHandler(request); | 54 return new MetadataRequestHandler(request); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void MetadataRequestHandler::Start() { | 57 void MetadataRequestHandler::Start() { |
| 57 // Start reading asynchronously so that all error reporting and data | 58 // Start reading asynchronously so that all error reporting and data |
| 58 // callbacks happen as they would for network requests. | 59 // callbacks happen as they would for network requests. |
| 59 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 60 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 60 this, &MetadataRequestHandler::StartAsync)); | 61 this, &MetadataRequestHandler::StartAsync)); |
| 61 } | 62 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 119 } |
| 119 | 120 |
| 120 void MetadataRequestHandler::StartAsync() { | 121 void MetadataRequestHandler::StartAsync() { |
| 121 NotifyHeadersComplete(); | 122 NotifyHeadersComplete(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 } // namespace | 125 } // namespace |
| 125 | 126 |
| 126 void RegisterMetadataURLRequestHandler() { | 127 void RegisterMetadataURLRequestHandler() { |
| 127 #if defined(OS_CHROMEOS) | 128 #if defined(OS_CHROMEOS) |
| 128 URLRequest::RegisterProtocolFactory(chrome::kMetadataScheme, | 129 net::URLRequest::RegisterProtocolFactory(chrome::kMetadataScheme, |
| 129 &MetadataRequestHandler::Factory); | 130 &MetadataRequestHandler::Factory); |
| 130 #endif | 131 #endif |
| 131 } | 132 } |
| OLD | NEW |