| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 DCHECK(slash != std::string::npos); | 54 DCHECK(slash != std::string::npos); |
| 55 url = GURL(key.substr(slash + 1)); | 55 url = GURL(key.substr(slash + 1)); |
| 56 } else { | 56 } else { |
| 57 url = GURL(key); | 57 url = GURL(key); |
| 58 } | 58 } |
| 59 const MockTransaction* t = FindMockTransaction(url); | 59 const MockTransaction* t = FindMockTransaction(url); |
| 60 DCHECK(t); | 60 DCHECK(t); |
| 61 test_mode_ = t->test_mode; | 61 test_mode_ = t->test_mode; |
| 62 } | 62 } |
| 63 | 63 |
| 64 ~MockDiskEntry() { | |
| 65 } | |
| 66 | |
| 67 bool is_doomed() const { return doomed_; } | 64 bool is_doomed() const { return doomed_; } |
| 68 | 65 |
| 69 virtual void Doom() { | 66 virtual void Doom() { |
| 70 doomed_ = true; | 67 doomed_ = true; |
| 71 } | 68 } |
| 72 | 69 |
| 73 virtual void Close() { | 70 virtual void Close() { |
| 74 Release(); | 71 Release(); |
| 75 } | 72 } |
| 76 | 73 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // The pending operation is already in the message loop (and hopefuly | 239 // The pending operation is already in the message loop (and hopefuly |
| 243 // already in the second pass). Just notify the caller that it finished. | 240 // already in the second pass). Just notify the caller that it finished. |
| 244 CallbackLater(completion_callback, 0); | 241 CallbackLater(completion_callback, 0); |
| 245 return net::ERR_IO_PENDING; | 242 return net::ERR_IO_PENDING; |
| 246 } | 243 } |
| 247 | 244 |
| 248 // Fail most subsequent requests. | 245 // Fail most subsequent requests. |
| 249 void set_fail_requests() { fail_requests_ = true; } | 246 void set_fail_requests() { fail_requests_ = true; } |
| 250 | 247 |
| 251 private: | 248 private: |
| 249 friend class base::RefCounted<MockDiskEntry>; |
| 250 |
| 251 ~MockDiskEntry() {} |
| 252 |
| 252 // Unlike the callbacks for MockHttpTransaction, we want this one to run even | 253 // Unlike the callbacks for MockHttpTransaction, we want this one to run even |
| 253 // if the consumer called Close on the MockDiskEntry. We achieve that by | 254 // if the consumer called Close on the MockDiskEntry. We achieve that by |
| 254 // leveraging the fact that this class is reference counted. | 255 // leveraging the fact that this class is reference counted. |
| 255 void CallbackLater(net::CompletionCallback* callback, int result) { | 256 void CallbackLater(net::CompletionCallback* callback, int result) { |
| 256 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, | 257 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 257 &MockDiskEntry::RunCallback, callback, result)); | 258 &MockDiskEntry::RunCallback, callback, result)); |
| 258 } | 259 } |
| 259 void RunCallback(net::CompletionCallback* callback, int result) { | 260 void RunCallback(net::CompletionCallback* callback, int result) { |
| 260 if (busy_) { | 261 if (busy_) { |
| 261 // This is kind of hacky, but controlling the behavior of just this entry | 262 // This is kind of hacky, but controlling the behavior of just this entry |
| (...skipping 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3410 std::string headers; | 3411 std::string headers; |
| 3411 response.headers->GetNormalizedHeaders(&headers); | 3412 response.headers->GetNormalizedHeaders(&headers); |
| 3412 | 3413 |
| 3413 EXPECT_EQ("HTTP/1.1 200 OK\n" | 3414 EXPECT_EQ("HTTP/1.1 200 OK\n" |
| 3414 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 3415 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
| 3415 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 3416 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
| 3416 headers); | 3417 headers); |
| 3417 | 3418 |
| 3418 RemoveMockTransaction(&mock_network_response); | 3419 RemoveMockTransaction(&mock_network_response); |
| 3419 } | 3420 } |
| OLD | NEW |