| 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/ui/webui/chrome_url_data_manager.h" | 5 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 16 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 18 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "grit/platform_locale_settings.h" | 20 #include "grit/platform_locale_settings.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 base::Lock ChromeURLDataManager::delete_lock_; | 28 base::Lock ChromeURLDataManager::delete_lock_; |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 ChromeURLDataManager::DataSources* ChromeURLDataManager::data_sources_ = NULL; | 31 ChromeURLDataManager::DataSources* ChromeURLDataManager::data_sources_ = NULL; |
| 31 | 32 |
| 32 // Invoked on the IO thread to do the actual adding of the DataSource. | 33 // Invoked on the IO thread to do the actual adding of the DataSource. |
| 33 static void AddDataSourceOnIOThread( | 34 static void AddDataSourceOnIOThread( |
| 34 scoped_refptr<net::URLRequestContextGetter> context_getter, | 35 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend, |
| 35 scoped_refptr<ChromeURLDataManager::DataSource> data_source) { | 36 scoped_refptr<ChromeURLDataManager::DataSource> data_source) { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 37 static_cast<ChromeURLRequestContext*>( | 38 backend.Run()->AddDataSource(data_source.get()); |
| 38 context_getter->GetURLRequestContext())-> | |
| 39 chrome_url_data_manager_backend()->AddDataSource(data_source.get()); | |
| 40 } | 39 } |
| 41 | 40 |
| 42 ChromeURLDataManager::ChromeURLDataManager(Profile* profile) | 41 ChromeURLDataManager::ChromeURLDataManager( |
| 43 : profile_(profile) { | 42 const base::Callback<ChromeURLDataManagerBackend*(void)>& backend) |
| 43 : backend_(backend) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 ChromeURLDataManager::~ChromeURLDataManager() { | 46 ChromeURLDataManager::~ChromeURLDataManager() { |
| 47 } | 47 } |
| 48 | 48 |
| 49 void ChromeURLDataManager::AddDataSource(DataSource* source) { | 49 void ChromeURLDataManager::AddDataSource(DataSource* source) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 BrowserThread::PostTask( | 51 BrowserThread::PostTask( |
| 52 BrowserThread::IO, FROM_HERE, | 52 BrowserThread::IO, FROM_HERE, |
| 53 NewRunnableFunction(AddDataSourceOnIOThread, | 53 NewRunnableFunction(AddDataSourceOnIOThread, |
| 54 make_scoped_refptr(profile_->GetRequestContext()), | 54 backend_, |
| 55 make_scoped_refptr(source))); | 55 make_scoped_refptr(source))); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 void ChromeURLDataManager::DeleteDataSources() { | 59 void ChromeURLDataManager::DeleteDataSources() { |
| 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 61 DataSources sources; | 61 DataSources sources; |
| 62 { | 62 { |
| 63 base::AutoLock lock(delete_lock_); | 63 base::AutoLock lock(delete_lock_); |
| 64 if (!data_sources_) | 64 if (!data_sources_) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 base::i18n::IsRTL() ? "rtl" : "ltr"); | 168 base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void ChromeURLDataManager::DataSource::SendResponseOnIOThread( | 171 void ChromeURLDataManager::DataSource::SendResponseOnIOThread( |
| 172 int request_id, | 172 int request_id, |
| 173 scoped_refptr<RefCountedMemory> bytes) { | 173 scoped_refptr<RefCountedMemory> bytes) { |
| 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 175 if (backend_) | 175 if (backend_) |
| 176 backend_->DataAvailable(request_id, bytes); | 176 backend_->DataAvailable(request_id, bytes); |
| 177 } | 177 } |
| OLD | NEW |