Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/ui/webui/chrome_url_data_manager.cc

Issue 7489044: Fix potential leak (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/webui/chrome_url_data_manager.h" 5 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 : source_name_(source_name), 112 : source_name_(source_name),
113 message_loop_(message_loop), 113 message_loop_(message_loop),
114 backend_(NULL) { 114 backend_(NULL) {
115 } 115 }
116 116
117 ChromeURLDataManager::DataSource::~DataSource() { 117 ChromeURLDataManager::DataSource::~DataSource() {
118 } 118 }
119 119
120 void ChromeURLDataManager::DataSource::SendResponse(int request_id, 120 void ChromeURLDataManager::DataSource::SendResponse(int request_id,
121 RefCountedMemory* bytes) { 121 RefCountedMemory* bytes) {
122 // Take a ref-pointer on entry so byte->Release() will always get called.
123 scoped_refptr<RefCountedMemory> bytes_ptr(bytes);
122 if (IsScheduledForDeletion(this)) { 124 if (IsScheduledForDeletion(this)) {
123 // We're scheduled for deletion. Servicing the request would result in 125 // We're scheduled for deletion. Servicing the request would result in
124 // this->AddRef being invoked, even though the ref count is 0 and 'this' is 126 // this->AddRef being invoked, even though the ref count is 0 and 'this' is
125 // about to be deleted. If the AddRef were allowed through, when 'this' is 127 // about to be deleted. If the AddRef were allowed through, when 'this' is
126 // released it would be deleted again. 128 // released it would be deleted again.
127 // 129 //
128 // This scenario occurs with DataSources that make history requests. Such 130 // This scenario occurs with DataSources that make history requests. Such
129 // DataSources do a history query in |StartDataRequest| and the request is 131 // DataSources do a history query in |StartDataRequest| and the request is
130 // live until the object is deleted (history requests don't up the ref 132 // live until the object is deleted (history requests don't up the ref
131 // count). This means it's entirely possible for the DataSource to invoke 133 // count). This means it's entirely possible for the DataSource to invoke
132 // |SendResponse| between the time when there are no more refs and the time 134 // |SendResponse| between the time when there are no more refs and the time
133 // when the object is deleted. 135 // when the object is deleted.
134 return; 136 return;
135 } 137 }
136 BrowserThread::PostTask( 138 BrowserThread::PostTask(
137 BrowserThread::IO, FROM_HERE, 139 BrowserThread::IO, FROM_HERE,
138 NewRunnableMethod(this, &DataSource::SendResponseOnIOThread, 140 NewRunnableMethod(this, &DataSource::SendResponseOnIOThread,
139 request_id, make_scoped_refptr(bytes))); 141 request_id, bytes_ptr));
140 } 142 }
141 143
142 MessageLoop* ChromeURLDataManager::DataSource::MessageLoopForRequestPath( 144 MessageLoop* ChromeURLDataManager::DataSource::MessageLoopForRequestPath(
143 const std::string& path) const { 145 const std::string& path) const {
144 return message_loop_; 146 return message_loop_;
145 } 147 }
146 148
147 bool ChromeURLDataManager::DataSource::ShouldReplaceExistingSource() const { 149 bool ChromeURLDataManager::DataSource::ShouldReplaceExistingSource() const {
148 return true; 150 return true;
149 } 151 }
(...skipping 18 matching lines...) Expand all
168 base::i18n::IsRTL() ? "rtl" : "ltr"); 170 base::i18n::IsRTL() ? "rtl" : "ltr");
169 } 171 }
170 172
171 void ChromeURLDataManager::DataSource::SendResponseOnIOThread( 173 void ChromeURLDataManager::DataSource::SendResponseOnIOThread(
172 int request_id, 174 int request_id,
173 scoped_refptr<RefCountedMemory> bytes) { 175 scoped_refptr<RefCountedMemory> bytes) {
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
175 if (backend_) 177 if (backend_)
176 backend_->DataAvailable(request_id, bytes); 178 backend_->DataAvailable(request_id, bytes);
177 } 179 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698