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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/user_manager.h" |
11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
13 | 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
17 // Set the render host waiting time to 5s on Android, that's the same | 22 // Set the render host waiting time to 5s on Android, that's the same |
18 // as an "Application Not Responding" timeout. | 23 // as an "Application Not Responding" timeout. |
19 const int64 kTimerDelaySeconds = 5; | 24 const int64 kTimerDelaySeconds = 5; |
20 #else | 25 #else |
21 const int64 kTimerDelaySeconds = 1; | 26 const int64 kTimerDelaySeconds = 1; |
(...skipping 28 matching lines...) Expand all Loading... |
50 // --single-process mode to avoid race conditions. | 55 // --single-process mode to avoid race conditions. |
51 DCHECK(hosts.empty() || profile->IsOffTheRecord() || | 56 DCHECK(hosts.empty() || profile->IsOffTheRecord() || |
52 content::RenderProcessHost::run_renderer_in_process()) << \ | 57 content::RenderProcessHost::run_renderer_in_process()) << \ |
53 "Profile still has " << hosts.size() << " hosts"; | 58 "Profile still has " << hosts.size() << " hosts"; |
54 // Note that we still test for !profile->IsOffTheRecord here even though we | 59 // Note that we still test for !profile->IsOffTheRecord here even though we |
55 // DCHECK'd above because we want to protect Release builds against this even | 60 // DCHECK'd above because we want to protect Release builds against this even |
56 // we need to identify if there are leaks when we run Debug builds. | 61 // we need to identify if there are leaks when we run Debug builds. |
57 if (hosts.empty() || !profile->IsOffTheRecord()) { | 62 if (hosts.empty() || !profile->IsOffTheRecord()) { |
58 if (profile->IsOffTheRecord()) | 63 if (profile->IsOffTheRecord()) |
59 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); | 64 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
60 else | 65 else { DLOG(ERROR) << "Delete the profile! " << profile->GetPath().MaybeAsAS
CII(); |
61 delete profile; | 66 delete profile; |
| 67 } |
62 } else { | 68 } else { |
63 // The instance will destroy itself once all render process hosts referring | 69 // The instance will destroy itself once all render process hosts referring |
64 // to it are properly terminated. | 70 // to it are properly terminated. |
65 new ProfileDestroyer(profile, &hosts); | 71 new ProfileDestroyer(profile, &hosts); |
66 } | 72 } |
67 } | 73 } |
68 | 74 |
69 // This can be called to cancel any pending destruction and destroy the profile | 75 // This can be called to cancel any pending destruction and destroy the profile |
70 // now, e.g., if the parent profile is being destroyed while the incognito one | 76 // now, e.g., if the parent profile is being destroyed while the incognito one |
71 // still pending... | 77 // still pending... |
(...skipping 10 matching lines...) Expand all Loading... |
82 NOTREACHED() << "A render process host wasn't destroyed early enough."; | 88 NOTREACHED() << "A render process host wasn't destroyed early enough."; |
83 (*i)->profile_ = NULL; | 89 (*i)->profile_ = NULL; |
84 break; | 90 break; |
85 } | 91 } |
86 } | 92 } |
87 } | 93 } |
88 DCHECK(profile->GetOriginalProfile()); | 94 DCHECK(profile->GetOriginalProfile()); |
89 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); | 95 profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
90 } | 96 } |
91 | 97 |
| 98 // static |
| 99 void ProfileDestroyer::DestroyGuestProfileIfAppropriate() { |
| 100 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 101 DCHECK(profile_manager); |
| 102 Profile* guest_profile = profile_manager-> |
| 103 GetProfileByPath(ProfileManager::GetGuestProfilePath()); |
| 104 DLOG(ERROR) << "Calling DestroyGuestProfileIfAppropriate!"; |
| 105 if (!guest_profile) |
| 106 return; |
| 107 |
| 108 if (BrowserList::IsOffTheRecordSessionActiveForProfile(guest_profile)) |
| 109 return; |
| 110 |
| 111 DLOG(ERROR) << "Deleting the Guest Profile!"; |
| 112 |
| 113 content::BrowserThread::PostTask( |
| 114 content::BrowserThread::UI, |
| 115 FROM_HERE, |
| 116 base::Bind(&ProfileDestroyer::DestroyProfileWhenAppropriate, |
| 117 guest_profile)); |
| 118 } |
| 119 |
92 ProfileDestroyer::ProfileDestroyer(Profile* const profile, HostSet* hosts) | 120 ProfileDestroyer::ProfileDestroyer(Profile* const profile, HostSet* hosts) |
93 : timer_(false, false), | 121 : timer_(false, false), |
94 num_hosts_(0), | 122 num_hosts_(0), |
95 profile_(profile), | 123 profile_(profile), |
96 weak_ptr_factory_(this) { | 124 weak_ptr_factory_(this) { |
97 if (pending_destroyers_ == NULL) | 125 if (pending_destroyers_ == NULL) |
98 pending_destroyers_ = new DestroyerSet; | 126 pending_destroyers_ = new DestroyerSet; |
99 pending_destroyers_->insert(this); | 127 pending_destroyers_->insert(this); |
100 for (HostSet::iterator i = hosts->begin(); i != hosts->end(); ++i) { | 128 for (HostSet::iterator i = hosts->begin(); i != hosts->end(); ++i) { |
101 (*i)->AddObserver(this); | 129 (*i)->AddObserver(this); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 176 } |
149 } | 177 } |
150 | 178 |
151 void ProfileDestroyer::DestroyProfile() { | 179 void ProfileDestroyer::DestroyProfile() { |
152 // We might have been cancelled externally before the timer expired. | 180 // We might have been cancelled externally before the timer expired. |
153 if (!profile_) { | 181 if (!profile_) { |
154 delete this; | 182 delete this; |
155 return; | 183 return; |
156 } | 184 } |
157 | 185 |
158 DCHECK(profile_->IsOffTheRecord()); | 186 DCHECK(profile_->IsOffTheRecord() || profile_->IsGuestSession()); |
159 DCHECK(profile_->GetOriginalProfile()); | 187 DCHECK(profile_->GetOriginalProfile()); |
160 profile_->GetOriginalProfile()->DestroyOffTheRecordProfile(); | 188 profile_->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
161 profile_ = NULL; | 189 profile_ = NULL; |
162 | 190 |
163 // And stop the timer so we can be released early too. | 191 // And stop the timer so we can be released early too. |
164 timer_.Stop(); | 192 timer_.Stop(); |
165 | 193 |
166 delete this; | 194 delete this; |
167 } | 195 } |
168 | 196 |
169 // static | 197 // static |
170 bool ProfileDestroyer::GetHostsForProfile( | 198 bool ProfileDestroyer::GetHostsForProfile( |
171 Profile* const profile, HostSet* hosts) { | 199 Profile* const profile, HostSet* hosts) { |
172 for (content::RenderProcessHost::iterator iter( | 200 for (content::RenderProcessHost::iterator iter( |
173 content::RenderProcessHost::AllHostsIterator()); | 201 content::RenderProcessHost::AllHostsIterator()); |
174 !iter.IsAtEnd(); iter.Advance()) { | 202 !iter.IsAtEnd(); iter.Advance()) { |
175 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); | 203 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); |
176 if (render_process_host && | 204 if (render_process_host && |
177 render_process_host->GetBrowserContext() == profile) { | 205 render_process_host->GetBrowserContext() == profile) { |
178 hosts->insert(render_process_host); | 206 hosts->insert(render_process_host); |
179 } | 207 } |
180 } | 208 } |
181 return !hosts->empty(); | 209 return !hosts->empty(); |
182 } | 210 } |
OLD | NEW |