Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 5 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/ref_counted_memory.h" | 12 #include "base/ref_counted_memory.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/stl_util-inl.h" | |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 18 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 19 #endif | 20 #endif |
| 20 #include "chrome/browser/appcache/view_appcache_internals_job_factory.h" | 21 #include "chrome/browser/appcache/view_appcache_internals_job_factory.h" |
| 21 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
| 22 #include "chrome/browser/dom_ui/shared_resources_data_source.h" | 23 #include "chrome/browser/dom_ui/shared_resources_data_source.h" |
| 23 #include "chrome/browser/net/chrome_url_request_context.h" | 24 #include "chrome/browser/net/chrome_url_request_context.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 if (p.IsAbsolute()) | 170 if (p.IsAbsolute()) |
| 170 return false; | 171 return false; |
| 171 | 172 |
| 172 *file_path = i->second.AppendASCII(relative_path); | 173 *file_path = i->second.AppendASCII(relative_path); |
| 173 | 174 |
| 174 return true; | 175 return true; |
| 175 } | 176 } |
| 176 | 177 |
| 177 ChromeURLDataManager::ChromeURLDataManager() : next_request_id_(0) { } | 178 ChromeURLDataManager::ChromeURLDataManager() : next_request_id_(0) { } |
| 178 | 179 |
| 179 ChromeURLDataManager::~ChromeURLDataManager() { } | 180 ChromeURLDataManager::~ChromeURLDataManager() { |
| 181 // This is used as a Singleton, so it is only called at exit cleanup time. | |
| 182 // This means it is called on the main (UI) thread. | |
| 183 // | |
| 184 // It will break if it is called at shutdown time on a different thread, as | |
| 185 // it will attempt to call the destructors for its |data_source_|s on the | |
| 186 // UI thread, but the UI thread's message loop will be not be running | |
| 187 // -- so the destructor calls will be dropped and we will leak the objects. | |
| 188 } | |
| 180 | 189 |
| 181 // static | 190 // static |
| 182 ChromeURLDataManager* ChromeURLDataManager::GetInstance() { | 191 ChromeURLDataManager* ChromeURLDataManager::GetInstance() { |
| 183 return Singleton<ChromeURLDataManager>::get(); | 192 return Singleton<ChromeURLDataManager>::get(); |
| 184 } | 193 } |
| 185 | 194 |
| 186 void ChromeURLDataManager::AddDataSource(scoped_refptr<DataSource> source) { | 195 void ChromeURLDataManager::AddDataSource(scoped_refptr<DataSource> source) { |
| 196 // Some |DataSource|-derived classes, notably |FileIconSource| and | |
| 197 // |DOMUIFavIconSource|, have members that will DCHECK if they are not | |
| 198 // destructed in the same thread as they are constructed (the UI thread). | |
| 199 // | |
| 200 // If |AddDataSource| is called more than once, it will destruct the object | |
| 201 // that it had before, as it is the only thing still holding a reference to | |
| 202 // that object. In order for the destructor to be called in the UI thread, | |
| 203 // |DataSource| now uses the |DeleteOnUIThread| trait. | |
|
eroman
2011/01/24 18:26:39
I don't like this comment, in particular how it sa
ahendrickson
2011/01/24 19:58:20
Done.
| |
| 204 // | |
| 187 // TODO(jackson): A new data source with same name should not clobber the | 205 // TODO(jackson): A new data source with same name should not clobber the |
| 188 // existing one. | 206 // existing one. |
| 189 data_sources_[source->source_name()] = source; | 207 data_sources_[source->source_name()] = source; |
| 190 } | 208 } |
| 191 | 209 |
| 192 void ChromeURLDataManager::AddFileSource(const std::string& source_name, | 210 void ChromeURLDataManager::AddFileSource(const std::string& source_name, |
| 193 const FilePath& file_path) { | 211 const FilePath& file_path) { |
| 194 DCHECK(file_sources_.count(source_name) == 0); | 212 DCHECK(file_sources_.count(source_name) == 0); |
| 195 file_sources_[source_name] = file_path; | 213 file_sources_[source_name] = file_path; |
| 196 } | 214 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 net::ERR_INVALID_URL)); | 450 net::ERR_INVALID_URL)); |
| 433 } | 451 } |
| 434 } | 452 } |
| 435 | 453 |
| 436 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, | 454 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, |
| 437 const FilePath& path) | 455 const FilePath& path) |
| 438 : net::URLRequestFileJob(request, path) { | 456 : net::URLRequestFileJob(request, path) { |
| 439 } | 457 } |
| 440 | 458 |
| 441 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 459 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } |
| OLD | NEW |