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

Side by Side Diff: ios/web/webui/url_data_source_ios_impl.cc

Issue 1110213002: Upstream most of the iOS WebUI support in ios/web/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/webui/url_data_source_impl.h" 5 #include "ios/web/webui/url_data_source_ios_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h"
8 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "content/browser/webui/url_data_manager_backend.h" 11 #include "ios/web/public/url_data_source_ios.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "ios/web/public/web_thread.h"
12 #include "content/public/browser/url_data_source.h" 13 #include "ios/web/webui/url_data_manager_ios_backend.h"
13 14
14 namespace content { 15 namespace web {
15 16
16 URLDataSourceImpl::URLDataSourceImpl(const std::string& source_name, 17 URLDataSourceIOSImpl::URLDataSourceIOSImpl(const std::string& source_name,
17 URLDataSource* source) 18 URLDataSourceIOS* source)
18 : source_name_(source_name), 19 : source_name_(source_name), backend_(NULL), source_(source) {
19 backend_(NULL),
20 source_(source) {
21 } 20 }
22 21
23 URLDataSourceImpl::~URLDataSourceImpl() { 22 URLDataSourceIOSImpl::~URLDataSourceIOSImpl() {
24 } 23 }
25 24
26 void URLDataSourceImpl::SendResponse( 25 void URLDataSourceIOSImpl::SendResponse(int request_id,
27 int request_id, 26 base::RefCountedMemory* bytes) {
28 base::RefCountedMemory* bytes) {
29 // Take a ref-pointer on entry so byte->Release() will always get called. 27 // Take a ref-pointer on entry so byte->Release() will always get called.
30 scoped_refptr<base::RefCountedMemory> bytes_ptr(bytes); 28 scoped_refptr<base::RefCountedMemory> bytes_ptr(bytes);
31 if (URLDataManager::IsScheduledForDeletion(this)) { 29 if (URLDataManagerIOS::IsScheduledForDeletion(this)) {
32 // We're scheduled for deletion. Servicing the request would result in 30 // We're scheduled for deletion. Servicing the request would result in
33 // this->AddRef being invoked, even though the ref count is 0 and 'this' is 31 // this->AddRef being invoked, even though the ref count is 0 and 'this' is
34 // about to be deleted. If the AddRef were allowed through, when 'this' is 32 // about to be deleted. If the AddRef were allowed through, when 'this' is
35 // released it would be deleted again. 33 // released it would be deleted again.
36 // 34 //
37 // This scenario occurs with DataSources that make history requests. Such 35 // This scenario occurs with DataSources that make history requests. Such
38 // DataSources do a history query in |StartDataRequest| and the request is 36 // DataSources do a history query in |StartDataRequest| and the request is
39 // live until the object is deleted (history requests don't up the ref 37 // live until the object is deleted (history requests don't up the ref
40 // count). This means it's entirely possible for the DataSource to invoke 38 // count). This means it's entirely possible for the DataSource to invoke
41 // |SendResponse| between the time when there are no more refs and the time 39 // |SendResponse| between the time when there are no more refs and the time
42 // when the object is deleted. 40 // when the object is deleted.
43 return; 41 return;
44 } 42 }
45 BrowserThread::PostTask( 43 web::WebThread::PostTask(
46 BrowserThread::IO, FROM_HERE, 44 web::WebThread::IO, FROM_HERE,
47 base::Bind(&URLDataSourceImpl::SendResponseOnIOThread, this, request_id, 45 base::Bind(&URLDataSourceIOSImpl::SendResponseOnIOThread, this,
48 bytes_ptr)); 46 request_id, bytes_ptr));
49 } 47 }
50 48
51 void URLDataSourceImpl::SendResponseOnIOThread( 49 void URLDataSourceIOSImpl::SendResponseOnIOThread(
52 int request_id, 50 int request_id,
53 scoped_refptr<base::RefCountedMemory> bytes) { 51 scoped_refptr<base::RefCountedMemory> bytes) {
54 DCHECK_CURRENTLY_ON(BrowserThread::IO); 52 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
55 if (backend_) 53 if (backend_)
56 backend_->DataAvailable(request_id, bytes.get()); 54 backend_->DataAvailable(request_id, bytes.get());
57 } 55 }
58 56
59 } // namespace content 57 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698