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