| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "content/browser/renderer_host/render_process_host_impl.h" | 6 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 7 #include "content/common/child_process_messages.h" | 7 #include "content/common/child_process_messages.h" |
| 8 #include "content/public/browser/render_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
| 9 #include "content/public/browser/render_process_host_observer.h" | 9 #include "content/public/browser/render_process_host_observer.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 return count; | 35 return count; |
| 36 } | 36 } |
| 37 | 37 |
| 38 class RenderProcessHostTest : public ContentBrowserTest, | 38 class RenderProcessHostTest : public ContentBrowserTest, |
| 39 public RenderProcessHostObserver { | 39 public RenderProcessHostObserver { |
| 40 public: | 40 public: |
| 41 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {} | 41 RenderProcessHostTest() : process_exits_(0), host_destructions_(0) {} |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 // RenderProcessHostObserver: | 44 // RenderProcessHostObserver: |
| 45 virtual void RenderProcessExited(RenderProcessHost* host, | 45 void RenderProcessExited(RenderProcessHost* host, |
| 46 base::TerminationStatus status, | 46 base::TerminationStatus status, |
| 47 int exit_code) override { | 47 int exit_code) override { |
| 48 ++process_exits_; | 48 ++process_exits_; |
| 49 } | 49 } |
| 50 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) override { | 50 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
| 51 ++host_destructions_; | 51 ++host_destructions_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 int process_exits_; | 54 int process_exits_; |
| 55 int host_destructions_; | 55 int host_destructions_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Sometimes the renderer process's ShutdownRequest (corresponding to the | 58 // Sometimes the renderer process's ShutdownRequest (corresponding to the |
| 59 // ViewMsg_WasSwappedOut from a previous navigation) doesn't arrive until after | 59 // ViewMsg_WasSwappedOut from a previous navigation) doesn't arrive until after |
| 60 // the browser process decides to re-use the renderer for a new purpose. This | 60 // the browser process decides to re-use the renderer for a new purpose. This |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 EXPECT_EQ(2, RenderProcessHostCount()); | 113 EXPECT_EQ(2, RenderProcessHostCount()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 class ShellCloser : public RenderProcessHostObserver { | 116 class ShellCloser : public RenderProcessHostObserver { |
| 117 public: | 117 public: |
| 118 ShellCloser(Shell* shell, std::string* logging_string) | 118 ShellCloser(Shell* shell, std::string* logging_string) |
| 119 : shell_(shell), logging_string_(logging_string) {} | 119 : shell_(shell), logging_string_(logging_string) {} |
| 120 | 120 |
| 121 protected: | 121 protected: |
| 122 // RenderProcessHostObserver: | 122 // RenderProcessHostObserver: |
| 123 virtual void RenderProcessExited(RenderProcessHost* host, | 123 void RenderProcessExited(RenderProcessHost* host, |
| 124 base::TerminationStatus status, | 124 base::TerminationStatus status, |
| 125 int exit_code) override { | 125 int exit_code) override { |
| 126 logging_string_->append("ShellCloser::RenderProcessExited "); | 126 logging_string_->append("ShellCloser::RenderProcessExited "); |
| 127 shell_->Close(); | 127 shell_->Close(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) override { | 130 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
| 131 logging_string_->append("ShellCloser::RenderProcessHostDestroyed "); | 131 logging_string_->append("ShellCloser::RenderProcessHostDestroyed "); |
| 132 } | 132 } |
| 133 | 133 |
| 134 Shell* shell_; | 134 Shell* shell_; |
| 135 std::string* logging_string_; | 135 std::string* logging_string_; |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class ObserverLogger : public RenderProcessHostObserver { | 138 class ObserverLogger : public RenderProcessHostObserver { |
| 139 public: | 139 public: |
| 140 explicit ObserverLogger(std::string* logging_string) | 140 explicit ObserverLogger(std::string* logging_string) |
| 141 : logging_string_(logging_string), host_destroyed_(false) {} | 141 : logging_string_(logging_string), host_destroyed_(false) {} |
| 142 | 142 |
| 143 bool host_destroyed() { return host_destroyed_; } | 143 bool host_destroyed() { return host_destroyed_; } |
| 144 | 144 |
| 145 protected: | 145 protected: |
| 146 // RenderProcessHostObserver: | 146 // RenderProcessHostObserver: |
| 147 virtual void RenderProcessExited(RenderProcessHost* host, | 147 void RenderProcessExited(RenderProcessHost* host, |
| 148 base::TerminationStatus status, | 148 base::TerminationStatus status, |
| 149 int exit_code) override { | 149 int exit_code) override { |
| 150 logging_string_->append("ObserverLogger::RenderProcessExited "); | 150 logging_string_->append("ObserverLogger::RenderProcessExited "); |
| 151 } | 151 } |
| 152 | 152 |
| 153 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) override { | 153 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
| 154 logging_string_->append("ObserverLogger::RenderProcessHostDestroyed "); | 154 logging_string_->append("ObserverLogger::RenderProcessHostDestroyed "); |
| 155 host_destroyed_ = true; | 155 host_destroyed_ = true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 std::string* logging_string_; | 158 std::string* logging_string_; |
| 159 bool host_destroyed_; | 159 bool host_destroyed_; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, | 162 IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, |
| 163 AllProcessExitedCallsBeforeAnyHostDestroyedCalls) { | 163 AllProcessExitedCallsBeforeAnyHostDestroyedCalls) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); | 227 GURL test_url = embedded_test_server()->GetURL("/simple_page.html"); |
| 228 NavigateToURL(shell(), test_url); | 228 NavigateToURL(shell(), test_url); |
| 229 | 229 |
| 230 EXPECT_EQ(1, RenderProcessHostCount()); | 230 EXPECT_EQ(1, RenderProcessHostCount()); |
| 231 EXPECT_EQ(0, process_exits_); | 231 EXPECT_EQ(0, process_exits_); |
| 232 } | 232 } |
| 233 #endif | 233 #endif |
| 234 | 234 |
| 235 } // namespace | 235 } // namespace |
| 236 } // namespace content | 236 } // namespace content |
| OLD | NEW |