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

Side by Side Diff: chrome/browser/ui/webui/test_chrome_web_ui_factory.cc

Issue 9224002: Make WebUI objects not derive from WebUI. WebUI objects own the controller. This is the ownership... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync to head to clear linux_chromeos browsertest failures Created 8 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 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 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" 5 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
9 9
10 using content::WebContents; 10 using content::WebContents;
11 using content::WebUIController;
11 12
12 TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() { 13 TestChromeWebUIFactory::WebUIProvider::~WebUIProvider() {
13 } 14 }
14 15
15 TestChromeWebUIFactory::TestChromeWebUIFactory() { 16 TestChromeWebUIFactory::TestChromeWebUIFactory() {
16 } 17 }
17 18
18 TestChromeWebUIFactory::~TestChromeWebUIFactory() { 19 TestChromeWebUIFactory::~TestChromeWebUIFactory() {
19 } 20 }
20 21
21 void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host, 22 void TestChromeWebUIFactory::AddFactoryOverride(const std::string& host,
22 WebUIProvider* provider) { 23 WebUIProvider* provider) {
23 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host)); 24 DCHECK_EQ(0U, GetInstance()->factory_overrides_.count(host));
24 GetInstance()->factory_overrides_[host] = provider; 25 GetInstance()->factory_overrides_[host] = provider;
25 } 26 }
26 27
27 void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) { 28 void TestChromeWebUIFactory::RemoveFactoryOverride(const std::string& host) {
28 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host)); 29 DCHECK_EQ(1U, GetInstance()->factory_overrides_.count(host));
29 GetInstance()->factory_overrides_.erase(host); 30 GetInstance()->factory_overrides_.erase(host);
30 } 31 }
31 32
32 WebUI::TypeID TestChromeWebUIFactory::GetWebUIType( 33 WebUI::TypeID TestChromeWebUIFactory::GetWebUIType(
33 content::BrowserContext* browser_context, const GURL& url) const { 34 content::BrowserContext* browser_context, const GURL& url) const {
34 Profile* profile = Profile::FromBrowserContext(browser_context); 35 Profile* profile = Profile::FromBrowserContext(browser_context);
35 WebUIProvider* provider = GetWebUIProvider(profile, url); 36 WebUIProvider* provider = GetWebUIProvider(profile, url);
36 return provider ? reinterpret_cast<WebUI::TypeID>(provider) : 37 return provider ? reinterpret_cast<WebUI::TypeID>(provider) :
37 ChromeWebUIFactory::GetWebUIType(profile, url); 38 ChromeWebUIFactory::GetWebUIType(profile, url);
38 } 39 }
39 40
40 WebUI* TestChromeWebUIFactory::CreateWebUIForURL(WebContents* web_contents, 41 WebUIController* TestChromeWebUIFactory::CreateWebUIForURL(
41 const GURL& url) const { 42 WebUI* web_ui, const GURL& url) const {
42 Profile* profile = 43 Profile* profile =
43 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 44 Profile::FromBrowserContext(web_ui->web_contents()->GetBrowserContext());
44 WebUIProvider* provider = GetWebUIProvider(profile, url); 45 WebUIProvider* provider = GetWebUIProvider(profile, url);
45 return provider ? provider->NewWebUI(web_contents, url) : 46 return provider ? provider->NewWebUI(web_ui, url) :
46 ChromeWebUIFactory::CreateWebUIForURL(web_contents, url); 47 ChromeWebUIFactory::CreateWebUIForURL(web_ui, url);
47 } 48 }
48 49
49 TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() { 50 TestChromeWebUIFactory* TestChromeWebUIFactory::GetInstance() {
50 return static_cast<TestChromeWebUIFactory*>( 51 return static_cast<TestChromeWebUIFactory*>(
51 ChromeWebUIFactory::GetInstance()); 52 ChromeWebUIFactory::GetInstance());
52 } 53 }
53 54
54 TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider( 55 TestChromeWebUIFactory::WebUIProvider* TestChromeWebUIFactory::GetWebUIProvider(
55 Profile* profile, const GURL& url) const { 56 Profile* profile, const GURL& url) const {
56 FactoryOverridesMap::const_iterator found = 57 FactoryOverridesMap::const_iterator found =
57 factory_overrides_.find(url.host()); 58 factory_overrides_.find(url.host());
58 return (found == factory_overrides_.end()) ? NULL : found->second; 59 return (found == factory_overrides_.end()) ? NULL : found->second;
59 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698