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

Side by Side Diff: components/memory_coordinator/browser/memory_coordinator.cc

Issue 2094583002: Add MemoryCoordinator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create handle per child Created 4 years, 5 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/memory_coordinator/browser/memory_coordinator.h"
6
7 namespace memory_coordinator {
8
9 // The implementation of MemoryCoordinatorHandle. See memory_coordinator.mojom
10 // for the role of this class.
11 class MemoryCoordinatorHandleImpl : public mojom::MemoryCoordinatorHandle {
12 public:
13 MemoryCoordinatorHandleImpl(mojom::MemoryCoordinatorHandleRequest request)
14 : binding_(this, std::move(request)) {
15 }
16
17 // mojom::MemoryCoordinatorHandle implementations:
18
19 void AddChild(mojom::ChildMemoryCoordinatorPtr child) override {
20 DCHECK(!child_.is_bound());
21 child_ = std::move(child);
22 }
23
24 mojom::ChildMemoryCoordinatorPtr& child() { return child_; }
25 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; }
26
27 private:
28 mojom::ChildMemoryCoordinatorPtr child_;
29 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_;
30
31 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl);
32 };
33
34 MemoryCoordinator::MemoryCoordinator() {}
35
36 MemoryCoordinator::~MemoryCoordinator() {}
37
38 void MemoryCoordinator::CreateHandle(
39 int id,
40 mojom::MemoryCoordinatorHandleRequest request) {
41 auto handle = new MemoryCoordinatorHandleImpl(std::move(request));
42 handle->binding().set_connection_error_handler(base::Bind(
43 &MemoryCoordinator::OnConnectionError, base::Unretained(this), id));
44 children_[id].reset(handle);
45 }
46
47 void MemoryCoordinator::IterateChildrenForTesting(
48 IterateCallback callback) {
49 for (auto& pair : children_) {
50 auto& child = pair.second->child();
51 DCHECK(child.is_bound());
52 callback.Run(child.get());
53 }
54 }
55
56 void MemoryCoordinator::OnConnectionError(int id) {
57 children_.erase(id);
58 }
59
60 } // namespace memory_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698