Changeset 148161 in webkit


Ignore:
Timestamp:
Apr 10, 2013 6:22:52 PM (11 years ago)
Author:
andersca@apple.com
Message:

Make StorageAreaImpl a wrapper around StorageAreaMap
https://bugs.webkit.org/show_bug.cgi?id=114404

Reviewed by Oliver Hunt.

Prepare for moving all the code that deals with local storage values to StorageAreaMap,
and make StorageAreaImpl a dumb wrapper that simply calls through to the map.

  • WebProcess/Storage/StorageAreaImpl.cpp:

(WebKit::StorageAreaImpl::create):
(WebKit::StorageAreaImpl::StorageAreaImpl):
(WebKit::StorageAreaImpl::~StorageAreaImpl):
(WebKit::StorageAreaImpl::storageType):
(WebKit::StorageAreaImpl::length):
(WebKit::StorageAreaImpl::key):
(WebKit::StorageAreaImpl::getItem):
(WebKit::StorageAreaImpl::setItem):
(WebKit::StorageAreaImpl::contains):

  • WebProcess/Storage/StorageAreaImpl.h:

(WebKit::StorageAreaImpl::storageAreaID):

  • WebProcess/Storage/StorageAreaMap.cpp:

(WebKit::generateStorageMapID):
(WebKit::StorageAreaMap::create):
(WebKit::StorageAreaMap::StorageAreaMap):
(WebKit::StorageAreaMap::storageType):
(WebKit::StorageAreaMap::length):
(WebKit::StorageAreaMap::key):
(WebKit::StorageAreaMap::item):
(WebKit::StorageAreaMap::setItem):
(WebKit::StorageAreaMap::contains):
(WebKit::StorageAreaMap::didSetItem):
(WebKit::StorageAreaMap::dispatchStorageEvent):

  • WebProcess/Storage/StorageAreaMap.h:
  • WebProcess/Storage/StorageNamespaceImpl.cpp:

(WebKit::StorageNamespaceImpl::storageArea):

  • WebProcess/Storage/StorageNamespaceImpl.h:

(StorageNamespaceImpl):

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r148160 r148161  
     12013-04-10  Anders Carlsson  <andersca@apple.com>
     2
     3        Make StorageAreaImpl a wrapper around StorageAreaMap
     4        https://bugs.webkit.org/show_bug.cgi?id=114404
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Prepare for moving all the code that deals with local storage values to StorageAreaMap,
     9        and make StorageAreaImpl a dumb wrapper that simply calls through to the map.
     10
     11        * WebProcess/Storage/StorageAreaImpl.cpp:
     12        (WebKit::StorageAreaImpl::create):
     13        (WebKit::StorageAreaImpl::StorageAreaImpl):
     14        (WebKit::StorageAreaImpl::~StorageAreaImpl):
     15        (WebKit::StorageAreaImpl::storageType):
     16        (WebKit::StorageAreaImpl::length):
     17        (WebKit::StorageAreaImpl::key):
     18        (WebKit::StorageAreaImpl::getItem):
     19        (WebKit::StorageAreaImpl::setItem):
     20        (WebKit::StorageAreaImpl::contains):
     21        * WebProcess/Storage/StorageAreaImpl.h:
     22        (WebKit::StorageAreaImpl::storageAreaID):
     23        * WebProcess/Storage/StorageAreaMap.cpp:
     24        (WebKit::generateStorageMapID):
     25        (WebKit::StorageAreaMap::create):
     26        (WebKit::StorageAreaMap::StorageAreaMap):
     27        (WebKit::StorageAreaMap::storageType):
     28        (WebKit::StorageAreaMap::length):
     29        (WebKit::StorageAreaMap::key):
     30        (WebKit::StorageAreaMap::item):
     31        (WebKit::StorageAreaMap::setItem):
     32        (WebKit::StorageAreaMap::contains):
     33        (WebKit::StorageAreaMap::didSetItem):
     34        (WebKit::StorageAreaMap::dispatchStorageEvent):
     35        * WebProcess/Storage/StorageAreaMap.h:
     36        * WebProcess/Storage/StorageNamespaceImpl.cpp:
     37        (WebKit::StorageNamespaceImpl::storageArea):
     38        * WebProcess/Storage/StorageNamespaceImpl.h:
     39        (StorageNamespaceImpl):
     40
    1412013-04-10  Anders Carlsson  <andersca@apple.com>
    242
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.cpp

    r148160 r148161  
    2727#include "StorageAreaImpl.h"
    2828
    29 #include "SecurityOriginData.h"
    30 #include "StorageAreaMapMessages.h"
    31 #include "StorageManagerMessages.h"
    32 #include "StorageNamespaceImpl.h"
    33 #include "WebProcess.h"
     29#include "StorageAreaMap.h"
    3430#include <WebCore/ExceptionCode.h>
    3531#include <WebCore/Frame.h>
    3632#include <WebCore/Page.h>
    3733#include <WebCore/SchemeRegistry.h>
    38 #include <WebCore/SecurityOrigin.h>
    39 #include <WebCore/StorageMap.h>
     34#include <WebCore/Settings.h>
    4035
    4136using namespace WebCore;
     
    4944}
    5045
    51 PassRefPtr<StorageAreaImpl> StorageAreaImpl::create(StorageNamespaceImpl* StorageNamespaceImpl, PassRefPtr<SecurityOrigin> securityOrigin)
     46PassRefPtr<StorageAreaImpl> StorageAreaImpl::create(PassRefPtr<StorageAreaMap> storageAreaMap)
    5247{
    53     return adoptRef(new StorageAreaImpl(StorageNamespaceImpl, securityOrigin));
     48    return adoptRef(new StorageAreaImpl(storageAreaMap));
    5449}
    5550
    56 StorageAreaImpl::StorageAreaImpl(StorageNamespaceImpl* StorageNamespaceImpl, PassRefPtr<SecurityOrigin> securityOrigin)
    57     : m_storageNamespaceID(StorageNamespaceImpl->storageNamespaceID())
    58     , m_quotaInBytes(StorageNamespaceImpl->quotaInBytes())
    59     , m_storageAreaID(generateStorageAreaID())
    60     , m_securityOrigin(securityOrigin)
     51StorageAreaImpl::StorageAreaImpl(PassRefPtr<StorageAreaMap> storageAreaMap)
     52    : m_storageAreaID(generateStorageAreaID())
     53    , m_storageAreaMap(storageAreaMap)
    6154{
    62     WebProcess::shared().connection()->send(Messages::StorageManager::CreateStorageMap(m_storageAreaID, StorageNamespaceImpl->storageNamespaceID(), SecurityOriginData::fromSecurityOrigin(m_securityOrigin.get())), 0);
    63     WebProcess::shared().addMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageAreaID, this);
    6455}
    6556
    6657StorageAreaImpl::~StorageAreaImpl()
    6758{
    68     WebProcess::shared().connection()->send(Messages::StorageManager::DestroyStorageMap(m_storageAreaID), 0);
    69     WebProcess::shared().removeMessageReceiver(Messages::StorageAreaMap::messageReceiverName(), m_storageAreaID);
     59}
     60
     61StorageType StorageAreaImpl::storageType() const
     62{
     63    return m_storageAreaMap->storageType();
    7064}
    7165
     
    8175        return 0;
    8276
    83     loadValuesIfNeeded();
    84     return m_storageMap->length();
     77    return m_storageAreaMap->length();
    8578}
    8679
     
    9285        return String();
    9386    }
     87
    9488    if (disabledByPrivateBrowsingInFrame(sourceFrame))
    9589        return String();
    9690
    97     loadValuesIfNeeded();
    98 
    99     return m_storageMap->key(index);
     91    return m_storageAreaMap->key(index);
    10092}
    10193
     
    10799        return String();
    108100    }
     101
    109102    if (disabledByPrivateBrowsingInFrame(sourceFrame))
    110103        return String();
    111104
    112     loadValuesIfNeeded();
    113     return m_storageMap->getItem(key);
     105    return m_storageAreaMap->item(key);
    114106}
    115107
     
    129121    }
    130122
    131     loadValuesIfNeeded();
     123    bool quotaException;
     124    m_storageAreaMap->setItem(this, key, value, quotaException);
    132125
    133     ASSERT(m_storageMap->hasOneRef());
    134     String oldValue;
    135     bool quotaException;
    136     m_storageMap->setItem(key, value, oldValue, quotaException);
    137 
    138     if (quotaException) {
     126    if (quotaException)
    139127        ec = QUOTA_EXCEEDED_ERR;
    140         return;
    141     }
    142 
    143     if (oldValue == value)
    144         return;
    145 
    146     m_pendingValueChanges.add(key);
    147 
    148     WebProcess::shared().connection()->send(Messages::StorageManager::SetItem(m_storageAreaID, key, value, sourceFrame->document()->url()), 0);
    149128}
    150129
     
    174153        return false;
    175154
    176     loadValuesIfNeeded();
    177 
    178     return m_storageMap->contains(key);
     155    return m_storageAreaMap->contains(key);
    179156}
    180157
     
    205182}
    206183
    207 
    208 void StorageAreaImpl::didSetItem(const String& key, bool quotaError)
    209 {
    210     ASSERT(m_pendingValueChanges.contains(key));
    211 
    212     m_pendingValueChanges.remove(key);
    213 
    214     if (quotaError)
    215         resetValues();
    216 }
    217 
    218 void StorageAreaImpl::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
    219 {
    220     if (!shouldApplyChangesForKey(key))
    221         return;
    222 
    223     ASSERT(!key.isNull());
    224     ASSERT(!newValue.isNull());
    225 
    226     ASSERT(m_storageMap->hasOneRef());
    227     m_storageMap->setItemIgnoringQuota(key, newValue);
    228 
    229     if (storageType() == SessionStorage)
    230         dispatchSessionStorageEvent(key, oldValue, newValue, urlString);
    231     else
    232         dispatchLocalStorageEvent(key, oldValue, newValue, urlString);
    233 }
    234 
    235 StorageType StorageAreaImpl::storageType() const
    236 {
    237     // A zero storage namespace ID is used for local storage.
    238     if (!m_storageNamespaceID)
    239         return LocalStorage;
    240 
    241     return SessionStorage;
    242 }
    243 
    244184bool StorageAreaImpl::disabledByPrivateBrowsingInFrame(const Frame* sourceFrame) const
    245185{
     
    253193}
    254194
    255 bool StorageAreaImpl::shouldApplyChangesForKey(const String& key) const
    256 {
    257     // We have not yet loaded anything from this storage map.
    258     if (!m_storageMap)
    259         return false;
    260 
    261     // Check if this storage area is currently waiting for the storage manager to update the given key.
    262     // If that is the case, we don't want to apply any changes made by other storage areas, since
    263     // our change was made last.
    264     if (m_pendingValueChanges.contains(key))
    265         return false;
    266 
    267     return true;
    268 }
    269 
    270 void StorageAreaImpl::loadValuesIfNeeded()
    271 {
    272     if (m_storageMap)
    273         return;
    274 
    275     HashMap<String, String> values;
    276     // FIXME: This should use a special sendSync flag to indicate that we don't want to process incoming messages while waiting for a reply.
    277     // (This flag does not yet exist).
    278     WebProcess::shared().connection()->sendSync(Messages::StorageManager::GetValues(m_storageAreaID), Messages::StorageManager::GetValues::Reply(values), 0);
    279 
    280     m_storageMap = StorageMap::create(m_quotaInBytes);
    281     m_storageMap->importItems(values);
    282 }
    283 
    284 void StorageAreaImpl::resetValues()
    285 {
    286     m_storageMap = nullptr;
    287     m_pendingValueChanges.clear();
    288 }
    289 
    290 void StorageAreaImpl::dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
    291 {
    292     ASSERT(storageType() == SessionStorage);
    293 
    294     // FIXME: Implement.
    295     UNUSED_PARAM(key);
    296     UNUSED_PARAM(oldValue);
    297     UNUSED_PARAM(newValue);
    298     UNUSED_PARAM(urlString);
    299 }
    300 
    301 void StorageAreaImpl::dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
    302 {
    303     ASSERT(storageType() == LocalStorage);
    304 
    305     // FIXME: Implement.
    306     UNUSED_PARAM(key);
    307     UNUSED_PARAM(oldValue);
    308     UNUSED_PARAM(newValue);
    309     UNUSED_PARAM(urlString);
    310 }
    311 
    312195} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaImpl.h

    r148148 r148161  
    3232#include <wtf/HashMap.h>
    3333
    34 namespace WebCore {
    35 class StorageMap;
    36 }
    37 
    3834namespace WebKit {
    3935
    40 class StorageNamespaceImpl;
     36class StorageAreaMap;
    4137
    42 class StorageAreaImpl : public WebCore::StorageArea, private CoreIPC::MessageReceiver {
     38class StorageAreaImpl : public WebCore::StorageArea {
    4339public:
    44     static PassRefPtr<StorageAreaImpl> create(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);
     40    static PassRefPtr<StorageAreaImpl> create(PassRefPtr<StorageAreaMap>);
    4541    virtual ~StorageAreaImpl();
    4642
     43    uint64_t storageAreaID() const { return m_storageAreaID; }
     44    WebCore::StorageType storageType() const;
     45
    4746private:
    48     StorageAreaImpl(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);
     47    StorageAreaImpl(PassRefPtr<StorageAreaMap>);
    4948
    5049    // WebCore::StorageArea.
     
    6261    virtual void closeDatabaseIfIdle() OVERRIDE;
    6362
    64     // CoreIPC::MessageReceiver
    65     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE;
    66 
    67     void didSetItem(const String& key, bool quotaError);
    68     void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
    69 
    70     WebCore::StorageType storageType() const;
    7163    bool disabledByPrivateBrowsingInFrame(const WebCore::Frame* sourceFrame) const;
    7264
    73     bool shouldApplyChangesForKey(const String& key) const;
    74     void loadValuesIfNeeded();
    75     void resetValues();
    76 
    77     void dispatchSessionStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
    78     void dispatchLocalStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
    79 
    80     uint64_t m_storageNamespaceID;
    81     unsigned m_quotaInBytes;
    8265    uint64_t m_storageAreaID;
    83 
    84     RefPtr<WebCore::SecurityOrigin> m_securityOrigin;
    85     RefPtr<WebCore::StorageMap> m_storageMap;
    86 
    87     HashCountedSet<String> m_pendingValueChanges;
     66    RefPtr<StorageAreaMap> m_storageAreaMap;
    8867};
    8968
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.cpp

    r148154 r148161  
    2727#include "StorageAreaMap.h"
    2828
     29#include "StorageNamespaceImpl.h"
     30#include <WebCore/StorageMap.h>
     31
     32using namespace WebCore;
     33
    2934namespace WebKit {
    3035
    31 PassRefPtr<StorageAreaMap> StorageAreaMap::create()
     36static uint64_t generateStorageMapID()
    3237{
    33     return adoptRef(new StorageAreaMap);
     38    static uint64_t storageMapID;
     39    return ++storageMapID;
    3440}
    3541
    36 StorageAreaMap::StorageAreaMap()
     42PassRefPtr<StorageAreaMap> StorageAreaMap::create(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin)
     43{
     44    return adoptRef(new StorageAreaMap(storageNamespace, securityOrigin));
     45}
     46
     47StorageAreaMap::StorageAreaMap(StorageNamespaceImpl* storageNamespace, PassRefPtr<WebCore::SecurityOrigin> securityOrigin)
     48    : m_storageMapID(generateStorageMapID())
     49    , m_storageNamespaceID(storageNamespace->storageNamespaceID())
     50    , m_quotaInBytes(storageNamespace->quotaInBytes())
     51    , m_securityOrigin(securityOrigin)
    3752{
    3853}
     
    4257}
    4358
     59StorageType StorageAreaMap::storageType() const
     60{
     61    // A zero storage namespace ID is used for local storage.
     62    if (!m_storageNamespaceID)
     63        return LocalStorage;
     64
     65    return SessionStorage;
     66}
     67
     68unsigned StorageAreaMap::length()
     69{
     70    // FIXME: Implement.
     71    return 0;
     72}
     73
     74String StorageAreaMap::key(unsigned index)
     75{
     76    // FIXME: Implement.
     77    return String();
     78}
     79
     80String StorageAreaMap::item(const String& key)
     81{
     82    // FIXME: Implement.
     83    return String();
     84}
     85
     86void StorageAreaMap::setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException)
     87{
     88    // FIXME: Implement.
     89}
     90
     91bool StorageAreaMap::contains(const String& key)
     92{
     93    // FIXME: Implement.
     94    return false;
     95}
     96
    4497void StorageAreaMap::didSetItem(const String& key, bool quotaError)
    4598{
     99    // FIXME: Implement.
    46100}
    47101
    48102void StorageAreaMap::dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString)
    49103{
     104    // FIXME: Implement.
    50105}
    51106
  • trunk/Source/WebKit2/WebProcess/Storage/StorageAreaMap.h

    r148154 r148161  
    2828
    2929#include "MessageReceiver.h"
     30#include <WebCore/SecurityOrigin.h>
     31#include <WebCore/StorageArea.h>
    3032#include <wtf/Forward.h>
    3133#include <wtf/PassRefPtr.h>
    3234#include <wtf/RefCounted.h>
    3335
     36namespace WebCore {
     37class SecurityOrigin;
     38class StorageMap;
     39}
     40
    3441namespace WebKit {
     42
     43class StorageAreaImpl;
     44class StorageNamespaceImpl;
    3545
    3646class StorageAreaMap : public RefCounted<StorageAreaMap>, private CoreIPC::MessageReceiver {
    3747public:
    38     static PassRefPtr<StorageAreaMap> create();
     48    static PassRefPtr<StorageAreaMap> create(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);
    3949    ~StorageAreaMap();
    4050
     51    WebCore::StorageType storageType() const;
     52
     53    unsigned length();
     54    String key(unsigned index);
     55    String item(const String& key);
     56    void setItem(StorageAreaImpl* sourceArea, const String& key, const String& value, bool& quotaException);
     57    bool contains(const String& key);
     58
    4159private:
    42     StorageAreaMap();
     60    StorageAreaMap(StorageNamespaceImpl*, PassRefPtr<WebCore::SecurityOrigin>);
    4361
    4462    // CoreIPC::MessageReceiver
     
    4765    void didSetItem(const String& key, bool quotaError);
    4866    void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, const String& urlString);
     67
     68    void loadValuesIfNeeded();
     69
     70    uint64_t m_storageMapID;
     71    uint64_t m_storageNamespaceID;
     72    unsigned m_quotaInBytes;
     73    RefPtr<WebCore::SecurityOrigin> m_securityOrigin;
     74
     75
     76    RefPtr<WebCore::StorageMap> m_storageMap;
    4977};
    5078
  • trunk/Source/WebKit2/WebProcess/Storage/StorageNamespaceImpl.cpp

    r148148 r148161  
    2828
    2929#include "StorageAreaImpl.h"
     30#include "StorageAreaMap.h"
    3031#include "WebPage.h"
    3132#include <WebCore/SecurityOrigin.h>
     
    5354PassRefPtr<StorageArea> StorageNamespaceImpl::storageArea(PassRefPtr<SecurityOrigin> securityOrigin)
    5455{
    55     HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaImpl> >::AddResult result = m_storageAreaMap.add(securityOrigin.get(), 0);
     56    HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaMap> >::AddResult result = m_storageAreaMaps.add(securityOrigin.get(), 0);
    5657    if (result.isNewEntry)
    57         result.iterator->value = StorageAreaImpl::create(this, securityOrigin);
     58        result.iterator->value = StorageAreaMap::create(this, securityOrigin);
    5859
    59     return result.iterator->value;
     60    return StorageAreaImpl::create(result.iterator->value);
    6061}
    6162
  • trunk/Source/WebKit2/WebProcess/Storage/StorageNamespaceImpl.h

    r148148 r148161  
    3434namespace WebKit {
    3535
    36 class StorageAreaImpl;
     36class StorageAreaMap;
    3737class WebPage;
    3838
     
    5959    unsigned m_quotaInBytes;
    6060
    61     HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaImpl> > m_storageAreaMap;
     61    HashMap<RefPtr<WebCore::SecurityOrigin>, RefPtr<StorageAreaMap> > m_storageAreaMaps;
    6262};
    6363
Note: See TracChangeset for help on using the changeset viewer.