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 "extensions/browser/mojo/stash_backend.h" | 5 #include "extensions/browser/mojo/stash_backend.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
16 #include "mojo/public/cpp/system/watcher.h" | 16 #include "mojo/public/cpp/system/watcher.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 namespace { | 19 namespace { |
20 | 20 |
21 // An implementation of StashService that forwards calls to a StashBackend. | 21 // An implementation of StashService that forwards calls to a StashBackend. |
22 class StashServiceImpl : public StashService { | 22 class StashServiceImpl : public StashService { |
23 public: | 23 public: |
24 StashServiceImpl(mojo::InterfaceRequest<StashService> request, | 24 StashServiceImpl(mojo::InterfaceRequest<StashService> request, |
25 base::WeakPtr<StashBackend> backend); | 25 base::WeakPtr<StashBackend> backend); |
26 ~StashServiceImpl() override; | 26 ~StashServiceImpl() override; |
27 | 27 |
28 // StashService overrides. | 28 // StashService overrides. |
29 void AddToStash(mojo::Array<StashedObjectPtr> stash) override; | 29 void AddToStash(mojo::Array<StashedObjectPtr> stash) override; |
30 void RetrieveStash(const RetrieveStashCallback& callback) override; | 30 void RetrieveStash( |
| 31 const mojo::Callback<void(mojo::Array<StashedObjectPtr> stash)>& callback) |
| 32 override; |
31 | 33 |
32 private: | 34 private: |
33 mojo::StrongBinding<StashService> binding_; | 35 mojo::StrongBinding<StashService> binding_; |
34 base::WeakPtr<StashBackend> backend_; | 36 base::WeakPtr<StashBackend> backend_; |
35 | 37 |
36 DISALLOW_COPY_AND_ASSIGN(StashServiceImpl); | 38 DISALLOW_COPY_AND_ASSIGN(StashServiceImpl); |
37 }; | 39 }; |
38 | 40 |
39 StashServiceImpl::StashServiceImpl(mojo::InterfaceRequest<StashService> request, | 41 StashServiceImpl::StashServiceImpl(mojo::InterfaceRequest<StashService> request, |
40 base::WeakPtr<StashBackend> backend) | 42 base::WeakPtr<StashBackend> backend) |
41 : binding_(this, std::move(request)), backend_(backend) {} | 43 : binding_(this, std::move(request)), backend_(backend) {} |
42 | 44 |
43 StashServiceImpl::~StashServiceImpl() { | 45 StashServiceImpl::~StashServiceImpl() { |
44 } | 46 } |
45 | 47 |
46 void StashServiceImpl::AddToStash( | 48 void StashServiceImpl::AddToStash( |
47 mojo::Array<StashedObjectPtr> stashed_objects) { | 49 mojo::Array<StashedObjectPtr> stashed_objects) { |
48 if (!backend_) | 50 if (!backend_) |
49 return; | 51 return; |
50 backend_->AddToStash(std::move(stashed_objects)); | 52 backend_->AddToStash(std::move(stashed_objects)); |
51 } | 53 } |
52 | 54 |
53 void StashServiceImpl::RetrieveStash(const RetrieveStashCallback& callback) { | 55 void StashServiceImpl::RetrieveStash( |
| 56 const mojo::Callback<void(mojo::Array<StashedObjectPtr>)>& callback) { |
54 if (!backend_) { | 57 if (!backend_) { |
55 callback.Run(mojo::Array<StashedObjectPtr>()); | 58 callback.Run(mojo::Array<StashedObjectPtr>()); |
56 return; | 59 return; |
57 } | 60 } |
58 callback.Run(backend_->RetrieveStash()); | 61 callback.Run(backend_->RetrieveStash()); |
59 } | 62 } |
60 | 63 |
61 } // namespace | 64 } // namespace |
62 | 65 |
63 // A stash entry for a stashed object. This handles notifications if a handle | 66 // A stash entry for a stashed object. This handles notifications if a handle |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 waiters_.clear(); | 166 waiters_.clear(); |
164 } | 167 } |
165 | 168 |
166 void StashBackend::StashEntry::OnHandleReady(MojoResult result) { | 169 void StashBackend::StashEntry::OnHandleReady(MojoResult result) { |
167 if (result != MOJO_RESULT_OK) | 170 if (result != MOJO_RESULT_OK) |
168 return; | 171 return; |
169 on_handle_readable_.Run(); | 172 on_handle_readable_.Run(); |
170 } | 173 } |
171 | 174 |
172 } // namespace extensions | 175 } // namespace extensions |
OLD | NEW |