OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "bindings/v8/V8DOMActivityLogger.h" | 6 #include "bindings/v8/V8DOMActivityLogger.h" |
7 | 7 |
8 #include "bindings/v8/V8Binding.h" | 8 #include "bindings/v8/V8Binding.h" |
| 9 #include "platform/weborigin/KURL.h" |
9 #include "wtf/HashMap.h" | 10 #include "wtf/HashMap.h" |
| 11 #include "wtf/MainThread.h" |
| 12 #include "wtf/text/StringHash.h" |
10 | 13 |
11 namespace WebCore { | 14 namespace WebCore { |
12 | 15 |
13 typedef HashMap<int, OwnPtr<V8DOMActivityLogger>, WTF::IntHash<int>, WTF::Unsign
edWithZeroKeyHashTraits<int> > DOMActivityLoggerMap; | 16 typedef HashMap<String, OwnPtr<V8DOMActivityLogger> > DOMActivityLoggerMapForMai
nWorld; |
| 17 typedef HashMap<int, OwnPtr<V8DOMActivityLogger>, WTF::IntHash<int>, WTF::Unsign
edWithZeroKeyHashTraits<int> > DOMActivityLoggerMapForIsolatedWorld; |
14 | 18 |
15 static DOMActivityLoggerMap& domActivityLoggers() | 19 static DOMActivityLoggerMapForMainWorld& domActivityLoggersForMainWorld() |
16 { | 20 { |
17 ASSERT(isMainThread()); | 21 ASSERT(isMainThread()); |
18 DEFINE_STATIC_LOCAL(DOMActivityLoggerMap, map, ()); | 22 DEFINE_STATIC_LOCAL(DOMActivityLoggerMapForMainWorld, map, ()); |
19 return map; | 23 return map; |
20 } | 24 } |
21 | 25 |
22 void V8DOMActivityLogger::setActivityLogger(int worldId, PassOwnPtr<V8DOMActivit
yLogger> logger) | 26 static DOMActivityLoggerMapForIsolatedWorld& domActivityLoggersForIsolatedWorld(
) |
23 { | 27 { |
24 domActivityLoggers().set(worldId, logger); | 28 ASSERT(isMainThread()); |
| 29 DEFINE_STATIC_LOCAL(DOMActivityLoggerMapForIsolatedWorld, map, ()); |
| 30 return map; |
25 } | 31 } |
26 | 32 |
27 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId) | 33 void V8DOMActivityLogger::setActivityLogger(int worldId, const String& extension
Id, PassOwnPtr<V8DOMActivityLogger> logger) |
28 { | 34 { |
29 DOMActivityLoggerMap& loggers = domActivityLoggers(); | 35 if (worldId) { |
30 DOMActivityLoggerMap::iterator it = loggers.find(worldId); | 36 domActivityLoggersForIsolatedWorld().set(worldId, logger); |
| 37 } else { |
| 38 domActivityLoggersForMainWorld().set(extensionId, logger); |
| 39 } |
| 40 } |
| 41 |
| 42 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId, const Stri
ng& extensionId) |
| 43 { |
| 44 if (worldId) { |
| 45 DOMActivityLoggerMapForIsolatedWorld& loggers = domActivityLoggersForIso
latedWorld(); |
| 46 DOMActivityLoggerMapForIsolatedWorld::iterator it = loggers.find(worldId
); |
| 47 return it == loggers.end() ? 0 : it->value.get(); |
| 48 } |
| 49 |
| 50 DOMActivityLoggerMapForMainWorld& loggers = domActivityLoggersForMainWorld()
; |
| 51 DOMActivityLoggerMapForMainWorld::iterator it = loggers.find(extensionId); |
31 return it == loggers.end() ? 0 : it->value.get(); | 52 return it == loggers.end() ? 0 : it->value.get(); |
32 } | 53 } |
33 | 54 |
| 55 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId, const KURL
& url) |
| 56 { |
| 57 // extension ID is ignored for worldId != 0. |
| 58 if (worldId) |
| 59 return activityLogger(worldId, String()); |
| 60 |
| 61 // To find an activity logger that corresponds to the main world of an |
| 62 // extension, we need to obtain the extension ID. Extension ID is a hostname |
| 63 // of a background page's URL. |
| 64 if (!url.protocolIs("chrome-extension")) |
| 65 return 0; |
| 66 |
| 67 return activityLogger(worldId, url.host()); |
| 68 } |
| 69 |
34 } // namespace WebCore | 70 } // namespace WebCore |
OLD | NEW |