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( | 30 void RetrieveStash(const RetrieveStashCallback& callback) override; |
31 const mojo::Callback<void(mojo::Array<StashedObjectPtr> stash)>& callback) | |
32 override; | |
33 | 31 |
34 private: | 32 private: |
35 mojo::StrongBinding<StashService> binding_; | 33 mojo::StrongBinding<StashService> binding_; |
36 base::WeakPtr<StashBackend> backend_; | 34 base::WeakPtr<StashBackend> backend_; |
37 | 35 |
38 DISALLOW_COPY_AND_ASSIGN(StashServiceImpl); | 36 DISALLOW_COPY_AND_ASSIGN(StashServiceImpl); |
39 }; | 37 }; |
40 | 38 |
41 StashServiceImpl::StashServiceImpl(mojo::InterfaceRequest<StashService> request, | 39 StashServiceImpl::StashServiceImpl(mojo::InterfaceRequest<StashService> request, |
42 base::WeakPtr<StashBackend> backend) | 40 base::WeakPtr<StashBackend> backend) |
43 : binding_(this, std::move(request)), backend_(backend) {} | 41 : binding_(this, std::move(request)), backend_(backend) {} |
44 | 42 |
45 StashServiceImpl::~StashServiceImpl() { | 43 StashServiceImpl::~StashServiceImpl() { |
46 } | 44 } |
47 | 45 |
48 void StashServiceImpl::AddToStash( | 46 void StashServiceImpl::AddToStash( |
49 mojo::Array<StashedObjectPtr> stashed_objects) { | 47 mojo::Array<StashedObjectPtr> stashed_objects) { |
50 if (!backend_) | 48 if (!backend_) |
51 return; | 49 return; |
52 backend_->AddToStash(std::move(stashed_objects)); | 50 backend_->AddToStash(std::move(stashed_objects)); |
53 } | 51 } |
54 | 52 |
55 void StashServiceImpl::RetrieveStash( | 53 void StashServiceImpl::RetrieveStash(const RetrieveStashCallback& callback) { |
56 const mojo::Callback<void(mojo::Array<StashedObjectPtr>)>& callback) { | |
57 if (!backend_) { | 54 if (!backend_) { |
58 callback.Run(mojo::Array<StashedObjectPtr>()); | 55 callback.Run(mojo::Array<StashedObjectPtr>()); |
59 return; | 56 return; |
60 } | 57 } |
61 callback.Run(backend_->RetrieveStash()); | 58 callback.Run(backend_->RetrieveStash()); |
62 } | 59 } |
63 | 60 |
64 } // namespace | 61 } // namespace |
65 | 62 |
66 // A stash entry for a stashed object. This handles notifications if a handle | 63 // 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... |
166 waiters_.clear(); | 163 waiters_.clear(); |
167 } | 164 } |
168 | 165 |
169 void StashBackend::StashEntry::OnHandleReady(MojoResult result) { | 166 void StashBackend::StashEntry::OnHandleReady(MojoResult result) { |
170 if (result != MOJO_RESULT_OK) | 167 if (result != MOJO_RESULT_OK) |
171 return; | 168 return; |
172 on_handle_readable_.Run(); | 169 on_handle_readable_.Run(); |
173 } | 170 } |
174 | 171 |
175 } // namespace extensions | 172 } // namespace extensions |
OLD | NEW |