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 "chrome/browser/profiles/profile_destroyer.h" | 5 #include "chrome/browser/profiles/profile_destroyer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 std::vector<content::RenderProcessHost*> hosts; | 29 std::vector<content::RenderProcessHost*> hosts; |
30 // Testing profiles can simply be deleted directly. Some tests don't setup | 30 // Testing profiles can simply be deleted directly. Some tests don't setup |
31 // RenderProcessHost correctly and don't necessary run on the UI thread | 31 // RenderProcessHost correctly and don't necessary run on the UI thread |
32 // anyway, so we can't use the AllHostIterator. | 32 // anyway, so we can't use the AllHostIterator. |
33 if (profile->AsTestingProfile() == NULL) { | 33 if (profile->AsTestingProfile() == NULL) { |
34 GetHostsForProfile(profile, &hosts); | 34 GetHostsForProfile(profile, &hosts); |
35 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) | 35 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) |
36 GetHostsForProfile(profile->GetOffTheRecordProfile(), &hosts); | 36 GetHostsForProfile(profile->GetOffTheRecordProfile(), &hosts); |
37 } | 37 } |
38 // This should never happen for non Off the record profile, this means that | 38 // Generally, !hosts.empty() means that there is a leak in a render process |
39 // there is a leak in a render process host that MUST BE FIXED!!! | 39 // host that MUST BE FIXED!!! |
40 DCHECK(hosts.empty() || profile->IsOffTheRecord()); | 40 // |
| 41 // However, off-the-record profiles are destroyed before their |
| 42 // RenderProcessHosts in order to erase private data quickly, and |
| 43 // RenderProcessHostImpl::Release() avoids destroying RenderProcessHosts in |
| 44 // --single-process mode to avoid race conditions. |
| 45 DCHECK(hosts.empty() || profile->IsOffTheRecord() || |
| 46 content::RenderProcessHost::run_renderer_in_process()); |
41 // Note that we still test for !profile->IsOffTheRecord here even though we | 47 // Note that we still test for !profile->IsOffTheRecord here even though we |
42 // DCHECK'd above because we want to protect Release builds against this even | 48 // DCHECK'd above because we want to protect Release builds against this even |
43 // we need to identify if there are leaks when we run Debug builds. | 49 // we need to identify if there are leaks when we run Debug builds. |
44 if (hosts.empty() || !profile->IsOffTheRecord()) { | 50 if (hosts.empty() || !profile->IsOffTheRecord()) { |
45 if (profile->IsOffTheRecord()) | 51 if (profile->IsOffTheRecord()) |
46 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); | 52 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
47 else | 53 else |
48 delete profile; | 54 delete profile; |
49 } else { | 55 } else { |
50 // The instance will destroy itself once all render process hosts referring | 56 // The instance will destroy itself once all render process hosts referring |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 content::RenderProcessHost::AllHostsIterator()); | 171 content::RenderProcessHost::AllHostsIterator()); |
166 !iter.IsAtEnd(); iter.Advance()) { | 172 !iter.IsAtEnd(); iter.Advance()) { |
167 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); | 173 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); |
168 if (render_process_host && Profile::FromBrowserContext( | 174 if (render_process_host && Profile::FromBrowserContext( |
169 render_process_host->GetBrowserContext()) == profile) { | 175 render_process_host->GetBrowserContext()) == profile) { |
170 hosts->push_back(render_process_host); | 176 hosts->push_back(render_process_host); |
171 } | 177 } |
172 } | 178 } |
173 return !hosts->empty(); | 179 return !hosts->empty(); |
174 } | 180 } |
OLD | NEW |