hunspell: Cleanup to fix the header include guards under google/ directory.
[chromium-blink-merge.git] / ios / web / webui / url_data_manager_ios.h
blobc23eda524aecb894ccdb7b7258c03c6cd89e26b8
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
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_WEBUI_URL_DATA_MANAGER_IOS_H_
6 #define IOS_WEB_WEBUI_URL_DATA_MANAGER_IOS_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/supports_user_data.h"
14 namespace web {
15 class BrowserState;
16 class URLDataSourceIOS;
17 class URLDataSourceIOSImpl;
18 class WebUIIOSDataSource;
20 // To serve dynamic data off of chrome: URLs, implement the
21 // URLDataManagerIOS::DataSource interface and register your handler
22 // with AddDataSource. DataSources must be added on the UI thread (they are also
23 // deleted on the UI thread). Internally the DataSources are maintained by
24 // URLDataManagerIOSBackend, see it for details.
25 class URLDataManagerIOS : public base::SupportsUserData::Data {
26 public:
27 explicit URLDataManagerIOS(BrowserState* browser_state);
28 ~URLDataManagerIOS() override;
30 // Adds a DataSource to the collection of data sources. This *must* be invoked
31 // on the UI thread.
33 // If |AddDataSource| is called more than once for a particular name it will
34 // release the old |DataSource|, most likely resulting in it getting deleted
35 // as there are no other references to it. |DataSource| uses the
36 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI
37 // thread. This is necessary as some |DataSource|s notably |FileIconSource|
38 // and |FaviconSource|, have members that will DCHECK if they are not
39 // destructed in the same thread as they are constructed (the UI thread).
40 void AddDataSource(URLDataSourceIOSImpl* source);
42 // Deletes any data sources no longer referenced. This is normally invoked
43 // for you, but can be invoked to force deletion (such as during shutdown).
44 static void DeleteDataSources();
46 // Convenience wrapper function to add |source| to |browser_context|'s
47 // |URLDataManagerIOS|. Creates a URLDataSourceIOSImpl to wrap the given
48 // source.
49 static void AddDataSource(BrowserState* browser_context,
50 URLDataSourceIOS* source);
52 // Adds a WebUI data source to |browser_context|'s |URLDataManagerIOS|.
53 static void AddWebUIIOSDataSource(BrowserState* browser_state,
54 WebUIIOSDataSource* source);
56 private:
57 friend class URLDataSourceIOSImpl;
58 friend struct DeleteURLDataSourceIOS;
59 typedef std::vector<const URLDataSourceIOSImpl*> URLDataSources;
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);
66 // If invoked on the UI thread the DataSource is deleted immediatlye,
67 // otherwise it is added to |data_sources_| and a task is scheduled to handle
68 // deletion on the UI thread. See note abouve DeleteDataSource for more info.
69 static void DeleteDataSource(const URLDataSourceIOSImpl* data_source);
71 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource|
72 // was invoked).
73 static bool IsScheduledForDeletion(const URLDataSourceIOSImpl* data_source);
75 BrowserState* browser_state_;
77 // |data_sources_| that are no longer referenced and scheduled for deletion.
78 // Protected by g_delete_lock in the .cc file.
79 static URLDataSources* data_sources_;
81 DISALLOW_COPY_AND_ASSIGN(URLDataManagerIOS);
84 } // namespace web
86 #endif // IOS_WEB_WEBUI_URL_DATA_MANAGER_IOS_H_