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 ASSERT(!extensionId.isEmpty()); | |
Jeffrey Yasskin
2014/05/08 00:17:34
This creates an intermediate state where any activ
pmarch
2014/05/08 01:14:05
Done.
| |
39 domActivityLoggersForMainWorld().set(extensionId, logger); | |
40 } | |
41 } | |
42 | |
43 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId, const Stri ng& extensionId) | |
44 { | |
45 if (worldId) { | |
46 DOMActivityLoggerMapForIsolatedWorld& loggers = domActivityLoggersForIso latedWorld(); | |
47 DOMActivityLoggerMapForIsolatedWorld::iterator it = loggers.find(worldId ); | |
48 return it == loggers.end() ? 0 : it->value.get(); | |
49 } | |
50 | |
51 if (extensionId.isEmpty()) | |
52 return 0; | |
53 DOMActivityLoggerMapForMainWorld& loggers = domActivityLoggersForMainWorld() ; | |
54 DOMActivityLoggerMapForMainWorld::iterator it = loggers.find(extensionId); | |
31 return it == loggers.end() ? 0 : it->value.get(); | 55 return it == loggers.end() ? 0 : it->value.get(); |
32 } | 56 } |
33 | 57 |
58 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId, const KURL & url) | |
59 { | |
60 // extension ID is ignored for worldId != 0. | |
61 if (worldId) | |
62 return activityLogger(worldId, String()); | |
63 | |
64 // To find an activity logger that corresponds to the main world of an | |
65 // extension, we need to obtain the extension ID. Extension ID is a hostname | |
66 // of a background page's URL. | |
67 if (!url.protocolIs("chrome-extension")) | |
68 return 0; | |
69 | |
70 return activityLogger(worldId, url.host()); | |
71 } | |
72 | |
34 } // namespace WebCore | 73 } // namespace WebCore |
OLD | NEW |