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

Side by Side Diff: chrome/browser/ui/webui/chrome_url_data_manager.h

Issue 10196004: Changed ChromeURLDataManager to a ProfileKeyedService and made a Factory for it. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Made ChromeURLDataManager's destructor virtual Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop_helpers.h" 14 #include "base/message_loop_helpers.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "chrome/browser/profiles/profile_keyed_service.h"
16 17
17 class ChromeURLDataManagerBackend; 18 class ChromeURLDataManagerBackend;
18 class MessageLoop; 19 class MessageLoop;
20 class Profile;
19 class RefCountedMemory; 21 class RefCountedMemory;
20 22
21 namespace base { 23 namespace base {
22 class DictionaryValue; 24 class DictionaryValue;
23 } 25 }
24 26
25 // To serve dynamic data off of chrome: URLs, implement the 27 // To serve dynamic data off of chrome: URLs, implement the
26 // ChromeURLDataManager::DataSource interface and register your handler 28 // ChromeURLDataManager::DataSource interface and register your handler
27 // 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
28 // deleted on the UI thread). Internally the DataSources are maintained by 30 // deleted on the UI thread). Internally the DataSources are maintained by
29 // ChromeURLDataManagerBackend, see it for details. 31 // ChromeURLDataManagerBackend, see it for details.
30 class ChromeURLDataManager { 32 class ChromeURLDataManager : public ProfileKeyedService {
31 public: 33 public:
32 class DataSource; 34 class DataSource;
33 35
34 // Trait used to handle deleting a DataSource. Deletion happens on the UI 36 // Trait used to handle deleting a DataSource. Deletion happens on the UI
35 // thread. 37 // thread.
36 // 38 //
37 // Implementation note: the normal shutdown sequence is for the UI loop to 39 // Implementation note: the normal shutdown sequence is for the UI loop to
38 // stop pumping events then the IO loop and thread are stopped. When the 40 // stop pumping events then the IO loop and thread are stopped. When the
39 // DataSources are no longer referenced (which happens when IO thread stops) 41 // DataSources are no longer referenced (which happens when IO thread stops)
40 // they get added to the UI message loop for deletion. But because the UI loop 42 // they get added to the UI message loop for deletion. But because the UI loop
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend 137 // A DataSource can be removed in two ways: the ChromeURLDataManagerBackend
136 // is deleted, or another DataSource is registered with the same 138 // is deleted, or another DataSource is registered with the same
137 // name. backend_ should only be accessed on the IO thread. 139 // name. backend_ should only be accessed on the IO thread.
138 // This reference can't be via a scoped_refptr else there would be a cycle 140 // This reference can't be via a scoped_refptr else there would be a cycle
139 // between the backend and data source. 141 // between the backend and data source.
140 ChromeURLDataManagerBackend* backend_; 142 ChromeURLDataManagerBackend* backend_;
141 }; 143 };
142 144
143 explicit ChromeURLDataManager( 145 explicit ChromeURLDataManager(
144 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend); 146 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend);
145 ~ChromeURLDataManager(); 147 virtual ~ChromeURLDataManager();
146 148
147 // Adds a DataSource to the collection of data sources. This *must* be invoked 149 // Adds a DataSource to the collection of data sources. This *must* be invoked
148 // on the UI thread. 150 // on the UI thread.
149 // 151 //
150 // If |AddDataSource| is called more than once for a particular name it will 152 // If |AddDataSource| is called more than once for a particular name it will
151 // release the old |DataSource|, most likely resulting in it getting deleted 153 // release the old |DataSource|, most likely resulting in it getting deleted
152 // as there are no other references to it. |DataSource| uses the 154 // as there are no other references to it. |DataSource| uses the
153 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI 155 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI
154 // thread. This is necessary as some |DataSource|s notably |FileIconSource| 156 // thread. This is necessary as some |DataSource|s notably |FileIconSource|
155 // and |FaviconSource|, have members that will DCHECK if they are not 157 // and |FaviconSource|, have members that will DCHECK if they are not
156 // destructed in the same thread as they are constructed (the UI thread). 158 // destructed in the same thread as they are constructed (the UI thread).
157 void AddDataSource(DataSource* source); 159 void AddDataSource(DataSource* source);
158 160
159 // Deletes any data sources no longer referenced. This is normally invoked 161 // Deletes any data sources no longer referenced. This is normally invoked
160 // for you, but can be invoked to force deletion (such as during shutdown). 162 // for you, but can be invoked to force deletion (such as during shutdown).
161 static void DeleteDataSources(); 163 static void DeleteDataSources();
162 164
165 // Convenience wrapper function to add |source| to |profile|'s
166 // |ChromeURLDataManager|.
167 static void AddDataSource(Profile* profile, DataSource* source);
168
163 private: 169 private:
164 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources; 170 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources;
165 171
166 // If invoked on the UI thread the DataSource is deleted immediatlye, 172 // If invoked on the UI thread the DataSource is deleted immediatlye,
167 // otherwise it is added to |data_sources_| and a task is scheduled to handle 173 // otherwise it is added to |data_sources_| and a task is scheduled to handle
168 // deletion on the UI thread. See note abouve DeleteDataSource for more info. 174 // deletion on the UI thread. See note abouve DeleteDataSource for more info.
169 static void DeleteDataSource(const DataSource* data_source); 175 static void DeleteDataSource(const DataSource* data_source);
170 176
171 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| 177 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource|
172 // was invoked). 178 // was invoked).
173 static bool IsScheduledForDeletion(const DataSource* data_source); 179 static bool IsScheduledForDeletion(const DataSource* data_source);
174 180
175 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on 181 // A callback that returns the ChromeURLDataManagerBackend. Only accessible on
176 // the IO thread. This is necessary because ChromeURLDataManager is created on 182 // the IO thread. This is necessary because ChromeURLDataManager is created on
177 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread. 183 // the UI thread, but ChromeURLDataManagerBackend lives on the IO thread.
178 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_; 184 const base::Callback<ChromeURLDataManagerBackend*(void)> backend_;
179 185
180 // |data_sources_| that are no longer referenced and scheduled for deletion. 186 // |data_sources_| that are no longer referenced and scheduled for deletion.
181 // Protected by g_delete_lock in the .cc file. 187 // Protected by g_delete_lock in the .cc file.
182 static DataSources* data_sources_; 188 static DataSources* data_sources_;
183 189
184 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); 190 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager);
185 }; 191 };
186 192
187 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_ 193 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/certificate_viewer_ui.cc ('k') | chrome/browser/ui/webui/chrome_url_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698