| 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/location.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 10 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
| 17 // Set the render host waiting time to 5s on Android, that's the same | 19 // Set the render host waiting time to 5s on Android, that's the same |
| 18 // as an "Application Not Responding" timeout. | 20 // as an "Application Not Responding" timeout. |
| 19 const int64 kTimerDelaySeconds = 5; | 21 const int64 kTimerDelaySeconds = 5; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 void ProfileDestroyer::RenderProcessHostDestroyed( | 140 void ProfileDestroyer::RenderProcessHostDestroyed( |
| 139 content::RenderProcessHost* host) { | 141 content::RenderProcessHost* host) { |
| 140 DCHECK(num_hosts_ > 0); | 142 DCHECK(num_hosts_ > 0); |
| 141 --num_hosts_; | 143 --num_hosts_; |
| 142 if (num_hosts_ == 0) { | 144 if (num_hosts_ == 0) { |
| 143 // Delay the destruction one step further in case other observers need to | 145 // Delay the destruction one step further in case other observers need to |
| 144 // look at the profile attached to the host. | 146 // look at the profile attached to the host. |
| 145 base::MessageLoop::current()->PostTask( | 147 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 146 FROM_HERE, base::Bind( | 148 FROM_HERE, base::Bind(&ProfileDestroyer::DestroyProfile, |
| 147 &ProfileDestroyer::DestroyProfile, weak_ptr_factory_.GetWeakPtr())); | 149 weak_ptr_factory_.GetWeakPtr())); |
| 148 } | 150 } |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ProfileDestroyer::DestroyProfile() { | 153 void ProfileDestroyer::DestroyProfile() { |
| 152 // We might have been cancelled externally before the timer expired. | 154 // We might have been cancelled externally before the timer expired. |
| 153 if (!profile_) { | 155 if (!profile_) { |
| 154 delete this; | 156 delete this; |
| 155 return; | 157 return; |
| 156 } | 158 } |
| 157 | 159 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 173 content::RenderProcessHost::AllHostsIterator()); | 175 content::RenderProcessHost::AllHostsIterator()); |
| 174 !iter.IsAtEnd(); iter.Advance()) { | 176 !iter.IsAtEnd(); iter.Advance()) { |
| 175 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); | 177 content::RenderProcessHost* render_process_host = iter.GetCurrentValue(); |
| 176 if (render_process_host && | 178 if (render_process_host && |
| 177 render_process_host->GetBrowserContext() == profile) { | 179 render_process_host->GetBrowserContext() == profile) { |
| 178 hosts->insert(render_process_host); | 180 hosts->insert(render_process_host); |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 return !hosts->empty(); | 183 return !hosts->empty(); |
| 182 } | 184 } |
| OLD | NEW |