summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/weak_v8_function_map.h
diff options
context:
space:
mode:
authorasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 00:48:58 +0000
committerasargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 00:48:58 +0000
commitde1b7bc3689b13c0894cab567e909b8c8fc33dcb (patch)
tree29ca71514a73e8d08a54f3bf98749d8ee4fb87a6 /chrome/renderer/weak_v8_function_map.h
parentdbd5391a3f7bd716f17f59a0028d002842d54f7b (diff)
downloadchromium_src-de1b7bc3689b13c0894cab567e909b8c8fc33dcb.zip
chromium_src-de1b7bc3689b13c0894cab567e909b8c8fc33dcb.tar.gz
chromium_src-de1b7bc3689b13c0894cab567e909b8c8fc33dcb.tar.bz2
Add js api for hosted/packaged apps to request notification authorization
BUG=98145 TEST=None (more pieces will be landing that will make it testable) Review URL: http://codereview.chromium.org/8113006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104410 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/weak_v8_function_map.h')
-rw-r--r--chrome/renderer/weak_v8_function_map.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome/renderer/weak_v8_function_map.h b/chrome/renderer/weak_v8_function_map.h
new file mode 100644
index 0000000..a51dc9d
--- /dev/null
+++ b/chrome/renderer/weak_v8_function_map.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_WEAK_V8_FUNCTION_MAP_H_
+#define CHROME_RENDERER_WEAK_V8_FUNCTION_MAP_H_
+#pragma once
+
+#include <map>
+
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "v8/include/v8.h"
+
+// This class lets you keep a mapping of integer to weak reference to a v8
+// function. The entry will automatically get removed from the map if the
+// function gets garbage collected.
+class WeakV8FunctionMap {
+ public:
+ WeakV8FunctionMap();
+ ~WeakV8FunctionMap();
+
+ // Adds |callback_function| to the map under |key|. The entry will be removed
+ // from the map when the function is about to be GCed.
+ void Add(int key, v8::Local<v8::Function> callback_function);
+
+ // Removes and returns a entry from the map for |key|. If there was no entry
+ // for |key|, the return value will return true for IsEmpty().
+ v8::Persistent<v8::Function> Remove(int key);
+
+ private:
+ typedef std::map<int, v8::Persistent<v8::Function> > Map;
+ Map map_;
+ base::WeakPtrFactory<WeakV8FunctionMap> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(WeakV8FunctionMap);
+};
+
+#endif // CHROME_RENDERER_WEAK_V8_FUNCTION_MAP_H_