Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6483)

Unified Diff: chrome/renderer/weak_v8_function_map.h

Issue 8113006: Add js api for hosted/pacakged apps to request notification authorization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, and fixed small nit Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/extension_helper.cc ('k') | chrome/renderer/weak_v8_function_map.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/weak_v8_function_map.h
diff --git a/chrome/renderer/weak_v8_function_map.h b/chrome/renderer/weak_v8_function_map.h
new file mode 100644
index 0000000000000000000000000000000000000000..a51dc9d9824a5e5854044617df780763dbaf6c1c
--- /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_
« no previous file with comments | « chrome/renderer/extensions/extension_helper.cc ('k') | chrome/renderer/weak_v8_function_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698