OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/message_loop_helpers.h" | 14 #include "base/message_loop_helpers.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "chrome/browser/profiles/profile_keyed_service.h" | |
16 | 17 |
17 class ChromeURLDataManagerBackend; | 18 class ChromeURLDataManagerBackend; |
18 class MessageLoop; | 19 class MessageLoop; |
20 class Profile; | |
19 class RefCountedMemory; | 21 class RefCountedMemory; |
20 | 22 |
21 namespace base { | 23 namespace base { |
22 class DictionaryValue; | 24 class DictionaryValue; |
23 } | 25 } |
24 | 26 |
25 // To serve dynamic data off of chrome: URLs, implement the | 27 // To serve dynamic data off of chrome: URLs, implement the |
26 // ChromeURLDataManager::DataSource interface and register your handler | 28 // ChromeURLDataManager::DataSource interface and register your handler |
27 // with AddDataSource. DataSources must be added on the UI thread (they are also | 29 // with AddDataSource. DataSources must be added on the UI thread (they are also |
28 // deleted on the UI thread). Internally the DataSources are maintained by | 30 // deleted on the UI thread). Internally the DataSources are maintained by |
29 // ChromeURLDataManagerBackend, see it for details. | 31 // ChromeURLDataManagerBackend, see it for details. |
30 class ChromeURLDataManager { | 32 class ChromeURLDataManager : public ProfileKeyedService { |
31 public: | 33 public: |
32 class DataSource; | 34 class DataSource; |
33 | 35 |
34 // Trait used to handle deleting a DataSource. Deletion happens on the UI | 36 // Trait used to handle deleting a DataSource. Deletion happens on the UI |
35 // thread. | 37 // thread. |
36 // | 38 // |
37 // Implementation note: the normal shutdown sequence is for the UI loop to | 39 // Implementation note: the normal shutdown sequence is for the UI loop to |
38 // stop pumping events then the IO loop and thread are stopped. When the | 40 // stop pumping events then the IO loop and thread are stopped. When the |
39 // DataSources are no longer referenced (which happens when IO thread stops) | 41 // DataSources are no longer referenced (which happens when IO thread stops) |
40 // they get added to the UI message loop for deletion. But because the UI loop | 42 // they get added to the UI message loop for deletion. But because the UI loop |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI | 155 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI |
154 // thread. This is necessary as some |DataSource|s notably |FileIconSource| | 156 // thread. This is necessary as some |DataSource|s notably |FileIconSource| |
155 // and |FaviconSource|, have members that will DCHECK if they are not | 157 // and |FaviconSource|, have members that will DCHECK if they are not |
156 // destructed in the same thread as they are constructed (the UI thread). | 158 // destructed in the same thread as they are constructed (the UI thread). |
157 void AddDataSource(DataSource* source); | 159 void AddDataSource(DataSource* source); |
158 | 160 |
159 // Deletes any data sources no longer referenced. This is normally invoked | 161 // Deletes any data sources no longer referenced. This is normally invoked |
160 // for you, but can be invoked to force deletion (such as during shutdown). | 162 // for you, but can be invoked to force deletion (such as during shutdown). |
161 static void DeleteDataSources(); | 163 static void DeleteDataSources(); |
162 | 164 |
165 // Convenience wrapper function to add |source| to |profile|'s | |
166 // |ChromeURLDataManager|. | |
167 static void AddDataSource(Profile *profile, DataSource* source); | |
Evan Stade
2012/04/24 21:22:14
star on the left
Kyle Horimoto
2012/04/24 22:17:49
Done.
| |
168 | |
163 private: | 169 private: |
164 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources; | 170 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources; |
165 | 171 |
166 // If invoked on the UI thread the DataSource is deleted immediatlye, | 172 // If invoked on the UI thread the DataSource is deleted immediatlye, |
167 // otherwise it is added to |data_sources_| and a task is scheduled to handle | 173 // otherwise it is added to |data_sources_| and a task is scheduled to handle |
168 // deletion on the UI thread. See note abouve DeleteDataSource for more info. | 174 // deletion on the UI thread. See note abouve DeleteDataSource for more info. |
169 static void DeleteDataSource(const DataSource* data_source); | 175 static void DeleteDataSource(const DataSource* data_source); |
170 | 176 |
171 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| | 177 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| |
172 // was invoked). | 178 // was invoked). |
173 static bool IsScheduledForDeletion(const DataSource* data_source); | 179 static bool IsScheduledForDeletion(const DataSource* data_source); |
174 | 180 |
175 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on | 181 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on |
176 // the IO thread. This is necessary because ChromeURLDataManager is created on | 182 // the IO thread. This is necessary because ChromeURLDataManager is created on |
177 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread. | 183 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread. |
178 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_; | 184 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_; |
179 | 185 |
180 // |data_sources_| that are no longer referenced and scheduled for deletion. | 186 // |data_sources_| that are no longer referenced and scheduled for deletion. |
181 // Protected by g_delete_lock in the .cc file. | 187 // Protected by g_delete_lock in the .cc file. |
182 static DataSources* data_sources_; | 188 static DataSources* data_sources_; |
183 | 189 |
184 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); | 190 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); |
185 }; | 191 }; |
186 | 192 |
187 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ | 193 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ |
OLD | NEW |