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 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ |
6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ | 6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 | 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 } |
| 20 |
16 namespace content { | 21 namespace content { |
17 class BrowserContext; | 22 class BrowserContext; |
18 class URLDataSource; | 23 class URLDataSource; |
19 class URLDataSourceImpl; | 24 class URLDataSourceImpl; |
20 class WebUIDataSource; | 25 class WebUIDataSource; |
21 | 26 |
22 // To serve dynamic data off of chrome: URLs, implement the | 27 // To serve dynamic data off of chrome: URLs, implement the |
23 // URLDataManager::DataSource interface and register your handler | 28 // URLDataManager::DataSource interface and register your handler |
24 // 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 |
25 // deleted on the UI thread). Internally the DataSources are maintained by | 30 // deleted on the UI thread). Internally the DataSources are maintained by |
26 // URLDataManagerBackend, see it for details. | 31 // URLDataManagerBackend, see it for details. |
27 class CONTENT_EXPORT URLDataManager : public base::SupportsUserData::Data { | 32 class CONTENT_EXPORT URLDataManager : public base::SupportsUserData::Data { |
28 public: | 33 public: |
29 explicit URLDataManager(BrowserContext* browser_context); | 34 explicit URLDataManager(BrowserContext* browser_context); |
30 ~URLDataManager() override; | 35 ~URLDataManager() override; |
31 | 36 |
32 // Adds a DataSource to the collection of data sources. This *must* be invoked | 37 // Adds a DataSource to the collection of data sources. This *must* be invoked |
33 // on the UI thread. | 38 // on the UI thread. |
34 // | 39 // |
35 // If |AddDataSource| is called more than once for a particular name it will | 40 // If |AddDataSource| is called more than once for a particular name it will |
36 // release the old |DataSource|, most likely resulting in it getting deleted | 41 // release the old |DataSource|, most likely resulting in it getting deleted |
37 // as there are no other references to it. |DataSource| uses the | 42 // as there are no other references to it. |DataSource| uses the |
38 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI | 43 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI |
39 // thread. This is necessary as some |DataSource|s notably |FileIconSource| | 44 // thread. This is necessary as some |DataSource|s notably |FileIconSource| |
40 // and |FaviconSource|, have members that will DCHECK if they are not | 45 // and |FaviconSource|, have members that will DCHECK if they are not |
41 // destructed in the same thread as they are constructed (the UI thread). | 46 // destructed in the same thread as they are constructed (the UI thread). |
42 void AddDataSource(URLDataSourceImpl* source); | 47 void AddDataSource(URLDataSourceImpl* source); |
43 | 48 |
| 49 void UpdateWebUIDataSource(const std::string& source_name, |
| 50 std::unique_ptr<base::DictionaryValue> update); |
| 51 |
44 // Deletes any data sources no longer referenced. This is normally invoked | 52 // Deletes any data sources no longer referenced. This is normally invoked |
45 // for you, but can be invoked to force deletion (such as during shutdown). | 53 // for you, but can be invoked to force deletion (such as during shutdown). |
46 static void DeleteDataSources(); | 54 static void DeleteDataSources(); |
47 | 55 |
48 // Convenience wrapper function to add |source| to |browser_context|'s | 56 // Convenience wrapper function to add |source| to |browser_context|'s |
49 // |URLDataManager|. Creates a URLDataSourceImpl to wrap the given | 57 // |URLDataManager|. Creates a URLDataSourceImpl to wrap the given |
50 // source. | 58 // source. |
51 static void AddDataSource(BrowserContext* browser_context, | 59 static void AddDataSource(BrowserContext* browser_context, |
52 URLDataSource* source); | 60 URLDataSource* source); |
53 | 61 |
54 // Adds a WebUI data source to |browser_context|'s |URLDataManager|. | 62 // Adds a WebUI data source to |browser_context|'s |URLDataManager|. |
55 static void AddWebUIDataSource(BrowserContext* browser_context, | 63 static void AddWebUIDataSource(BrowserContext* browser_context, |
56 WebUIDataSource* source); | 64 WebUIDataSource* source); |
57 | 65 |
| 66 // Updates an existing WebUI data source. |
| 67 static void UpdateWebUIDataSource( |
| 68 BrowserContext* browser_context, |
| 69 const std::string& source_name, |
| 70 std::unique_ptr<base::DictionaryValue> update); |
| 71 |
58 private: | 72 private: |
59 friend class URLDataSourceImpl; | 73 friend class URLDataSourceImpl; |
60 friend struct DeleteURLDataSource; | 74 friend struct DeleteURLDataSource; |
61 typedef std::vector<const URLDataSourceImpl*> URLDataSources; | 75 typedef std::vector<const URLDataSourceImpl*> URLDataSources; |
62 | 76 |
63 // If invoked on the UI thread the DataSource is deleted immediatlye, | 77 // If invoked on the UI thread the DataSource is deleted immediatlye, |
64 // otherwise it is added to |data_sources_| and a task is scheduled to handle | 78 // otherwise it is added to |data_sources_| and a task is scheduled to handle |
65 // deletion on the UI thread. See note abouve DeleteDataSource for more info. | 79 // deletion on the UI thread. See note abouve DeleteDataSource for more info. |
66 static void DeleteDataSource(const URLDataSourceImpl* data_source); | 80 static void DeleteDataSource(const URLDataSourceImpl* data_source); |
67 | 81 |
68 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| | 82 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| |
69 // was invoked). | 83 // was invoked). |
70 static bool IsScheduledForDeletion(const URLDataSourceImpl* data_source); | 84 static bool IsScheduledForDeletion(const URLDataSourceImpl* data_source); |
71 | 85 |
72 BrowserContext* browser_context_; | 86 BrowserContext* browser_context_; |
73 | 87 |
74 // |data_sources_| that are no longer referenced and scheduled for deletion. | 88 // |data_sources_| that are no longer referenced and scheduled for deletion. |
75 // Protected by g_delete_lock in the .cc file. | 89 // Protected by g_delete_lock in the .cc file. |
76 static URLDataSources* data_sources_; | 90 static URLDataSources* data_sources_; |
77 | 91 |
78 DISALLOW_COPY_AND_ASSIGN(URLDataManager); | 92 DISALLOW_COPY_AND_ASSIGN(URLDataManager); |
79 }; | 93 }; |
80 | 94 |
81 } // namespace content | 95 } // namespace content |
82 | 96 |
83 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ | 97 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_ |
OLD | NEW |