• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  * Copyright (C) 2012 Intel Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef Performance_h
33 #define Performance_h
34 
35 #include "bindings/v8/ScriptWrappable.h"
36 #include "core/events/EventTarget.h"
37 #include "core/frame/DOMWindowProperty.h"
38 #include "core/timing/MemoryInfo.h"
39 #include "core/timing/PerformanceEntry.h"
40 #include "core/timing/PerformanceNavigation.h"
41 #include "core/timing/PerformanceTiming.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefCounted.h"
44 #include "wtf/RefPtr.h"
45 #include "wtf/text/WTFString.h"
46 
47 namespace WebCore {
48 
49 class Document;
50 class ExceptionState;
51 class ResourceRequest;
52 class ResourceResponse;
53 class ResourceTimingInfo;
54 class UserTiming;
55 
56 class Performance : public ScriptWrappable, public RefCounted<Performance>, public DOMWindowProperty, public EventTargetWithInlineData {
57     REFCOUNTED_EVENT_TARGET(Performance);
58 public:
create(Frame * frame)59     static PassRefPtr<Performance> create(Frame* frame) { return adoptRef(new Performance(frame)); }
60     ~Performance();
61 
62     virtual const AtomicString& interfaceName() const OVERRIDE;
63     virtual ExecutionContext* executionContext() const OVERRIDE;
64 
65     PassRefPtr<MemoryInfo> memory() const;
66     PerformanceNavigation* navigation() const;
67     PerformanceTiming* timing() const;
68     double now() const;
69 
70     Vector<RefPtr<PerformanceEntry> > getEntries() const;
71     Vector<RefPtr<PerformanceEntry> > getEntriesByType(const String& entryType);
72     Vector<RefPtr<PerformanceEntry> > getEntriesByName(const String& name, const String& entryType);
73 
74     void webkitClearResourceTimings();
75     void webkitSetResourceTimingBufferSize(unsigned int);
76 
77     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitresourcetimingbufferfull);
78 
79     void addResourceTiming(const ResourceTimingInfo&, Document*);
80 
81     void mark(const String& markName, ExceptionState&);
82     void clearMarks(const String& markName);
83 
84     void measure(const String& measureName, const String& startMark, const String& endMark, ExceptionState&);
85     void clearMeasures(const String& measureName);
86 
87 private:
88     explicit Performance(Frame*);
89 
90     bool isResourceTimingBufferFull();
91     void addResourceTimingBuffer(PassRefPtr<PerformanceEntry>);
92 
93     mutable RefPtr<PerformanceNavigation> m_navigation;
94     mutable RefPtr<PerformanceTiming> m_timing;
95 
96     Vector<RefPtr<PerformanceEntry> > m_resourceTimingBuffer;
97     unsigned m_resourceTimingBufferSize;
98     double m_referenceTime;
99 
100     RefPtr<UserTiming> m_userTiming;
101 };
102 
103 }
104 
105 #endif // Performance_h
106