Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/chromeos/power/extension_event_observer.cc

Issue 1547093002: Switch to standard integer types in chrome/browser/chromeos/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 bool ExtensionEventObserver::TestApi::WillDelaySuspendForExtensionHost( 48 bool ExtensionEventObserver::TestApi::WillDelaySuspendForExtensionHost(
49 extensions::ExtensionHost* host) { 49 extensions::ExtensionHost* host) {
50 if (!parent_) 50 if (!parent_)
51 return false; 51 return false;
52 52
53 return parent_->keepalive_sources_.contains(host); 53 return parent_->keepalive_sources_.contains(host);
54 } 54 }
55 55
56 struct ExtensionEventObserver::KeepaliveSources { 56 struct ExtensionEventObserver::KeepaliveSources {
57 std::set<int> unacked_push_messages; 57 std::set<int> unacked_push_messages;
58 std::set<uint64> pending_network_requests; 58 std::set<uint64_t> pending_network_requests;
59 }; 59 };
60 60
61 ExtensionEventObserver::ExtensionEventObserver() 61 ExtensionEventObserver::ExtensionEventObserver()
62 : should_delay_suspend_(true), 62 : should_delay_suspend_(true),
63 suspend_is_pending_(false), 63 suspend_is_pending_(false),
64 suspend_keepalive_count_(0), 64 suspend_keepalive_count_(0),
65 weak_factory_(this) { 65 weak_factory_(this) {
66 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, 66 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
67 content::NotificationService::AllBrowserContextsAndSources()); 67 content::NotificationService::AllBrowserContextsAndSources());
68 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 68 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 DCHECK(keepalive_sources_.contains(host)); 167 DCHECK(keepalive_sources_.contains(host));
168 168
169 if (keepalive_sources_.get(host)->unacked_push_messages.erase(event_id) > 0) { 169 if (keepalive_sources_.get(host)->unacked_push_messages.erase(event_id) > 0) {
170 --suspend_keepalive_count_; 170 --suspend_keepalive_count_;
171 MaybeReportSuspendReadiness(); 171 MaybeReportSuspendReadiness();
172 } 172 }
173 } 173 }
174 174
175 void ExtensionEventObserver::OnNetworkRequestStarted( 175 void ExtensionEventObserver::OnNetworkRequestStarted(
176 const extensions::ExtensionHost* host, 176 const extensions::ExtensionHost* host,
177 uint64 request_id) { 177 uint64_t request_id) {
178 DCHECK(keepalive_sources_.contains(host)); 178 DCHECK(keepalive_sources_.contains(host));
179 179
180 KeepaliveSources* sources = keepalive_sources_.get(host); 180 KeepaliveSources* sources = keepalive_sources_.get(host);
181 181
182 // We only care about network requests that were started while a push message 182 // We only care about network requests that were started while a push message
183 // is pending. This is an indication that the network request is related to 183 // is pending. This is an indication that the network request is related to
184 // the push message. 184 // the push message.
185 if (sources->unacked_push_messages.empty()) 185 if (sources->unacked_push_messages.empty())
186 return; 186 return;
187 187
188 sources->pending_network_requests.insert(request_id); 188 sources->pending_network_requests.insert(request_id);
189 ++suspend_keepalive_count_; 189 ++suspend_keepalive_count_;
190 } 190 }
191 191
192 void ExtensionEventObserver::OnNetworkRequestDone( 192 void ExtensionEventObserver::OnNetworkRequestDone(
193 const extensions::ExtensionHost* host, 193 const extensions::ExtensionHost* host,
194 uint64 request_id) { 194 uint64_t request_id) {
195 DCHECK(keepalive_sources_.contains(host)); 195 DCHECK(keepalive_sources_.contains(host));
196 196
197 if (keepalive_sources_.get(host)->pending_network_requests.erase(request_id) > 197 if (keepalive_sources_.get(host)->pending_network_requests.erase(request_id) >
198 0) { 198 0) {
199 --suspend_keepalive_count_; 199 --suspend_keepalive_count_;
200 MaybeReportSuspendReadiness(); 200 MaybeReportSuspendReadiness();
201 } 201 }
202 } 202 }
203 203
204 void ExtensionEventObserver::SuspendImminent() { 204 void ExtensionEventObserver::SuspendImminent() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (!suspend_is_pending_ || suspend_keepalive_count_ > 0 || 263 if (!suspend_is_pending_ || suspend_keepalive_count_ > 0 ||
264 power_manager_callback_.is_null()) 264 power_manager_callback_.is_null())
265 return; 265 return;
266 266
267 suspend_is_pending_ = false; 267 suspend_is_pending_ = false;
268 power_manager_callback_.Run(); 268 power_manager_callback_.Run();
269 power_manager_callback_.Reset(); 269 power_manager_callback_.Reset();
270 } 270 }
271 271
272 } // namespace chromeos 272 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698