OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extension_event_observer.h" | 5 #include "chrome/browser/chromeos/power/extension_event_observer.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/extensions/api/gcm.h" | 15 #include "chrome/common/extensions/api/gcm.h" |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
15 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
16 #include "extensions/browser/extension_host.h" | 18 #include "extensions/browser/extension_host.h" |
17 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
18 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
19 #include "extensions/common/manifest_handlers/background_info.h" | 21 #include "extensions/common/manifest_handlers/background_info.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 79 |
78 for (const auto& pair : keepalive_sources_) { | 80 for (const auto& pair : keepalive_sources_) { |
79 extensions::ExtensionHost* host = | 81 extensions::ExtensionHost* host = |
80 const_cast<extensions::ExtensionHost*>(pair.first); | 82 const_cast<extensions::ExtensionHost*>(pair.first); |
81 host->RemoveObserver(this); | 83 host->RemoveObserver(this); |
82 } | 84 } |
83 | 85 |
84 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 86 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
85 } | 87 } |
86 | 88 |
87 scoped_ptr<ExtensionEventObserver::TestApi> | 89 std::unique_ptr<ExtensionEventObserver::TestApi> |
88 ExtensionEventObserver::CreateTestApi() { | 90 ExtensionEventObserver::CreateTestApi() { |
89 return make_scoped_ptr( | 91 return base::WrapUnique( |
90 new ExtensionEventObserver::TestApi(weak_factory_.GetWeakPtr())); | 92 new ExtensionEventObserver::TestApi(weak_factory_.GetWeakPtr())); |
91 } | 93 } |
92 | 94 |
93 void ExtensionEventObserver::SetShouldDelaySuspend(bool should_delay) { | 95 void ExtensionEventObserver::SetShouldDelaySuspend(bool should_delay) { |
94 should_delay_suspend_ = should_delay; | 96 should_delay_suspend_ = should_delay; |
95 if (!should_delay_suspend_ && suspend_is_pending_) { | 97 if (!should_delay_suspend_ && suspend_is_pending_) { |
96 // There is a suspend attempt pending but this class should no longer be | 98 // There is a suspend attempt pending but this class should no longer be |
97 // delaying it. Immediately report readiness. | 99 // delaying it. Immediately report readiness. |
98 suspend_is_pending_ = false; | 100 suspend_is_pending_ = false; |
99 power_manager_callback_.Run(); | 101 power_manager_callback_.Run(); |
(...skipping 23 matching lines...) Expand all Loading... |
123 void ExtensionEventObserver::OnBackgroundHostCreated( | 125 void ExtensionEventObserver::OnBackgroundHostCreated( |
124 extensions::ExtensionHost* host) { | 126 extensions::ExtensionHost* host) { |
125 // We only care about ExtensionHosts for extensions that use GCM and have a | 127 // We only care about ExtensionHosts for extensions that use GCM and have a |
126 // lazy background page. | 128 // lazy background page. |
127 if (!host->extension()->permissions_data()->HasAPIPermission( | 129 if (!host->extension()->permissions_data()->HasAPIPermission( |
128 extensions::APIPermission::kGcm) || | 130 extensions::APIPermission::kGcm) || |
129 !extensions::BackgroundInfo::HasLazyBackgroundPage(host->extension())) | 131 !extensions::BackgroundInfo::HasLazyBackgroundPage(host->extension())) |
130 return; | 132 return; |
131 | 133 |
132 auto result = | 134 auto result = |
133 keepalive_sources_.add(host, make_scoped_ptr(new KeepaliveSources())); | 135 keepalive_sources_.add(host, base::WrapUnique(new KeepaliveSources())); |
134 | 136 |
135 if (result.second) | 137 if (result.second) |
136 host->AddObserver(this); | 138 host->AddObserver(this); |
137 } | 139 } |
138 | 140 |
139 void ExtensionEventObserver::OnExtensionHostDestroyed( | 141 void ExtensionEventObserver::OnExtensionHostDestroyed( |
140 const extensions::ExtensionHost* host) { | 142 const extensions::ExtensionHost* host) { |
141 DCHECK(keepalive_sources_.contains(host)); | 143 DCHECK(keepalive_sources_.contains(host)); |
142 | 144 |
143 scoped_ptr<KeepaliveSources> sources = | 145 std::unique_ptr<KeepaliveSources> sources = |
144 keepalive_sources_.take_and_erase(host); | 146 keepalive_sources_.take_and_erase(host); |
145 | 147 |
146 suspend_keepalive_count_ -= sources->unacked_push_messages.size(); | 148 suspend_keepalive_count_ -= sources->unacked_push_messages.size(); |
147 suspend_keepalive_count_ -= sources->pending_network_requests.size(); | 149 suspend_keepalive_count_ -= sources->pending_network_requests.size(); |
148 MaybeReportSuspendReadiness(); | 150 MaybeReportSuspendReadiness(); |
149 } | 151 } |
150 | 152 |
151 void ExtensionEventObserver::OnBackgroundEventDispatched( | 153 void ExtensionEventObserver::OnBackgroundEventDispatched( |
152 const extensions::ExtensionHost* host, | 154 const extensions::ExtensionHost* host, |
153 const std::string& event_name, | 155 const std::string& event_name, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 if (!suspend_is_pending_ || suspend_keepalive_count_ > 0 || | 265 if (!suspend_is_pending_ || suspend_keepalive_count_ > 0 || |
264 power_manager_callback_.is_null()) | 266 power_manager_callback_.is_null()) |
265 return; | 267 return; |
266 | 268 |
267 suspend_is_pending_ = false; | 269 suspend_is_pending_ = false; |
268 power_manager_callback_.Run(); | 270 power_manager_callback_.Run(); |
269 power_manager_callback_.Reset(); | 271 power_manager_callback_.Reset(); |
270 } | 272 } |
271 | 273 |
272 } // namespace chromeos | 274 } // namespace chromeos |
OLD | NEW |