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

Side by Side Diff: content/browser/webui/url_data_manager.cc

Issue 12049052: Move core url data manager classes to content. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/webui/url_data_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "content/browser/webui/url_data_manager_backend.h"
17 #include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h" 17 #include "content/browser/webui/web_ui_data_source.h"
18 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 18 #include "content/browser/storage_partition_impl.h"
19 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 19 #include "content/browser/resource_context_impl.h"
20 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/url_data_source.h" 22 #include "content/public/browser/url_data_source.h"
22 23
23 using content::BrowserThread; 24 using content::BrowserThread;
25 using content::StoragePartitionImpl;
24 26
25 static base::LazyInstance<base::Lock>::Leaky 27 static base::LazyInstance<base::Lock>::Leaky
26 g_delete_lock = LAZY_INSTANCE_INITIALIZER; 28 g_delete_lock = LAZY_INSTANCE_INITIALIZER;
27 29
28 // static 30 // static
29 ChromeURLDataManager::URLDataSources* ChromeURLDataManager::data_sources_ = 31 ChromeURLDataManager::URLDataSources* ChromeURLDataManager::data_sources_ =
30 NULL; 32 NULL;
31 33
32 // Invoked on the IO thread to do the actual adding of the DataSource. 34 // Invoked on the IO thread to do the actual adding of the DataSource.
33 static void AddDataSourceOnIOThread( 35 static void AddDataSourceOnIOThread(
34 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend, 36 content::ResourceContext* resource_context,
35 scoped_refptr<URLDataSourceImpl> data_source) { 37 scoped_refptr<URLDataSourceImpl> data_source) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 backend.Run()->AddDataSource(data_source.get()); 39 GetURLDataManagerForResourceContext(resource_context)->AddDataSource(
40 data_source.get());
38 } 41 }
39 42
40 ChromeURLDataManager::ChromeURLDataManager( 43 ChromeURLDataManager::ChromeURLDataManager(
41 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend) 44 content::BrowserContext* browser_context)
42 : backend_(backend) { 45 : browser_context_(browser_context) {
43 } 46 }
44 47
45 ChromeURLDataManager::~ChromeURLDataManager() { 48 ChromeURLDataManager::~ChromeURLDataManager() {
46 } 49 }
47 50
48 void ChromeURLDataManager::AddDataSource(URLDataSourceImpl* source) { 51 void ChromeURLDataManager::AddDataSource(URLDataSourceImpl* source) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 BrowserThread::PostTask( 53 BrowserThread::PostTask(
51 BrowserThread::IO, FROM_HERE, 54 BrowserThread::IO, FROM_HERE,
52 base::Bind(&AddDataSourceOnIOThread, 55 base::Bind(&AddDataSourceOnIOThread,
53 backend_, make_scoped_refptr(source))); 56 browser_context_->GetResourceContext(),
57 make_scoped_refptr(source)));
54 } 58 }
55 59
56 // static 60 // static
57 void ChromeURLDataManager::DeleteDataSources() { 61 void ChromeURLDataManager::DeleteDataSources() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 URLDataSources sources; 63 URLDataSources sources;
60 { 64 {
61 base::AutoLock lock(g_delete_lock.Get()); 65 base::AutoLock lock(g_delete_lock.Get());
62 if (!data_sources_) 66 if (!data_sources_)
63 return; 67 return;
(...skipping 26 matching lines...) Expand all
90 if (schedule_delete) { 94 if (schedule_delete) {
91 // Schedule a task to delete the DataSource back on the UI thread. 95 // Schedule a task to delete the DataSource back on the UI thread.
92 BrowserThread::PostTask( 96 BrowserThread::PostTask(
93 BrowserThread::UI, FROM_HERE, 97 BrowserThread::UI, FROM_HERE,
94 base::Bind(&ChromeURLDataManager::DeleteDataSources)); 98 base::Bind(&ChromeURLDataManager::DeleteDataSources));
95 } 99 }
96 } 100 }
97 101
98 // static 102 // static
99 void ChromeURLDataManager::AddDataSource( 103 void ChromeURLDataManager::AddDataSource(
100 Profile* profile, 104 content::BrowserContext* browser_context,
101 content::URLDataSource* source) { 105 content::URLDataSource* source) {
102 ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource( 106 content::StoragePartition* storage_partition =
103 new URLDataSourceImpl(source->GetSource(), source)); 107 content::BrowserContext::GetDefaultStoragePartition(browser_context);
108 static_cast<StoragePartitionImpl*>(storage_partition)->url_data_manager()->
109 AddDataSource(new URLDataSourceImpl(source->GetSource(), source));
104 } 110 }
105 111
106 // static 112 // static
107 void ChromeURLDataManager::AddWebUIDataSource( 113 void ChromeURLDataManager::AddWebUIDataSource(
108 Profile* profile, 114 content::BrowserContext* browser_context,
109 content::WebUIDataSource* source) { 115 content::WebUIDataSource* source) {
110 ChromeWebUIDataSource* impl = static_cast<ChromeWebUIDataSource*>(source); 116 ChromeWebUIDataSource* impl = static_cast<ChromeWebUIDataSource*>(source);
111 ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource(impl); 117 content::StoragePartition* storage_partition =
118 content::BrowserContext::GetDefaultStoragePartition(browser_context);
119 static_cast<StoragePartitionImpl*>(storage_partition)->url_data_manager()->
120 AddDataSource(impl);
112 } 121 }
113 122
114 // static 123 // static
115 bool ChromeURLDataManager::IsScheduledForDeletion( 124 bool ChromeURLDataManager::IsScheduledForDeletion(
116 const URLDataSourceImpl* data_source) { 125 const URLDataSourceImpl* data_source) {
117 base::AutoLock lock(g_delete_lock.Get()); 126 base::AutoLock lock(g_delete_lock.Get());
118 if (!data_sources_) 127 if (!data_sources_)
119 return false; 128 return false;
120 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != 129 return std::find(data_sources_->begin(), data_sources_->end(), data_source) !=
121 data_sources_->end(); 130 data_sources_->end();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 bytes_ptr)); 165 bytes_ptr));
157 } 166 }
158 167
159 void URLDataSourceImpl::SendResponseOnIOThread( 168 void URLDataSourceImpl::SendResponseOnIOThread(
160 int request_id, 169 int request_id,
161 scoped_refptr<base::RefCountedMemory> bytes) { 170 scoped_refptr<base::RefCountedMemory> bytes) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
163 if (backend_) 172 if (backend_)
164 backend_->DataAvailable(request_id, bytes); 173 backend_->DataAvailable(request_id, bytes);
165 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698