Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: content/browser/webui/url_data_manager.h

Issue 12049052: Move core url data manager classes to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ 5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ 6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/sequenced_task_runner_helpers.h" 13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/supports_user_data.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h" 16 #include "content/common/content_export.h"
16 17
17 class ChromeURLDataManagerBackend; 18 class ChromeURLDataManagerBackend;
18 class MessageLoop; 19 class MessageLoop;
19 class Profile;
20 20
21 namespace base { 21 namespace base {
22 class RefCountedMemory; 22 class RefCountedMemory;
23 } 23 }
24 24
25 namespace content { 25 namespace content {
26 class BrowserContext;
26 class URLDataSource; 27 class URLDataSource;
27 class WebUIDataSource; 28 class WebUIDataSource;
28 } 29 }
29 30
30 class URLDataSourceImpl; 31 class URLDataSourceImpl;
31 32
32 // To serve dynamic data off of chrome: URLs, implement the 33 // To serve dynamic data off of chrome: URLs, implement the
33 // ChromeURLDataManager::DataSource interface and register your handler 34 // ChromeURLDataManager::DataSource interface and register your handler
34 // with AddDataSource. DataSources must be added on the UI thread (they are also 35 // with AddDataSource. DataSources must be added on the UI thread (they are also
35 // deleted on the UI thread). Internally the DataSources are maintained by 36 // deleted on the UI thread). Internally the DataSources are maintained by
36 // ChromeURLDataManagerBackend, see it for details. 37 // ChromeURLDataManagerBackend, see it for details.
37 class ChromeURLDataManager : public ProfileKeyedService { 38 class CONTENT_EXPORT ChromeURLDataManager
39 : public base::SupportsUserData::Data {
38 public: 40 public:
39 explicit ChromeURLDataManager( 41 explicit ChromeURLDataManager(content::BrowserContext* browser_context);
40 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend);
41 virtual ~ChromeURLDataManager(); 42 virtual ~ChromeURLDataManager();
42 43
43 // Adds a DataSource to the collection of data sources. This *must* be invoked 44 // Adds a DataSource to the collection of data sources. This *must* be invoked
44 // on the UI thread. 45 // on the UI thread.
45 // 46 //
46 // If |AddDataSource| is called more than once for a particular name it will 47 // If |AddDataSource| is called more than once for a particular name it will
47 // release the old |DataSource|, most likely resulting in it getting deleted 48 // release the old |DataSource|, most likely resulting in it getting deleted
48 // as there are no other references to it. |DataSource| uses the 49 // as there are no other references to it. |DataSource| uses the
49 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI 50 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI
50 // thread. This is necessary as some |DataSource|s notably |FileIconSource| 51 // thread. This is necessary as some |DataSource|s notably |FileIconSource|
51 // and |FaviconSource|, have members that will DCHECK if they are not 52 // and |FaviconSource|, have members that will DCHECK if they are not
52 // destructed in the same thread as they are constructed (the UI thread). 53 // destructed in the same thread as they are constructed (the UI thread).
53 void AddDataSource(URLDataSourceImpl* source); 54 void AddDataSource(URLDataSourceImpl* source);
54 55
55 // Deletes any data sources no longer referenced. This is normally invoked 56 // Deletes any data sources no longer referenced. This is normally invoked
56 // for you, but can be invoked to force deletion (such as during shutdown). 57 // for you, but can be invoked to force deletion (such as during shutdown).
57 static void DeleteDataSources(); 58 static void DeleteDataSources();
58 59
59 // Convenience wrapper function to add |source| to |profile|'s 60 // Convenience wrapper function to add |source| to |browser_context|'s
60 // |ChromeURLDataManager|. Creates a URLDataSourceImpl to wrap the given 61 // |ChromeURLDataManager|. Creates a URLDataSourceImpl to wrap the given
61 // source. 62 // source.
62 static void AddDataSource(Profile* profile, 63 static void AddDataSource(
63 content::URLDataSource* source); 64 content::BrowserContext* browser_context,
65 content::URLDataSource* source);
64 66
65 // Adds a WebUI data source to |profile|'s |ChromeURLDataManager|. 67 // Adds a WebUI data source to |browser_context|'s |ChromeURLDataManager|.
66 static void AddWebUIDataSource(Profile* profile, 68 static void AddWebUIDataSource(
67 content::WebUIDataSource* source); 69 content::BrowserContext* browser_context,
70 content::WebUIDataSource* source);
68 71
69 private: 72 private:
70 friend class URLDataSourceImpl; 73 friend class URLDataSourceImpl;
71 friend struct DeleteURLDataSource; 74 friend struct DeleteURLDataSource;
72 typedef std::vector<const URLDataSourceImpl*> URLDataSources; 75 typedef std::vector<const URLDataSourceImpl*> URLDataSources;
73 76
74 // If invoked on the UI thread the DataSource is deleted immediatlye, 77 // If invoked on the UI thread the DataSource is deleted immediatlye,
75 // 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
76 // 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.
77 static void DeleteDataSource(const URLDataSourceImpl* data_source); 80 static void DeleteDataSource(const URLDataSourceImpl* data_source);
78 81
79 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| 82 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource|
80 // was invoked). 83 // was invoked).
81 static bool IsScheduledForDeletion(const URLDataSourceImpl* data_source); 84 static bool IsScheduledForDeletion(const URLDataSourceImpl* data_source);
82 85
83 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on 86 content::BrowserContext* browser_context_;
84 // the IO thread. This is necessary because ChromeURLDataManager is created on
85 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread.
86 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_;
87 87
88 // |data_sources_| that are no longer referenced and scheduled for deletion. 88 // |data_sources_| that are no longer referenced and scheduled for deletion.
89 // Protected by g_delete_lock in the .cc file. 89 // Protected by g_delete_lock in the .cc file.
90 static URLDataSources* data_sources_; 90 static URLDataSources* data_sources_;
91 91
92 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); 92 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager);
93 }; 93 };
94 94
95 // Trait used to handle deleting a URLDataSource. Deletion happens on the UI 95 // Trait used to handle deleting a URLDataSource. Deletion happens on the UI
96 // thread. 96 // thread.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend 157 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend
158 // is deleted, or another DataSource is registered with the same 158 // is deleted, or another DataSource is registered with the same
159 // name. backend_ should only be accessed on the IO thread. 159 // name. backend_ should only be accessed on the IO thread.
160 // This reference can't be via a scoped_refptr else there would be a cycle 160 // This reference can't be via a scoped_refptr else there would be a cycle
161 // between the backend and data source. 161 // between the backend and data source.
162 ChromeURLDataManagerBackend* backend_; 162 ChromeURLDataManagerBackend* backend_;
163 163
164 scoped_ptr<content::URLDataSource> source_; 164 scoped_ptr<content::URLDataSource> source_;
165 }; 165 };
166 166
167 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ 167 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/webui/shared_resources_data_source.cc ('k') | content/browser/webui/url_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698