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

Unified Diff: chrome/browser/ui/webui/chrome_url_data_manager.cc

Issue 11881055: Simplify WebUI data sources. Currently WebUI data sources implement a URLDataSourceDelegate interfa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix issue in about_ui exposed by cros tests 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chrome_url_data_manager.cc
===================================================================
--- chrome/browser/ui/webui/chrome_url_data_manager.cc (revision 176942)
+++ chrome/browser/ui/webui/chrome_url_data_manager.cc (working copy)
@@ -7,32 +7,19 @@
#include <vector>
#include "base/bind.h"
-#include "base/i18n/rtl.h"
#include "base/lazy_instance.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/synchronization/lock.h"
-#include "base/values.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/url_data_source_delegate.h"
-#include "grit/platform_locale_settings.h"
-#include "ui/base/l10n/l10n_util.h"
+#include "content/public/browser/url_data_source.h"
-#if defined (TOOLKIT_GTK)
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/font.h"
-#endif
-
-#if defined(OS_WIN)
-#include "base/win/windows_version.h"
-#endif
-
using content::BrowserThread;
static base::LazyInstance<base::Lock>::Leaky
@@ -45,7 +32,7 @@
// Invoked on the IO thread to do the actual adding of the DataSource.
static void AddDataSourceOnIOThread(
const base::Callback<ChromeURLDataManagerBackend*(void)>& backend,
- scoped_refptr<URLDataSource> data_source) {
+ scoped_refptr<URLDataSourceImpl> data_source) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
backend.Run()->AddDataSource(data_source.get());
}
@@ -58,7 +45,7 @@
ChromeURLDataManager::~ChromeURLDataManager() {
}
-void ChromeURLDataManager::AddDataSource(URLDataSource* source) {
+void ChromeURLDataManager::AddDataSource(URLDataSourceImpl* source) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -81,7 +68,8 @@
}
// static
-void ChromeURLDataManager::DeleteDataSource(const URLDataSource* data_source) {
+void ChromeURLDataManager::DeleteDataSource(
+ const URLDataSourceImpl* data_source) {
// Invoked when a DataSource is no longer referenced and needs to be deleted.
if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
// We're on the UI thread, delete right away.
@@ -110,18 +98,20 @@
// static
void ChromeURLDataManager::AddDataSource(
Profile* profile,
- content::URLDataSourceDelegate* delegate) {
- if (!delegate->url_data_source_) {
- delegate->url_data_source_ = new URLDataSource(
- delegate->GetSource(), delegate);
- }
+ content::URLDataSource* source) {
ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource(
- delegate->url_data_source_);
+ new URLDataSourceImpl(source->GetSource(), source));
}
// static
+void ChromeURLDataManager::AddDataSourceImpl(Profile* profile,
+ URLDataSourceImpl* source) {
+ ChromeURLDataManagerFactory::GetForProfile(profile)->AddDataSource(source);
+}
+
+// static
bool ChromeURLDataManager::IsScheduledForDeletion(
- const URLDataSource* data_source) {
+ const URLDataSourceImpl* data_source) {
base::AutoLock lock(g_delete_lock.Get());
if (!data_sources_)
return false;
@@ -129,17 +119,17 @@
data_sources_->end();
}
-URLDataSource::URLDataSource(const std::string& source_name,
- content::URLDataSourceDelegate* delegate)
+URLDataSourceImpl::URLDataSourceImpl(const std::string& source_name,
+ content::URLDataSource* source)
: source_name_(source_name),
backend_(NULL),
- delegate_(delegate) {
+ source_(source) {
}
-URLDataSource::~URLDataSource() {
+URLDataSourceImpl::~URLDataSourceImpl() {
}
-void URLDataSource::SendResponse(
+void URLDataSourceImpl::SendResponse(
int request_id,
base::RefCountedMemory* bytes) {
// Take a ref-pointer on entry so byte->Release() will always get called.
@@ -160,40 +150,11 @@
}
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
- base::Bind(&URLDataSource::SendResponseOnIOThread, this, request_id,
+ base::Bind(&URLDataSourceImpl::SendResponseOnIOThread, this, request_id,
bytes_ptr));
}
-// static
-void URLDataSource::SetFontAndTextDirection(
- DictionaryValue* localized_strings) {
- int web_font_family_id = IDS_WEB_FONT_FAMILY;
- int web_font_size_id = IDS_WEB_FONT_SIZE;
-#if defined(OS_WIN)
- // Vary font settings for Windows XP.
- if (base::win::GetVersion() < base::win::VERSION_VISTA) {
- web_font_family_id = IDS_WEB_FONT_FAMILY_XP;
- web_font_size_id = IDS_WEB_FONT_SIZE_XP;
- }
-#endif
-
- std::string font_family = l10n_util::GetStringUTF8(web_font_family_id);
-
-#if defined(TOOLKIT_GTK)
- // Use the system font on Linux/GTK. Keep the hard-coded font families as
- // backup in case for some crazy reason this one isn't available.
- font_family = ui::ResourceBundle::GetSharedInstance().GetFont(
- ui::ResourceBundle::BaseFont).GetFontName() + ", " + font_family;
-#endif
-
- localized_strings->SetString("fontfamily", font_family);
- localized_strings->SetString("fontsize",
- l10n_util::GetStringUTF8(web_font_size_id));
- localized_strings->SetString("textdirection",
- base::i18n::IsRTL() ? "rtl" : "ltr");
-}
-
-void URLDataSource::SendResponseOnIOThread(
+void URLDataSourceImpl::SendResponseOnIOThread(
int request_id,
scoped_refptr<base::RefCountedMemory> bytes) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));

Powered by Google App Engine
This is Rietveld 408576698