1/* 2 * Copyright (C) 2013 University of Washington. All rights reserved. 3 * Copyright (C) 2014 Apple 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 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 18 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "config.h" 29#include "ReplaySession.h" 30 31#if ENABLE(WEB_REPLAY) 32 33#include "ReplaySessionSegment.h" 34#include <wtf/CurrentTime.h> 35 36namespace WebCore { 37 38static unsigned s_nextIdentifier = 1; 39 40PassRefPtr<ReplaySession> ReplaySession::create() 41{ 42 return adoptRef(new ReplaySession()); 43} 44 45ReplaySession::ReplaySession() 46 : m_identifier(s_nextIdentifier++) 47 , m_timestamp(currentTimeMS()) 48{ 49} 50 51ReplaySession::~ReplaySession() 52{ 53} 54 55PassRefPtr<ReplaySessionSegment> ReplaySession::at(size_t position) const 56{ 57 return m_segments.at(position); 58} 59 60void ReplaySession::appendSegment(PassRefPtr<ReplaySessionSegment> prpSegment) 61{ 62 RefPtr<ReplaySessionSegment> segment = prpSegment; 63 64 // For now, only support one segment. 65 ASSERT(!m_segments.size()); 66 67 // Since replay locations are specified with segment IDs, we can only 68 // have one instance of a segment in the session. 69 size_t offset = m_segments.find(segment); 70 ASSERT_UNUSED(offset, offset == notFound); 71 72 m_segments.append(segment.release()); 73} 74 75void ReplaySession::insertSegment(size_t position, PassRefPtr<ReplaySessionSegment> segment) 76{ 77 ASSERT(position < m_segments.size()); 78 m_segments.insert(position, segment); 79} 80 81void ReplaySession::removeSegment(size_t position) 82{ 83 ASSERT(position < m_segments.size()); 84 m_segments.remove(position); 85} 86 87}; // namespace WebCore 88 89#endif // ENABLE(WEB_REPLAY) 90