Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / webui / url_data_manager.h
blob8a318b73dbaed2f85e8525bb2b60b6f38cef3f69
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_
6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/supports_user_data.h"
13 #include "content/common/content_export.h"
15 namespace content {
16 class BrowserContext;
17 class URLDataSource;
18 class URLDataSourceImpl;
19 class WebUIDataSource;
21 // To serve dynamic data off of chrome: URLs, implement the
22 // URLDataManager::DataSource interface and register your handler
23 // 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
25 // URLDataManagerBackend, see it for details.
26 class CONTENT_EXPORT URLDataManager : public base::SupportsUserData::Data {
27 public:
28 explicit URLDataManager(BrowserContext* browser_context);
29 ~URLDataManager() override;
31 // Adds a DataSource to the collection of data sources. This *must* be invoked
32 // on the UI thread.
34 // 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
36 // as there are no other references to it. |DataSource| uses the
37 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI
38 // thread. This is necessary as some |DataSource|s notably |FileIconSource|
39 // and |FaviconSource|, have members that will DCHECK if they are not
40 // destructed in the same thread as they are constructed (the UI thread).
41 void AddDataSource(URLDataSourceImpl* source);
43 // 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).
45 static void DeleteDataSources();
47 // Convenience wrapper function to add |source| to |browser_context|'s
48 // |URLDataManager|. Creates a URLDataSourceImpl to wrap the given
49 // source.
50 static void AddDataSource(BrowserContext* browser_context,
51 URLDataSource* source);
53 // Adds a WebUI data source to |browser_context|'s |URLDataManager|.
54 static void AddWebUIDataSource(BrowserContext* browser_context,
55 WebUIDataSource* source);
57 private:
58 friend class URLDataSourceImpl;
59 friend struct DeleteURLDataSource;
60 typedef std::vector<const URLDataSourceImpl*> URLDataSources;
62 // 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
64 // deletion on the UI thread. See note abouve DeleteDataSource for more info.
65 static void DeleteDataSource(const URLDataSourceImpl* data_source);
67 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource|
68 // was invoked).
69 static bool IsScheduledForDeletion(const URLDataSourceImpl* data_source);
71 BrowserContext* browser_context_;
73 // |data_sources_| that are no longer referenced and scheduled for deletion.
74 // Protected by g_delete_lock in the .cc file.
75 static URLDataSources* data_sources_;
77 DISALLOW_COPY_AND_ASSIGN(URLDataManager);
80 } // namespace content
82 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_