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

Side by Side Diff: services/resource_coordinator/coordination_unit/coordination_unit_impl.cc

Issue 2925123002: NOCOMMIT PROTOTYPE [GRC] Tab CPU Usage Observer (Closed)
Patch Set: Rebase Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "services/resource_coordinator/coordination_unit/coordination_unit_impl .h" 5 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl .h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "services/resource_coordinator/public/cpp/coordination_unit_id.h" 13 #include "services/resource_coordinator/public/cpp/coordination_unit_id.h"
14 14
15 namespace resource_coordinator { 15 namespace resource_coordinator {
16 16
17 namespace { 17 namespace {
18 18
19 using CUIDMap = std::unordered_map<CoordinationUnitID, CoordinationUnitImpl*>; 19 using CUIDMap = std::unordered_map<CoordinationUnitID, CoordinationUnitImpl*>;
20 20
21 CUIDMap& g_cu_map() { 21 CUIDMap& g_cu_map() {
22 static CUIDMap* instance = new CUIDMap(); 22 static CUIDMap* instance = new CUIDMap();
23 return *instance; 23 return *instance;
24 } 24 }
25 25
26 } // namespace 26 } // namespace
27 27
28 const double CoordinationUnitImpl::kCPUUsageMinimumForTesting = 0.0;
29 const double CoordinationUnitImpl::kCPUUsageUnmeasuredForTesting = -1.0;
30
31 CoordinationUnitImpl::CoordinationUnitImpl( 28 CoordinationUnitImpl::CoordinationUnitImpl(
32 const CoordinationUnitID& id, 29 const CoordinationUnitID& id,
33 std::unique_ptr<service_manager::ServiceContextRef> service_ref) 30 std::unique_ptr<service_manager::ServiceContextRef> service_ref)
34 : id_(id.type, id.id) { 31 : id_(id.type, id.id) {
35 auto it = g_cu_map().insert(std::make_pair(id_, this)); 32 auto it = g_cu_map().insert(std::make_pair(id_, this));
36 DCHECK(it.second); // Inserted successfully 33 DCHECK(it.second); // Inserted successfully
37 34
38 service_ref_ = std::move(service_ref); 35 service_ref_ = std::move(service_ref);
39 } 36 }
40 37
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 policy_callback_ = std::move(callback); 255 policy_callback_ = std::move(callback);
259 256
260 RecalcCoordinationPolicy(); 257 RecalcCoordinationPolicy();
261 } 258 }
262 259
263 void CoordinationUnitImpl::UnregisterCoordinationPolicyCallback() { 260 void CoordinationUnitImpl::UnregisterCoordinationPolicyCallback() {
264 policy_callback_.reset(); 261 policy_callback_.reset();
265 current_policy_.reset(); 262 current_policy_.reset();
266 } 263 }
267 264
268 double CoordinationUnitImpl::GetCPUUsageForTesting() {
269 return kCPUUsageUnmeasuredForTesting;
270 }
271
272 base::Value CoordinationUnitImpl::GetProperty( 265 base::Value CoordinationUnitImpl::GetProperty(
273 mojom::PropertyType property) const { 266 mojom::PropertyType property) const {
274 auto value_it = property_store_.find(property); 267 auto value_it = property_store_.find(property);
275 268
276 return value_it != property_store_.end() ? value_it->second : base::Value(); 269 return value_it != property_store_.end() ? value_it->second : base::Value();
277 } 270 }
278 271
279 void CoordinationUnitImpl::ClearProperty(mojom::PropertyType property) { 272 void CoordinationUnitImpl::ClearProperty(mojom::PropertyType property) {
280 property_store_.erase(property); 273 property_store_.erase(property);
281 } 274 }
(...skipping 20 matching lines...) Expand all
302 } 295 }
303 296
304 void CoordinationUnitImpl::WillBeDestroyed() { 297 void CoordinationUnitImpl::WillBeDestroyed() {
305 for (auto listener : 298 for (auto listener :
306 on_will_be_destroyed_event_listeners_.GetListenersWithoutAFilter()) { 299 on_will_be_destroyed_event_listeners_.GetListenersWithoutAFilter()) {
307 listener.Run(this); 300 listener.Run(this);
308 } 301 }
309 } 302 }
310 303
311 } // namespace resource_coordinator 304 } // namespace resource_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698