| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/power/renderer_freezer.h" | 5 #include "chrome/browser/chromeos/power/renderer_freezer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "extensions/browser/process_map.h" | 27 #include "extensions/browser/process_map.h" |
| 28 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 29 #include "extensions/common/permissions/api_permission.h" | 29 #include "extensions/common/permissions/api_permission.h" |
| 30 #include "extensions/common/permissions/permissions_data.h" | 30 #include "extensions/common/permissions/permissions_data.h" |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 | 33 |
| 34 RendererFreezer::RendererFreezer( | 34 RendererFreezer::RendererFreezer( |
| 35 std::unique_ptr<RendererFreezer::Delegate> delegate) | 35 std::unique_ptr<RendererFreezer::Delegate> delegate) |
| 36 : delegate_(std::move(delegate)), weak_factory_(this) { | 36 : delegate_(std::move(delegate)), weak_factory_(this) { |
| 37 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 38 VLOG(1) << "Creating RendererFreezer " << this; | |
| 39 delegate_->CheckCanFreezeRenderers( | 37 delegate_->CheckCanFreezeRenderers( |
| 40 base::Bind(&RendererFreezer::OnCheckCanFreezeRenderersComplete, | 38 base::Bind(&RendererFreezer::OnCheckCanFreezeRenderersComplete, |
| 41 weak_factory_.GetWeakPtr())); | 39 weak_factory_.GetWeakPtr())); |
| 42 } | 40 } |
| 43 | 41 |
| 44 RendererFreezer::~RendererFreezer() { | 42 RendererFreezer::~RendererFreezer() { |
| 45 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 46 VLOG(1) << "Destroying RendererFreezer " << this; | |
| 47 for (int rph_id : gcm_extension_processes_) { | 43 for (int rph_id : gcm_extension_processes_) { |
| 48 content::RenderProcessHost* host = | 44 content::RenderProcessHost* host = |
| 49 content::RenderProcessHost::FromID(rph_id); | 45 content::RenderProcessHost::FromID(rph_id); |
| 50 if (host) | 46 if (host) |
| 51 host->RemoveObserver(this); | 47 host->RemoveObserver(this); |
| 52 } | 48 } |
| 53 } | 49 } |
| 54 | 50 |
| 55 void RendererFreezer::SuspendImminent() { | 51 void RendererFreezer::SuspendImminent() { |
| 56 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 57 VLOG(1) << "Asking delegate to freeze renderers"; | |
| 58 // All the delegate's operations are asynchronous so they may not complete | 52 // All the delegate's operations are asynchronous so they may not complete |
| 59 // before the system suspends. This is ok since the renderers only need to be | 53 // before the system suspends. This is ok since the renderers only need to be |
| 60 // frozen in dark resume. As long as they do get frozen soon after we enter | 54 // frozen in dark resume. As long as they do get frozen soon after we enter |
| 61 // dark resume, there shouldn't be a problem. | 55 // dark resume, there shouldn't be a problem. |
| 62 delegate_->FreezeRenderers(); | 56 delegate_->FreezeRenderers(); |
| 63 } | 57 } |
| 64 | 58 |
| 65 void RendererFreezer::SuspendDone() { | 59 void RendererFreezer::SuspendDone() { |
| 66 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 67 VLOG(1) << "Asking delegate to thaw renderers"; | |
| 68 delegate_->ThawRenderers(base::Bind(&RendererFreezer::OnThawRenderersComplete, | 60 delegate_->ThawRenderers(base::Bind(&RendererFreezer::OnThawRenderersComplete, |
| 69 weak_factory_.GetWeakPtr())); | 61 weak_factory_.GetWeakPtr())); |
| 70 } | 62 } |
| 71 | 63 |
| 72 void RendererFreezer::Observe(int type, | 64 void RendererFreezer::Observe(int type, |
| 73 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
| 74 const content::NotificationDetails& details) { | 66 const content::NotificationDetails& details) { |
| 75 switch (type) { | 67 switch (type) { |
| 76 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { | 68 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: { |
| 77 OnScreenLockStateChanged( | 69 OnScreenLockStateChanged( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 123 |
| 132 registrar_.Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 124 registrar_.Add(this, chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 133 content::NotificationService::AllBrowserContextsAndSources()); | 125 content::NotificationService::AllBrowserContextsAndSources()); |
| 134 registrar_.Add( | 126 registrar_.Add( |
| 135 this, | 127 this, |
| 136 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 128 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 137 content::NotificationService::AllBrowserContextsAndSources()); | 129 content::NotificationService::AllBrowserContextsAndSources()); |
| 138 } | 130 } |
| 139 | 131 |
| 140 void RendererFreezer::OnThawRenderersComplete(bool success) { | 132 void RendererFreezer::OnThawRenderersComplete(bool success) { |
| 141 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 142 VLOG(1) << "Thawing renderers complete"; | |
| 143 if (success) | 133 if (success) |
| 144 return; | 134 return; |
| 145 | 135 |
| 146 // We failed to write the thaw command and the renderers are still frozen. We | 136 // We failed to write the thaw command and the renderers are still frozen. We |
| 147 // are in big trouble because none of the tabs will be responsive so let's | 137 // are in big trouble because none of the tabs will be responsive so let's |
| 148 // crash the browser instead. | 138 // crash the browser instead. |
| 149 LOG(FATAL) << "Unable to thaw renderers."; | 139 LOG(FATAL) << "Unable to thaw renderers."; |
| 150 } | 140 } |
| 151 | 141 |
| 152 void RendererFreezer::OnScreenLockStateChanged(chromeos::ScreenLocker* locker, | 142 void RendererFreezer::OnScreenLockStateChanged(chromeos::ScreenLocker* locker, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 rph->AddObserver(this); | 200 rph->AddObserver(this); |
| 211 return; | 201 return; |
| 212 } | 202 } |
| 213 | 203 |
| 214 // We didn't find an extension in this RenderProcessHost that is using GCM so | 204 // We didn't find an extension in this RenderProcessHost that is using GCM so |
| 215 // we can go ahead and freeze it on suspend. | 205 // we can go ahead and freeze it on suspend. |
| 216 delegate_->SetShouldFreezeRenderer(rph->GetHandle(), true); | 206 delegate_->SetShouldFreezeRenderer(rph->GetHandle(), true); |
| 217 } | 207 } |
| 218 | 208 |
| 219 } // namespace chromeos | 209 } // namespace chromeos |
| OLD | NEW |