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

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/resource_context_impl.h"
19 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 19 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/url_data_source.h" 21 #include "content/public/browser/url_data_source.h"
22 22
23 using content::BrowserContext;
23 using content::BrowserThread; 24 using content::BrowserThread;
24 25
26 namespace {
27
28 static const char* kURLDataManagerKeyName = "url_data_manager";
29
25 static base::LazyInstance<base::Lock>::Leaky 30 static base::LazyInstance<base::Lock>::Leaky
26 g_delete_lock = LAZY_INSTANCE_INITIALIZER; 31 g_delete_lock = LAZY_INSTANCE_INITIALIZER;
27 32
33 ChromeURLDataManager* GetFromBrowserContext(BrowserContext* context) {
34 if (!context->GetUserData(kURLDataManagerKeyName)) {
35 context->SetUserData(kURLDataManagerKeyName,
36 new ChromeURLDataManager(context));
37 }
38 return static_cast<ChromeURLDataManager*>(
39 context->GetUserData(kURLDataManagerKeyName));
40 }
41
42 // Invoked on the IO thread to do the actual adding of the DataSource.
43 static void AddDataSourceOnIOThread(
44 content::ResourceContext* resource_context,
45 scoped_refptr<URLDataSourceImpl> data_source) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
47 GetURLDataManagerForResourceContext(resource_context)->AddDataSource(
48 data_source.get());
49 }
50
51 } // namespace
52
53
28 // static 54 // static
29 ChromeURLDataManager::URLDataSources* ChromeURLDataManager::data_sources_ = 55 ChromeURLDataManager::URLDataSources* ChromeURLDataManager::data_sources_ =
30 NULL; 56 NULL;
31 57
32 // Invoked on the IO thread to do the actual adding of the DataSource.
33 static void AddDataSourceOnIOThread(
34 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend,
35 scoped_refptr<URLDataSourceImpl> data_source) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 backend.Run()->AddDataSource(data_source.get());
38 }
39
40 ChromeURLDataManager::ChromeURLDataManager( 58 ChromeURLDataManager::ChromeURLDataManager(
41 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend) 59 content::BrowserContext* browser_context)
42 : backend_(backend) { 60 : browser_context_(browser_context) {
43 } 61 }
44 62
45 ChromeURLDataManager::~ChromeURLDataManager() { 63 ChromeURLDataManager::~ChromeURLDataManager() {
46 } 64 }
47 65
48 void ChromeURLDataManager::AddDataSource(URLDataSourceImpl* source) { 66 void ChromeURLDataManager::AddDataSource(URLDataSourceImpl* source) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 BrowserThread::PostTask( 68 BrowserThread::PostTask(
51 BrowserThread::IO, FROM_HERE, 69 BrowserThread::IO, FROM_HERE,
52 base::Bind(&AddDataSourceOnIOThread, 70 base::Bind(&AddDataSourceOnIOThread,
53 backend_, make_scoped_refptr(source))); 71 browser_context_->GetResourceContext(),
72 make_scoped_refptr(source)));
54 } 73 }
55 74
56 // static 75 // static
57 void ChromeURLDataManager::DeleteDataSources() { 76 void ChromeURLDataManager::DeleteDataSources() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 URLDataSources sources; 78 URLDataSources sources;
60 { 79 {
61 base::AutoLock lock(g_delete_lock.Get()); 80 base::AutoLock lock(g_delete_lock.Get());
62 if (!data_sources_) 81 if (!data_sources_)
63 return; 82 return;
(...skipping 26 matching lines...) Expand all
90 if (schedule_delete) { 109 if (schedule_delete) {
91 // Schedule a task to delete the DataSource back on the UI thread. 110 // Schedule a task to delete the DataSource back on the UI thread.
92 BrowserThread::PostTask( 111 BrowserThread::PostTask(
93 BrowserThread::UI, FROM_HERE, 112 BrowserThread::UI, FROM_HERE,
94 base::Bind(&ChromeURLDataManager::DeleteDataSources)); 113 base::Bind(&ChromeURLDataManager::DeleteDataSources));
95 } 114 }
96 } 115 }
97 116
98 // static 117 // static
99 void ChromeURLDataManager::AddDataSource( 118 void ChromeURLDataManager::AddDataSource(
100 Profile* profile, 119 content::BrowserContext* browser_context,
101 content::URLDataSource* source) { 120 content::URLDataSource* source) {
102 ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource( 121 GetFromBrowserContext(browser_context)->
103 new URLDataSourceImpl(source->GetSource(), source)); 122 AddDataSource(new URLDataSourceImpl(source->GetSource(), source));
104 } 123 }
105 124
106 // static 125 // static
107 void ChromeURLDataManager::AddWebUIDataSource( 126 void ChromeURLDataManager::AddWebUIDataSource(
108 Profile* profile, 127 content::BrowserContext* browser_context,
109 content::WebUIDataSource* source) { 128 content::WebUIDataSource* source) {
110 ChromeWebUIDataSource* impl = static_cast<ChromeWebUIDataSource*>(source); 129 ChromeWebUIDataSource* impl = static_cast<ChromeWebUIDataSource*>(source);
111 ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource(impl); 130 GetFromBrowserContext(browser_context)->AddDataSource(impl);
112 } 131 }
113 132
114 // static 133 // static
115 bool ChromeURLDataManager::IsScheduledForDeletion( 134 bool ChromeURLDataManager::IsScheduledForDeletion(
116 const URLDataSourceImpl* data_source) { 135 const URLDataSourceImpl* data_source) {
117 base::AutoLock lock(g_delete_lock.Get()); 136 base::AutoLock lock(g_delete_lock.Get());
118 if (!data_sources_) 137 if (!data_sources_)
119 return false; 138 return false;
120 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != 139 return std::find(data_sources_->begin(), data_sources_->end(), data_source) !=
121 data_sources_->end(); 140 data_sources_->end();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 bytes_ptr)); 175 bytes_ptr));
157 } 176 }
158 177
159 void URLDataSourceImpl::SendResponseOnIOThread( 178 void URLDataSourceImpl::SendResponseOnIOThread(
160 int request_id, 179 int request_id,
161 scoped_refptr<base::RefCountedMemory> bytes) { 180 scoped_refptr<base::RefCountedMemory> bytes) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
163 if (backend_) 182 if (backend_)
164 backend_->DataAvailable(request_id, bytes); 183 backend_->DataAvailable(request_id, bytes);
165 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698