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