Chromium Code Reviews| Index: chrome/renderer/extensions/callback_map.h |
| diff --git a/chrome/renderer/extensions/callback_map.h b/chrome/renderer/extensions/callback_map.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..923bc85e743731a4a4453263c43bd7275f72b440 |
| --- /dev/null |
| +++ b/chrome/renderer/extensions/callback_map.h |
| @@ -0,0 +1,43 @@ |
| +// 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_EXTENSIONS_CALLBACK_MAP_H_ |
| +#define CHROME_RENDERER_EXTENSIONS_CALLBACK_MAP_H_ |
| +#pragma once |
| + |
| +#include <map> |
| + |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "v8/include/v8.h" |
| + |
| +namespace extensions_v8_util { |
|
Aaron Boodman
2011/10/03 22:07:43
This isn't specific to extensions - can you just p
asargent_no_longer_on_chrome
2011/10/04 00:43:20
Done.
|
| + |
| +// Callback functions are kept track of in maps keyed by an integer. Values are |
| +// weak references to functions. Entries are automatically removed when |
| +// functions get garbage collected. |
| +class CallbackMap { |
| + public: |
| + CallbackMap(); |
| + ~CallbackMap(); |
| + |
| + // 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<CallbackMap> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CallbackMap); |
| +}; |
| + |
| +} // namespace extensions_v8_util |
| + |
| +#endif // CHROME_RENDERER_EXTENSIONS_CALLBACK_MAP_H_ |