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

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

Issue 6546078: Makes a handful of DataSources not replace the existing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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) 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_WEBUI_CHROME_URL_DATA_MANAGER_H_ 5 #ifndef CHROME_BROWSER_WEBUI_CHROME_URL_DATA_MANAGER_H_
6 #define CHROME_BROWSER_WEBUI_CHROME_URL_DATA_MANAGER_H_ 6 #define CHROME_BROWSER_WEBUI_CHROME_URL_DATA_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <set>
11 #include <string> 9 #include <string>
12 10
13 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
14 #include "base/task.h" 12 #include "base/task.h"
15 #include "chrome/browser/browser_thread.h" 13 #include "chrome/browser/browser_thread.h"
16 14
17 class ChromeURLDataManagerBackend; 15 class ChromeURLDataManagerBackend;
18 class DictionaryValue; 16 class DictionaryValue;
19 class FilePath; 17 class FilePath;
20 class MessageLoop; 18 class MessageLoop;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // message_loop_, which generally results in processing on the UI thread. 86 // message_loop_, which generally results in processing on the UI thread.
89 // It may be beneficial to return NULL for requests that are safe to handle 87 // It may be beneficial to return NULL for requests that are safe to handle
90 // directly on the IO thread. This can improve performance by satisfying 88 // directly on the IO thread. This can improve performance by satisfying
91 // such requests more rapidly when there is a large amount of UI thread 89 // such requests more rapidly when there is a large amount of UI thread
92 // contention. 90 // contention.
93 virtual MessageLoop* MessageLoopForRequestPath(const std::string& path) 91 virtual MessageLoop* MessageLoopForRequestPath(const std::string& path)
94 const; 92 const;
95 93
96 const std::string& source_name() const { return source_name_; } 94 const std::string& source_name() const { return source_name_; }
97 95
96 // Returns true if this DataSource should replace an existing DataSource
97 // with the same name that has already been registered. The default is
98 // true.
99 //
100 // WARNING: this is invoked on the IO thread.
101 //
102 // TODO: nuke this and convert all callers to not replace.
103 virtual bool ShouldReplaceExistingSource() const;
104
98 static void SetFontAndTextDirection(DictionaryValue* localized_strings); 105 static void SetFontAndTextDirection(DictionaryValue* localized_strings);
99 106
100 protected: 107 protected:
101 virtual ~DataSource(); 108 virtual ~DataSource();
102 109
103 private: 110 private:
104 friend class ChromeURLDataManagerBackend; 111 friend class ChromeURLDataManagerBackend;
105 friend class ChromeURLDataManager; 112 friend class ChromeURLDataManager;
106 friend class DeleteTask<DataSource>; 113 friend class DeleteTask<DataSource>;
107 114
(...skipping 29 matching lines...) Expand all
137 // 144 //
138 // If |AddDataSource| is called more than once for a particular name it will 145 // If |AddDataSource| is called more than once for a particular name it will
139 // release the old |DataSource|, most likely resulting in it getting deleted 146 // release the old |DataSource|, most likely resulting in it getting deleted
140 // as there are no other references to it. |DataSource| uses the 147 // as there are no other references to it. |DataSource| uses the
141 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI 148 // |DeleteOnUIThread| trait to insure that the destructor is called on the UI
142 // thread. This is necessary as some |DataSource|s notably |FileIconSource| 149 // thread. This is necessary as some |DataSource|s notably |FileIconSource|
143 // and |WebUIFavIconSource|, have members that will DCHECK if they are not 150 // and |WebUIFavIconSource|, have members that will DCHECK if they are not
144 // destructed in the same thread as they are constructed (the UI thread). 151 // destructed in the same thread as they are constructed (the UI thread).
145 void AddDataSource(DataSource* source); 152 void AddDataSource(DataSource* source);
146 153
147 // Returns true if a DataSource has been added with the given name.
148 bool IsRegistered(const std::string& name);
149
150 // Deletes any data sources no longer referenced. This is normally invoked 154 // Deletes any data sources no longer referenced. This is normally invoked
151 // for you, but can be invoked to force deletion (such as during shutdown). 155 // for you, but can be invoked to force deletion (such as during shutdown).
152 static void DeleteDataSources(); 156 static void DeleteDataSources();
153 157
154 private: 158 private:
155 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources; 159 typedef std::vector<const ChromeURLDataManager::DataSource*> DataSources;
156 160
157 // If invoked on the UI thread the DataSource is deleted immediatlye, 161 // If invoked on the UI thread the DataSource is deleted immediatlye,
158 // otherwise it is added to |data_sources_| and a task is scheduled to handle 162 // otherwise it is added to |data_sources_| and a task is scheduled to handle
159 // deletion on the UI thread. See note abouve DeleteDataSource for more info. 163 // deletion on the UI thread. See note abouve DeleteDataSource for more info.
160 static void DeleteDataSource(const DataSource* data_source); 164 static void DeleteDataSource(const DataSource* data_source);
161 165
162 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource| 166 // Returns true if |data_source| is scheduled for deletion (|DeleteDataSource|
163 // was invoked). 167 // was invoked).
164 static bool IsScheduledForDeletion(const DataSource* data_source); 168 static bool IsScheduledForDeletion(const DataSource* data_source);
165 169
166 Profile* profile_; 170 Profile* profile_;
167 171
168 // Names of the DataSources that have been registered.
169 // By caching this rather than accessing ChromeURLDataManagerBackend we avoid
170 // a delay between when AddDataSource is invoked and when the IO thread
171 // processes it.
172 std::set<std::string> registered_source_names_;
173
174 // Lock used when accessing |data_sources_|. 172 // Lock used when accessing |data_sources_|.
175 static base::Lock delete_lock_; 173 static base::Lock delete_lock_;
176 174
177 // |data_sources_| that are no longer referenced and scheduled for deletion. 175 // |data_sources_| that are no longer referenced and scheduled for deletion.
178 static DataSources* data_sources_; 176 static DataSources* data_sources_;
179 177
180 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager); 178 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManager);
181 }; 179 };
182 180
183 #endif // CHROME_BROWSER_WEBUI_CHROME_URL_DATA_MANAGER_H_ 181 #endif // CHROME_BROWSER_WEBUI_CHROME_URL_DATA_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698