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 #ifndef EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ | 5 #ifndef EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ |
6 #define EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ | 6 #define EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ |
7 | 7 |
8 #include <vector> | 8 #include "base/callback.h" |
9 | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/memory/linked_ptr.h" | |
11 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
12 #include "extensions/common/mojo/stash.mojom.h" | 11 #include "extensions/common/mojo/stash.mojom.h" |
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" | 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
14 | 13 |
15 namespace extensions { | 14 namespace extensions { |
16 | 15 |
17 // A backend that provides access to StashService for a single extension. | 16 // A backend that provides access to StashService for a single extension. |
18 class StashBackend { | 17 class StashBackend { |
19 public: | 18 public: |
20 StashBackend(); | 19 explicit StashBackend(const base::Closure& on_handle_readable); |
21 ~StashBackend(); | 20 ~StashBackend(); |
22 | 21 |
23 // Creates a StashService that forwards calls to this StashBackend and bind it | 22 // Creates a StashService that forwards calls to this StashBackend and bind it |
24 // to |request|. | 23 // to |request|. |
25 void BindToRequest(mojo::InterfaceRequest<StashService> request); | 24 void BindToRequest(mojo::InterfaceRequest<StashService> request); |
26 | 25 |
27 // Adds the StashedObjects contained within |stash| to the stash. | 26 // Adds the StashedObjects contained within |stash| to the stash. |
28 void AddToStash(mojo::Array<StashedObjectPtr> stash); | 27 void AddToStash(mojo::Array<StashedObjectPtr> stash); |
29 | 28 |
30 // Returns all StashedObjects added to the stash since the last call to | 29 // Returns all StashedObjects added to the stash since the last call to |
31 // RetrieveStash. | 30 // RetrieveStash. |
32 mojo::Array<StashedObjectPtr> RetrieveStash(); | 31 mojo::Array<StashedObjectPtr> RetrieveStash(); |
33 | 32 |
34 private: | 33 private: |
| 34 class StashEntry; |
| 35 |
| 36 // Invoked when a handle is readable. |
| 37 void OnHandleReady(); |
| 38 |
35 // The objects that have been stashed. | 39 // The objects that have been stashed. |
36 mojo::Array<StashedObjectPtr> stashed_objects_; | 40 ScopedVector<StashEntry> stashed_objects_; |
| 41 |
| 42 // The callback to call when a handle is readable. |
| 43 const base::Closure on_handle_readable_; |
| 44 |
| 45 // Whether a handle has become readable since the last RetrieveStash() call. |
| 46 bool has_notified_; |
37 | 47 |
38 base::WeakPtrFactory<StashBackend> weak_factory_; | 48 base::WeakPtrFactory<StashBackend> weak_factory_; |
39 | 49 |
40 DISALLOW_COPY_AND_ASSIGN(StashBackend); | 50 DISALLOW_COPY_AND_ASSIGN(StashBackend); |
41 }; | 51 }; |
42 | 52 |
43 } // namespace extensions | 53 } // namespace extensions |
44 | 54 |
45 #endif // EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ | 55 #endif // EXTENSIONS_BROWSER_MOJO_STASH_BACKEND_H_ |
OLD | NEW |