Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / persistent_object_store.py
blob0feb6d81beb56e9a926433ebc30ae48f0a54142c
1 # Copyright 2013 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 from appengine_wrappers import db
6 from datastore_models import PersistentObjectStoreItem
7 from environment import IsDevServer
8 from future import Future
9 from object_store import ObjectStore
12 class PersistentObjectStore(ObjectStore):
13 '''Stores data persistently using the AppEngine Datastore API.
14 '''
15 def __init__(self, namespace):
16 self._namespace = namespace
18 def SetMulti(self, mapping):
19 futures = []
20 for key, value in mapping.items():
21 futures.append(db.put_async(
22 PersistentObjectStoreItem.CreateItem(self._namespace, key, value)))
23 # If running the dev server, the futures don't complete until the server is
24 # *quitting*. This is annoying. Flush now.
25 if IsDevServer():
26 [future.wait() for future in futures]
28 def GetMulti(self, keys):
29 db_futures = dict(
30 (k, db.get_async(
31 PersistentObjectStoreItem.CreateKey(self._namespace, k)))
32 for k in keys)
33 def resolve():
34 return dict((key, future.get_result().GetValue())
35 for key, future in db_futures.iteritems()
36 if future.get_result() is not None)
37 return Future(callback=resolve)
39 def DelMulti(self, keys):
40 futures = []
41 for key in keys:
42 futures.append(db.delete_async(
43 PersistentObjectStoreItem.CreateKey(self._namespace, key)))
44 # If running the dev server, the futures don't complete until the server is
45 # *quitting*. This is annoying. Flush now.
46 if IsDevServer():
47 [future.wait() for future in futures]