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