• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #include "config.h"
29 #include "OriginQuotaManager.h"
30 
31 #include "Database.h"
32 #include "OriginUsageRecord.h"
33 
34 namespace WebCore {
35 
OriginQuotaManager()36 OriginQuotaManager::OriginQuotaManager()
37 #ifndef NDEBUG
38     : m_usageRecordGuardLocked(false)
39 #endif
40 {
41 }
42 
lock()43 void OriginQuotaManager::lock()
44 {
45     m_usageRecordGuard.lock();
46 #ifndef NDEBUG
47     m_usageRecordGuardLocked = true;
48 #endif
49 }
50 
unlock()51 void OriginQuotaManager::unlock()
52 {
53 #ifndef NDEBUG
54     m_usageRecordGuardLocked = false;
55 #endif
56     m_usageRecordGuard.unlock();
57 }
58 
trackOrigin(PassRefPtr<SecurityOrigin> origin)59 void OriginQuotaManager::trackOrigin(PassRefPtr<SecurityOrigin> origin)
60 {
61     ASSERT(m_usageRecordGuardLocked);
62     ASSERT(!m_usageMap.contains(origin.get()));
63 
64     m_usageMap.set(origin, new OriginUsageRecord);
65 }
66 
tracksOrigin(SecurityOrigin * origin) const67 bool OriginQuotaManager::tracksOrigin(SecurityOrigin* origin) const
68 {
69     ASSERT(m_usageRecordGuardLocked);
70     return m_usageMap.contains(origin);
71 }
72 
addDatabase(SecurityOrigin * origin,const String & databaseIdentifier,const String & fullPath)73 void OriginQuotaManager::addDatabase(SecurityOrigin* origin, const String& databaseIdentifier, const String& fullPath)
74 {
75     ASSERT(m_usageRecordGuardLocked);
76 
77     OriginUsageRecord* usageRecord = m_usageMap.get(origin);
78     ASSERT(usageRecord);
79 
80     usageRecord->addDatabase(databaseIdentifier.copy(), fullPath.copy());
81 }
82 
removeDatabase(SecurityOrigin * origin,const String & databaseIdentifier)83 void OriginQuotaManager::removeDatabase(SecurityOrigin* origin, const String& databaseIdentifier)
84 {
85     ASSERT(m_usageRecordGuardLocked);
86 
87     if (OriginUsageRecord* usageRecord = m_usageMap.get(origin))
88         usageRecord->removeDatabase(databaseIdentifier);
89 }
90 
removeOrigin(SecurityOrigin * origin)91 void OriginQuotaManager::removeOrigin(SecurityOrigin* origin)
92 {
93     ASSERT(m_usageRecordGuardLocked);
94 
95     if (OriginUsageRecord* usageRecord = m_usageMap.get(origin)) {
96         m_usageMap.remove(origin);
97         delete usageRecord;
98     }
99 }
100 
markDatabase(Database * database)101 void OriginQuotaManager::markDatabase(Database* database)
102 {
103     ASSERT(database);
104     ASSERT(m_usageRecordGuardLocked);
105     RefPtr<SecurityOrigin> origin = database->securityOriginCopy();
106     OriginUsageRecord* usageRecord = m_usageMap.get(origin);
107     ASSERT(usageRecord);
108 
109     usageRecord->markDatabase(database->stringIdentifier());
110 }
111 
diskUsage(SecurityOrigin * origin) const112 unsigned long long OriginQuotaManager::diskUsage(SecurityOrigin* origin) const
113 {
114     ASSERT(m_usageRecordGuardLocked);
115 
116     OriginUsageRecord* usageRecord = m_usageMap.get(origin);
117     ASSERT(usageRecord);
118 
119     return usageRecord->diskUsage();
120 }
121 
122 
123 }
124