| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/url_request/view_cache_helper.h" | 5 #include "net/url_request/view_cache_helper.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "net/base/escape.h" | 8 #include "net/base/escape.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 } // namespace. | 39 } // namespace. |
| 40 | 40 |
| 41 ViewCacheHelper::ViewCacheHelper() | 41 ViewCacheHelper::ViewCacheHelper() |
| 42 : disk_cache_(NULL), | 42 : disk_cache_(NULL), |
| 43 entry_(NULL), | 43 entry_(NULL), |
| 44 iter_(NULL), | 44 iter_(NULL), |
| 45 buf_len_(0), | 45 buf_len_(0), |
| 46 index_(0), | 46 index_(0), |
| 47 data_(NULL), | 47 data_(NULL), |
| 48 callback_(NULL), | |
| 49 next_state_(STATE_NONE), | 48 next_state_(STATE_NONE), |
| 50 ALLOW_THIS_IN_INITIALIZER_LIST( | 49 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 51 cache_callback_(this, &ViewCacheHelper::OnIOComplete)), | 50 cache_callback_(this, &ViewCacheHelper::OnIOComplete)), |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST( | 51 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 53 entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( | 52 entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( |
| 54 this, &ViewCacheHelper::OnIOComplete))) { | 53 this, &ViewCacheHelper::OnIOComplete))) { |
| 55 } | 54 } |
| 56 | 55 |
| 57 ViewCacheHelper::~ViewCacheHelper() { | 56 ViewCacheHelper::~ViewCacheHelper() { |
| 58 if (entry_) | 57 if (entry_) |
| 59 entry_->Close(); | 58 entry_->Close(); |
| 60 | 59 |
| 61 // Cancel any pending entry callback. | 60 // Cancel any pending entry callback. |
| 62 entry_callback_->Cancel(); | 61 entry_callback_->Cancel(); |
| 63 } | 62 } |
| 64 | 63 |
| 65 int ViewCacheHelper::GetEntryInfoHTML(const std::string& key, | 64 int ViewCacheHelper::GetEntryInfoHTML(const std::string& key, |
| 66 const URLRequestContext* context, | 65 const URLRequestContext* context, |
| 67 std::string* out, | 66 std::string* out, |
| 68 OldCompletionCallback* callback) { | 67 const CompletionCallback& callback) { |
| 69 return GetInfoHTML(key, context, std::string(), out, callback); | 68 return GetInfoHTML(key, context, std::string(), out, callback); |
| 70 } | 69 } |
| 71 | 70 |
| 72 int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context, | 71 int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context, |
| 73 const std::string& url_prefix, | 72 const std::string& url_prefix, |
| 74 std::string* out, | 73 std::string* out, |
| 75 OldCompletionCallback* callback) { | 74 const CompletionCallback& callback) { |
| 76 return GetInfoHTML(std::string(), context, url_prefix, out, callback); | 75 return GetInfoHTML(std::string(), context, url_prefix, out, callback); |
| 77 } | 76 } |
| 78 | 77 |
| 79 // static | 78 // static |
| 80 void ViewCacheHelper::HexDump(const char *buf, size_t buf_len, | 79 void ViewCacheHelper::HexDump(const char *buf, size_t buf_len, |
| 81 std::string* result) { | 80 std::string* result) { |
| 82 const size_t kMaxRows = 16; | 81 const size_t kMaxRows = 16; |
| 83 int offset = 0; | 82 int offset = 0; |
| 84 | 83 |
| 85 const unsigned char *p; | 84 const unsigned char *p; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 114 buf_len -= row_max; | 113 buf_len -= row_max; |
| 115 } | 114 } |
| 116 } | 115 } |
| 117 | 116 |
| 118 //----------------------------------------------------------------------------- | 117 //----------------------------------------------------------------------------- |
| 119 | 118 |
| 120 int ViewCacheHelper::GetInfoHTML(const std::string& key, | 119 int ViewCacheHelper::GetInfoHTML(const std::string& key, |
| 121 const URLRequestContext* context, | 120 const URLRequestContext* context, |
| 122 const std::string& url_prefix, | 121 const std::string& url_prefix, |
| 123 std::string* out, | 122 std::string* out, |
| 124 OldCompletionCallback* callback) { | 123 const CompletionCallback& callback) { |
| 125 DCHECK(!callback_); | 124 DCHECK(callback_.is_null()); |
| 126 DCHECK(context); | 125 DCHECK(context); |
| 127 key_ = key; | 126 key_ = key; |
| 128 context_ = context; | 127 context_ = context; |
| 129 url_prefix_ = url_prefix; | 128 url_prefix_ = url_prefix; |
| 130 data_ = out; | 129 data_ = out; |
| 131 next_state_ = STATE_GET_BACKEND; | 130 next_state_ = STATE_GET_BACKEND; |
| 132 int rv = DoLoop(OK); | 131 int rv = DoLoop(OK); |
| 133 | 132 |
| 134 if (rv == ERR_IO_PENDING) | 133 if (rv == ERR_IO_PENDING) |
| 135 callback_ = callback; | 134 callback_ = callback; |
| 136 | 135 |
| 137 return rv; | 136 return rv; |
| 138 } | 137 } |
| 139 | 138 |
| 140 void ViewCacheHelper::DoCallback(int rv) { | 139 void ViewCacheHelper::DoCallback(int rv) { |
| 141 DCHECK_NE(ERR_IO_PENDING, rv); | 140 DCHECK_NE(ERR_IO_PENDING, rv); |
| 142 DCHECK(callback_); | 141 DCHECK(!callback_.is_null()); |
| 143 | 142 |
| 144 OldCompletionCallback* c = callback_; | 143 callback_.Run(rv); |
| 145 callback_ = NULL; | 144 callback_.Reset(); |
| 146 c->Run(rv); | |
| 147 } | 145 } |
| 148 | 146 |
| 149 void ViewCacheHelper::HandleResult(int rv) { | 147 void ViewCacheHelper::HandleResult(int rv) { |
| 150 DCHECK_NE(ERR_IO_PENDING, rv); | 148 DCHECK_NE(ERR_IO_PENDING, rv); |
| 151 DCHECK_NE(ERR_FAILED, rv); | 149 DCHECK_NE(ERR_FAILED, rv); |
| 152 context_ = NULL; | 150 context_ = NULL; |
| 153 if (callback_) | 151 if (!callback_.is_null()) |
| 154 DoCallback(rv); | 152 DoCallback(rv); |
| 155 } | 153 } |
| 156 | 154 |
| 157 int ViewCacheHelper::DoLoop(int result) { | 155 int ViewCacheHelper::DoLoop(int result) { |
| 158 DCHECK(next_state_ != STATE_NONE); | 156 DCHECK(next_state_ != STATE_NONE); |
| 159 | 157 |
| 160 int rv = result; | 158 int rv = result; |
| 161 do { | 159 do { |
| 162 State state = next_state_; | 160 State state = next_state_; |
| 163 next_state_ = STATE_NONE; | 161 next_state_ = STATE_NONE; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 entry_ = NULL; | 348 entry_ = NULL; |
| 351 } | 349 } |
| 352 return OK; | 350 return OK; |
| 353 } | 351 } |
| 354 | 352 |
| 355 void ViewCacheHelper::OnIOComplete(int result) { | 353 void ViewCacheHelper::OnIOComplete(int result) { |
| 356 DoLoop(result); | 354 DoLoop(result); |
| 357 } | 355 } |
| 358 | 356 |
| 359 } // namespace net. | 357 } // namespace net. |
| OLD | NEW |