Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #ifndef CHROME_RENDERER_EXTENSIONS_CALLBACK_MAP_H_ | |
| 6 #define CHROME_RENDERER_EXTENSIONS_CALLBACK_MAP_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "v8/include/v8.h" | |
| 14 | |
| 15 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.
| |
| 16 | |
| 17 // Callback functions are kept track of in maps keyed by an integer. Values are | |
| 18 // weak references to functions. Entries are automatically removed when | |
| 19 // functions get garbage collected. | |
| 20 class CallbackMap { | |
| 21 public: | |
| 22 CallbackMap(); | |
| 23 ~CallbackMap(); | |
| 24 | |
| 25 // Adds |callback_function| to the map under |key|. The entry will be removed | |
| 26 // from the map when the function is about to be GCed. | |
| 27 void Add(int key, v8::Local<v8::Function> callback_function); | |
| 28 | |
| 29 // Removes and returns a entry from the map for |key|. If there was no entry | |
| 30 // for |key|, the return value will return true for IsEmpty(). | |
| 31 v8::Persistent<v8::Function> Remove(int key); | |
| 32 | |
| 33 private: | |
| 34 typedef std::map<int, v8::Persistent<v8::Function> > Map; | |
| 35 Map map_; | |
| 36 base::WeakPtrFactory<CallbackMap> weak_ptr_factory_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(CallbackMap); | |
| 39 }; | |
| 40 | |
| 41 } // namespace extensions_v8_util | |
| 42 | |
| 43 #endif // CHROME_RENDERER_EXTENSIONS_CALLBACK_MAP_H_ | |
| OLD | NEW |