Chromium Code Reviews| 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" |
| 10 #include "wtf/MainThread.h" | 11 #include "wtf/MainThread.h" |
| 12 #include "wtf/text/StringHash.h" | |
| 11 | 13 |
| 12 namespace WebCore { | 14 namespace WebCore { |
| 13 | 15 |
| 14 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; | |
| 15 | 18 |
| 16 static DOMActivityLoggerMap& domActivityLoggers() | 19 static DOMActivityLoggerMapForMainWorld& domActivityLoggersForMainWorld() |
| 17 { | 20 { |
| 18 ASSERT(isMainThread()); | 21 ASSERT(isMainThread()); |
| 19 DEFINE_STATIC_LOCAL(DOMActivityLoggerMap, map, ()); | 22 DEFINE_STATIC_LOCAL(DOMActivityLoggerMapForMainWorld, map, ()); |
| 20 return map; | 23 return map; |
| 21 } | 24 } |
| 22 | 25 |
| 23 void V8DOMActivityLogger::setActivityLogger(int worldId, PassOwnPtr<V8DOMActivit yLogger> logger) | 26 static DOMActivityLoggerMapForIsolatedWorld& domActivityLoggersForIsolatedWorld( ) |
| 24 { | 27 { |
| 25 domActivityLoggers().set(worldId, logger); | 28 ASSERT(isMainThread()); |
| 29 DEFINE_STATIC_LOCAL(DOMActivityLoggerMapForIsolatedWorld, map, ()); | |
| 30 return map; | |
| 26 } | 31 } |
| 27 | 32 |
| 28 V8DOMActivityLogger* V8DOMActivityLogger::activityLogger(int worldId) | 33 void V8DOMActivityLogger::setActivityLogger(int worldId, const String& extension Id, PassOwnPtr<V8DOMActivityLogger> logger) |
| 29 { | 34 { |
| 30 DOMActivityLoggerMap& loggers = domActivityLoggers(); | 35 if (worldId) { |
| 31 DOMActivityLoggerMap::iterator it = loggers.find(worldId); | 36 domActivityLoggersForIsolatedWorld().set(worldId, logger); |
| 37 } else { | |
| 38 ASSERT(!extensionId.isEmpty()); | |
| 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(); | |
|
mvrable
2014/04/29 20:15:32
I would have used NULL rather than 0. However, is
pmarch
2014/05/07 15:28:24
Blink follows C++ style of null pointers, so using
| |
| 49 } | |
| 50 | |
| 51 if (extensionId.isEmpty()) | |
| 52 return 0; | |
| 53 DOMActivityLoggerMapForMainWorld& loggers = domActivityLoggersForMainWorld() ; | |
| 54 DOMActivityLoggerMapForMainWorld::iterator it = loggers.find(extensionId); | |
| 32 return it == loggers.end() ? 0 : it->value.get(); | 55 return it == loggers.end() ? 0 : it->value.get(); |
| 33 } | 56 } |
| 34 | 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 | |
| 35 } // namespace WebCore | 73 } // namespace WebCore |
| OLD | NEW |