OLD | NEW |
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 "content/browser/webui/url_data_manager.h" | 5 #include "content/browser/webui/url_data_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" |
12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
13 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "content/browser/resource_context_impl.h" | 18 #include "content/browser/resource_context_impl.h" |
18 #include "content/browser/webui/url_data_manager_backend.h" | 19 #include "content/browser/webui/url_data_manager_backend.h" |
19 #include "content/browser/webui/url_data_source_impl.h" | 20 #include "content/browser/webui/url_data_source_impl.h" |
20 #include "content/browser/webui/web_ui_data_source_impl.h" | 21 #include "content/browser/webui/web_ui_data_source_impl.h" |
21 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
(...skipping 17 matching lines...) Expand all Loading... |
39 | 40 |
40 // Invoked on the IO thread to do the actual adding of the DataSource. | 41 // Invoked on the IO thread to do the actual adding of the DataSource. |
41 static void AddDataSourceOnIOThread( | 42 static void AddDataSourceOnIOThread( |
42 ResourceContext* resource_context, | 43 ResourceContext* resource_context, |
43 scoped_refptr<URLDataSourceImpl> data_source) { | 44 scoped_refptr<URLDataSourceImpl> data_source) { |
44 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
45 GetURLDataManagerForResourceContext(resource_context)->AddDataSource( | 46 GetURLDataManagerForResourceContext(resource_context)->AddDataSource( |
46 data_source.get()); | 47 data_source.get()); |
47 } | 48 } |
48 | 49 |
| 50 static void UpdateWebUIDataSourceOnIOThread( |
| 51 ResourceContext* resource_context, |
| 52 std::string source_name, |
| 53 const base::DictionaryValue* update) { |
| 54 GetURLDataManagerForResourceContext(resource_context) |
| 55 ->UpdateWebUIDataSource(source_name, *update); |
| 56 } |
| 57 |
49 } // namespace | 58 } // namespace |
50 | 59 |
51 // static | 60 // static |
52 URLDataManager::URLDataSources* URLDataManager::data_sources_ = NULL; | 61 URLDataManager::URLDataSources* URLDataManager::data_sources_ = NULL; |
53 | 62 |
54 URLDataManager::URLDataManager(BrowserContext* browser_context) | 63 URLDataManager::URLDataManager(BrowserContext* browser_context) |
55 : browser_context_(browser_context) { | 64 : browser_context_(browser_context) { |
56 } | 65 } |
57 | 66 |
58 URLDataManager::~URLDataManager() { | 67 URLDataManager::~URLDataManager() { |
59 } | 68 } |
60 | 69 |
61 void URLDataManager::AddDataSource(URLDataSourceImpl* source) { | 70 void URLDataManager::AddDataSource(URLDataSourceImpl* source) { |
62 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
63 BrowserThread::PostTask( | 72 BrowserThread::PostTask( |
64 BrowserThread::IO, FROM_HERE, | 73 BrowserThread::IO, FROM_HERE, |
65 base::Bind(&AddDataSourceOnIOThread, | 74 base::Bind(&AddDataSourceOnIOThread, |
66 browser_context_->GetResourceContext(), | 75 browser_context_->GetResourceContext(), |
67 make_scoped_refptr(source))); | 76 make_scoped_refptr(source))); |
68 } | 77 } |
69 | 78 |
| 79 void URLDataManager::UpdateWebUIDataSource( |
| 80 const std::string& source_name, |
| 81 std::unique_ptr<base::DictionaryValue> update) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 83 BrowserThread::PostTask( |
| 84 BrowserThread::IO, FROM_HERE, |
| 85 base::Bind(&UpdateWebUIDataSourceOnIOThread, |
| 86 browser_context_->GetResourceContext(), source_name, |
| 87 base::Owned(update.release()))); |
| 88 } |
| 89 |
70 // static | 90 // static |
71 void URLDataManager::DeleteDataSources() { | 91 void URLDataManager::DeleteDataSources() { |
72 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
73 URLDataSources sources; | 93 URLDataSources sources; |
74 { | 94 { |
75 base::AutoLock lock(g_delete_lock.Get()); | 95 base::AutoLock lock(g_delete_lock.Get()); |
76 if (!data_sources_) | 96 if (!data_sources_) |
77 return; | 97 return; |
78 data_sources_->swap(sources); | 98 data_sources_->swap(sources); |
79 } | 99 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 AddDataSource(new URLDataSourceImpl(source->GetSource(), source)); | 135 AddDataSource(new URLDataSourceImpl(source->GetSource(), source)); |
116 } | 136 } |
117 | 137 |
118 // static | 138 // static |
119 void URLDataManager::AddWebUIDataSource(BrowserContext* browser_context, | 139 void URLDataManager::AddWebUIDataSource(BrowserContext* browser_context, |
120 WebUIDataSource* source) { | 140 WebUIDataSource* source) { |
121 WebUIDataSourceImpl* impl = static_cast<WebUIDataSourceImpl*>(source); | 141 WebUIDataSourceImpl* impl = static_cast<WebUIDataSourceImpl*>(source); |
122 GetFromBrowserContext(browser_context)->AddDataSource(impl); | 142 GetFromBrowserContext(browser_context)->AddDataSource(impl); |
123 } | 143 } |
124 | 144 |
| 145 void URLDataManager::UpdateWebUIDataSource( |
| 146 BrowserContext* browser_context, |
| 147 const std::string& source_name, |
| 148 std::unique_ptr<base::DictionaryValue> update) { |
| 149 GetFromBrowserContext(browser_context) |
| 150 ->UpdateWebUIDataSource(source_name, std::move(update)); |
| 151 } |
| 152 |
125 // static | 153 // static |
126 bool URLDataManager::IsScheduledForDeletion( | 154 bool URLDataManager::IsScheduledForDeletion( |
127 const URLDataSourceImpl* data_source) { | 155 const URLDataSourceImpl* data_source) { |
128 base::AutoLock lock(g_delete_lock.Get()); | 156 base::AutoLock lock(g_delete_lock.Get()); |
129 if (!data_sources_) | 157 if (!data_sources_) |
130 return false; | 158 return false; |
131 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != | 159 return std::find(data_sources_->begin(), data_sources_->end(), data_source) != |
132 data_sources_->end(); | 160 data_sources_->end(); |
133 } | 161 } |
134 | 162 |
135 } // namespace content | 163 } // namespace content |
OLD | NEW |