| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 #include <vector> |
| 11 |
| 9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/scoped_vector.h" | |
| 13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 17 #include "content/browser/browser_thread_impl.h" |
| 16 #include "content/browser/browsing_instance.h" | 18 #include "content/browser/browsing_instance.h" |
| 17 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 18 #include "content/browser/frame_host/navigation_entry_impl.h" | 20 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 19 #include "content/browser/renderer_host/render_process_host_impl.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_view_host_impl.h" | 22 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 21 #include "content/browser/web_contents/web_contents_impl.h" | 23 #include "content/browser/web_contents/web_contents_impl.h" |
| 22 #include "content/browser/webui/content_web_ui_controller_factory.h" | 24 #include "content/browser/webui/content_web_ui_controller_factory.h" |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 // On Android by default the number of renderer hosts is unlimited and process | 587 // On Android by default the number of renderer hosts is unlimited and process |
| 586 // sharing doesn't happen. We set the override so that the test can run | 588 // sharing doesn't happen. We set the override so that the test can run |
| 587 // everywhere. | 589 // everywhere. |
| 588 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); | 590 RenderProcessHost::SetMaxRendererProcessCount(kMaxRendererProcessCount); |
| 589 | 591 |
| 590 ChildProcessSecurityPolicyImpl* policy = | 592 ChildProcessSecurityPolicyImpl* policy = |
| 591 ChildProcessSecurityPolicyImpl::GetInstance(); | 593 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 592 | 594 |
| 593 // Make a bunch of mock renderers so that we hit the limit. | 595 // Make a bunch of mock renderers so that we hit the limit. |
| 594 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 596 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 595 ScopedVector<MockRenderProcessHost> hosts; | 597 std::vector<std::unique_ptr<MockRenderProcessHost>> hosts; |
| 596 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) | 598 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) |
| 597 hosts.push_back(new MockRenderProcessHost(browser_context.get())); | 599 hosts.push_back( |
| 600 base::MakeUnique<MockRenderProcessHost>(browser_context.get())); |
| 598 | 601 |
| 599 // Create some extension instances and make sure they share a process. | 602 // Create some extension instances and make sure they share a process. |
| 600 scoped_refptr<SiteInstanceImpl> extension1_instance( | 603 scoped_refptr<SiteInstanceImpl> extension1_instance( |
| 601 CreateSiteInstance(browser_context.get(), | 604 CreateSiteInstance(browser_context.get(), |
| 602 GURL(kPrivilegedScheme + std::string("://foo/bar")))); | 605 GURL(kPrivilegedScheme + std::string("://foo/bar")))); |
| 603 set_privileged_process_id(extension1_instance->GetProcess()->GetID()); | 606 set_privileged_process_id(extension1_instance->GetProcess()->GetID()); |
| 604 | 607 |
| 605 scoped_refptr<SiteInstanceImpl> extension2_instance( | 608 scoped_refptr<SiteInstanceImpl> extension2_instance( |
| 606 CreateSiteInstance(browser_context.get(), | 609 CreateSiteInstance(browser_context.get(), |
| 607 GURL(kPrivilegedScheme + std::string("://baz/bar")))); | 610 GURL(kPrivilegedScheme + std::string("://baz/bar")))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 620 browser_context.get(), | 623 browser_context.get(), |
| 621 GURL(kChromeUIScheme + std::string("://media-internals")))); | 624 GURL(kChromeUIScheme + std::string("://media-internals")))); |
| 622 | 625 |
| 623 std::unique_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); | 626 std::unique_ptr<RenderProcessHost> dom_host(webui1_instance->GetProcess()); |
| 624 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 627 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
| 625 | 628 |
| 626 // Make sure none of differing privilege processes are mixed. | 629 // Make sure none of differing privilege processes are mixed. |
| 627 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 630 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
| 628 | 631 |
| 629 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { | 632 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
| 630 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 633 EXPECT_NE(extension1_instance->GetProcess(), hosts[i].get()); |
| 631 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 634 EXPECT_NE(webui1_instance->GetProcess(), hosts[i].get()); |
| 632 } | 635 } |
| 633 | 636 |
| 634 DrainMessageLoop(); | 637 DrainMessageLoop(); |
| 635 | 638 |
| 636 // Disable the process limit override. | 639 // Disable the process limit override. |
| 637 RenderProcessHost::SetMaxRendererProcessCount(0u); | 640 RenderProcessHost::SetMaxRendererProcessCount(0u); |
| 638 } | 641 } |
| 639 | 642 |
| 640 // Test to ensure that HasWrongProcessForURL behaves properly for different | 643 // Test to ensure that HasWrongProcessForURL behaves properly for different |
| 641 // types of URLs. | 644 // types of URLs. |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 835 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 833 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 836 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 834 | 837 |
| 835 // Free the subframe instance, which should free the browsing instance. | 838 // Free the subframe instance, which should free the browsing instance. |
| 836 subframe_instance = nullptr; | 839 subframe_instance = nullptr; |
| 837 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 838 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 841 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 839 } | 842 } |
| 840 | 843 |
| 841 } // namespace content | 844 } // namespace content |
| OLD | NEW |