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

Unified Diff: content/browser/webui/url_data_source_impl.cc

Issue 12093012: Clean up of url data manager classes in content: move URLDataSourceImpl to its own file, move all t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/webui/url_data_source_impl.h ('k') | content/browser/webui/web_ui_data_source.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/webui/url_data_source_impl.cc
===================================================================
--- content/browser/webui/url_data_source_impl.cc (revision 0)
+++ content/browser/webui/url_data_source_impl.cc (revision 0)
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/webui/url_data_source_impl.h"
+
+#include "base/bind.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/string_util.h"
+#include "content/browser/webui/url_data_manager_backend.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/url_data_source.h"
+
+namespace content {
+
+URLDataSourceImpl::URLDataSourceImpl(const std::string& source_name,
+ URLDataSource* source)
+ : source_name_(source_name),
+ backend_(NULL),
+ source_(source) {
+}
+
+URLDataSourceImpl::~URLDataSourceImpl() {
+}
+
+void URLDataSourceImpl::SendResponse(
+ int request_id,
+ base::RefCountedMemory* bytes) {
+ // Take a ref-pointer on entry so byte->Release() will always get called.
+ scoped_refptr<base::RefCountedMemory> bytes_ptr(bytes);
+ if (URLDataManager::IsScheduledForDeletion(this)) {
+ // We're scheduled for deletion. Servicing the request would result in
+ // this->AddRef being invoked, even though the ref count is 0 and 'this' is
+ // about to be deleted. If the AddRef were allowed through, when 'this' is
+ // released it would be deleted again.
+ //
+ // This scenario occurs with DataSources that make history requests. Such
+ // DataSources do a history query in |StartDataRequest| and the request is
+ // live until the object is deleted (history requests don't up the ref
+ // count). This means it's entirely possible for the DataSource to invoke
+ // |SendResponse| between the time when there are no more refs and the time
+ // when the object is deleted.
+ return;
+ }
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&URLDataSourceImpl::SendResponseOnIOThread, this, request_id,
+ bytes_ptr));
+}
+
+void URLDataSourceImpl::SendResponseOnIOThread(
+ int request_id,
+ scoped_refptr<base::RefCountedMemory> bytes) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (backend_)
+ backend_->DataAvailable(request_id, bytes);
+}
+
+} // namespace content
Property changes on: content\browser\webui\url_data_source_impl.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « content/browser/webui/url_data_source_impl.h ('k') | content/browser/webui/web_ui_data_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698