| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/view_http_cache_job_factory.h" | 5 #include "chrome/browser/net/view_http_cache_job_factory.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 13 #include "net/url_request/url_request_simple_job.h" | 13 #include "net/url_request/url_request_simple_job.h" |
| 14 #include "net/url_request/view_cache_helper.h" | 14 #include "net/url_request/view_cache_helper.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // A job subclass that dumps an HTTP cache entry. | 18 // A job subclass that dumps an HTTP cache entry. |
| 19 class ViewHttpCacheJob : public net::URLRequestJob { | 19 class ViewHttpCacheJob : public net::URLRequestJob { |
| 20 public: | 20 public: |
| 21 explicit ViewHttpCacheJob(net::URLRequest* request) | 21 explicit ViewHttpCacheJob(net::URLRequest* request) |
| 22 : URLRequestJob(request), data_offset_(0), cancel_(false), busy_(false), | 22 : net::URLRequestJob(request), |
| 23 data_offset_(0), |
| 24 cancel_(false), |
| 25 busy_(false), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST( | 26 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 24 callback_(this, &ViewHttpCacheJob::OnIOComplete)) {} | 27 callback_(this, &ViewHttpCacheJob::OnIOComplete)) {} |
| 25 | 28 |
| 26 virtual void Start(); | 29 virtual void Start(); |
| 27 virtual void Kill(); | 30 virtual void Kill(); |
| 28 virtual bool GetMimeType(std::string* mime_type) const; | 31 virtual bool GetMimeType(std::string* mime_type) const; |
| 29 virtual bool GetCharset(std::string* charset); | 32 virtual bool GetCharset(std::string* charset); |
| 30 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 33 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
| 31 | 34 |
| 32 private: | 35 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 71 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 69 this, &ViewHttpCacheJob::OnIOComplete, rv)); | 72 this, &ViewHttpCacheJob::OnIOComplete, rv)); |
| 70 } | 73 } |
| 71 } | 74 } |
| 72 | 75 |
| 73 void ViewHttpCacheJob::Kill() { | 76 void ViewHttpCacheJob::Kill() { |
| 74 // We don't want to delete this object while we are busy; we'll do it when it | 77 // We don't want to delete this object while we are busy; we'll do it when it |
| 75 // is safe. | 78 // is safe. |
| 76 cancel_ = true; | 79 cancel_ = true; |
| 77 if (!busy_) | 80 if (!busy_) |
| 78 URLRequestJob::Kill(); | 81 net::URLRequestJob::Kill(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 bool ViewHttpCacheJob::GetMimeType(std::string* mime_type) const { | 84 bool ViewHttpCacheJob::GetMimeType(std::string* mime_type) const { |
| 82 mime_type->assign("text/html"); | 85 mime_type->assign("text/html"); |
| 83 return true; | 86 return true; |
| 84 } | 87 } |
| 85 | 88 |
| 86 bool ViewHttpCacheJob::GetCharset(std::string* charset) { | 89 bool ViewHttpCacheJob::GetCharset(std::string* charset) { |
| 87 charset->assign("UTF-8"); | 90 charset->assign("UTF-8"); |
| 88 return true; | 91 return true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 } | 104 } |
| 102 | 105 |
| 103 void ViewHttpCacheJob::OnIOComplete(int result) { | 106 void ViewHttpCacheJob::OnIOComplete(int result) { |
| 104 // We may be holding the last reference to this job. | 107 // We may be holding the last reference to this job. |
| 105 scoped_refptr<ViewHttpCacheJob> self(this); | 108 scoped_refptr<ViewHttpCacheJob> self(this); |
| 106 DCHECK_EQ(net::OK, result); | 109 DCHECK_EQ(net::OK, result); |
| 107 busy_ = false; | 110 busy_ = false; |
| 108 Release(); // Acquired on Start(). | 111 Release(); // Acquired on Start(). |
| 109 | 112 |
| 110 if (cancel_) | 113 if (cancel_) |
| 111 return URLRequestJob::Kill(); | 114 return net::URLRequestJob::Kill(); |
| 112 | 115 |
| 113 // Notify that the headers are complete. | 116 // Notify that the headers are complete. |
| 114 NotifyHeadersComplete(); | 117 NotifyHeadersComplete(); |
| 115 } | 118 } |
| 116 | 119 |
| 117 } // namespace. | 120 } // namespace. |
| 118 | 121 |
| 119 // Static. | 122 // Static. |
| 120 bool ViewHttpCacheJobFactory::IsSupportedURL(const GURL& url) { | 123 bool ViewHttpCacheJobFactory::IsSupportedURL(const GURL& url) { |
| 121 return StartsWithASCII(url.spec(), chrome::kNetworkViewCacheURL, | 124 return StartsWithASCII(url.spec(), chrome::kNetworkViewCacheURL, |
| 122 true /*case_sensitive*/); | 125 true /*case_sensitive*/); |
| 123 } | 126 } |
| 124 | 127 |
| 125 // Static. | 128 // Static. |
| 126 URLRequestJob* ViewHttpCacheJobFactory::CreateJobForRequest( | 129 net::URLRequestJob* ViewHttpCacheJobFactory::CreateJobForRequest( |
| 127 net::URLRequest* request) { | 130 net::URLRequest* request) { |
| 128 return new ViewHttpCacheJob(request); | 131 return new ViewHttpCacheJob(request); |
| 129 } | 132 } |
| OLD | NEW |