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

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

Issue 6992019: Allow overriding WebUIFactory when test flag is set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment namespace end. Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/test_chrome_web_ui_factory.cc
diff --git a/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cc8366569bd11c7626b909c58eb62b627cd28e7b
--- /dev/null
+++ b/chrome/browser/ui/webui/test_chrome_web_ui_factory.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
+
+#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
+#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/webui/web_ui.h"
+
+TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() {
+}
+
+TestChromeWebUIFactory::TestChromeWebUIFactory() {
+}
+
+TestChromeWebUIFactory::~TestChromeWebUIFactory() {
+}
+
+void
Evan Stade 2011/05/24 17:25:59 wrap the args rather than the return type
Sheridan Rawlins 2011/05/24 20:17:22 Done.
+TestChromeWebUIFactory::AddFactoryOverride(const std::string& host,
+ WebUIProvider* provider) {
+ DCHECK_EQ(size_t(0), GetInstance()->factory_overrides_.count(host));
Evan Stade 2011/05/24 17:25:59 0U rather than size_t(0)
Sheridan Rawlins 2011/05/24 20:17:22 Done.
+ GetInstance()->factory_overrides_[host] = provider;
+}
+
+void
+TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) {
+ DCHECK_EQ(size_t(1), GetInstance()->factory_overrides_.count(host));
+ GetInstance()->factory_overrides_.erase(host);
+}
+
+WebUI::TypeID
+TestChromeWebUIFactory::GetWebUIType(Profile* profile, const GURL& url) const {
+ WebUIProvider* provider = GetWebUIProvider(profile, url);
+ return provider ? reinterpret_cast<WebUI::TypeID>(provider) :
+ ChromeWebUIFactory::GetWebUIType(profile, url);
+}
+
+WebUI*
+TestChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents,
+ const GURL& url) const {
+ WebUIProvider* provider = GetWebUIProvider(tab_contents->profile(), url);
+ return provider ? provider->NewWebUI(tab_contents, url) :
+ ChromeWebUIFactory::CreateWebUIForURL(tab_contents, url);
+}
+
+TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() {
+ return static_cast<TestChromeWebUIFactory*>(
+ ChromeWebUIFactory::GetInstance());
+}
+
+TestChromeWebUIFactory::WebUIProvider*
+TestChromeWebUIFactory::GetWebUIProvider(Profile* profile,
+ const GURL& url) const {
+ FactoryOverridesMap::const_iterator found =
+ factory_overrides_.find(url.host());
+ if (found != factory_overrides_.end()) {
Evan Stade 2011/05/24 17:25:59 no curlies
Sheridan Rawlins 2011/05/24 20:17:22 Done.
+ return found->second;
+ }
+ return NULL;
+}

Powered by Google App Engine
This is Rietveld 408576698