Chromium Code Reviews| Index: chrome/browser/profiles/profile_destroyer.cc |
| =================================================================== |
| --- chrome/browser/profiles/profile_destroyer.cc (revision 122340) |
| +++ chrome/browser/profiles/profile_destroyer.cc (working copy) |
| @@ -8,21 +8,33 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/message_loop.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_process_host.h" |
| // static |
| -void ProfileDestroyer::DestroyOffTheRecordProfile(Profile* const profile) { |
| +void ProfileDestroyer::DestroyProfileWhenAppropriate(Profile* const profile) { |
| std::vector<content::RenderProcessHost*> hosts; |
| - if (GetHostsForProfile(profile, &hosts)) { |
| + // Some tests try to destroy their profile on other threads than the UI. |
|
sky
2012/02/17 16:53:09
I hate to have to change around code like this for
MAD
2012/02/17 17:06:09
Yeah, I agree with you... I was lazy... I was scar
|
| + // Ignore those, since we can't enumerate the hosts unless we're on the UI |
| + // thread. |
| + if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| + GetHostsForProfile(profile, &hosts); |
| + if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) |
| + GetHostsForProfile(profile->GetOffTheRecordProfile(), &hosts); |
| + } |
| + |
| + if (hosts.empty()) { |
| + if (profile->IsOffTheRecord()) |
| + profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
| + else |
| + delete profile; |
| + } else { |
| // The instance will destroy itself once all render process hosts referring |
| - // to it are properly terminated. |
| + // to it and/or it's off the record profile are properly terminated. |
| scoped_refptr<ProfileDestroyer> profile_destroyer( |
| new ProfileDestroyer(profile, hosts)); |
| - } else { |
| - // Safe to destroy now... We're done... |
| - profile->GetOriginalProfile()->DestroyOffTheRecordProfile(); |
| } |
| } |
| @@ -41,7 +53,7 @@ |
| ProfileDestroyer::~ProfileDestroyer() { |
| // Check again, in case other render hosts were added while we were |
| // waiting for the previous ones to go away... |
| - DestroyOffTheRecordProfile(profile_); |
| + DestroyProfileWhenAppropriate(profile_); |
| } |
| void ProfileDestroyer::Observe(int type, |