| Index: webkit/tools/test_shell/simple_dom_storage_system.cc | 
| =================================================================== | 
| --- webkit/tools/test_shell/simple_dom_storage_system.cc	(revision 133749) | 
| +++ webkit/tools/test_shell/simple_dom_storage_system.cc	(working copy) | 
| @@ -4,21 +4,23 @@ | 
|  | 
| #include "webkit/tools/test_shell/simple_dom_storage_system.h" | 
|  | 
| +#include "base/auto_reset.h" | 
| #include "googleurl/src/gurl.h" | 
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" | 
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageEventDispatcher.h" | 
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h" | 
| #include "webkit/database/database_util.h" | 
| -#include "webkit/dom_storage/dom_storage_context.h" | 
| +#include "webkit/dom_storage/dom_storage_area.h" | 
| #include "webkit/dom_storage/dom_storage_host.h" | 
| -#include "webkit/dom_storage/dom_storage_session.h" | 
|  | 
| using dom_storage::DomStorageContext; | 
| using dom_storage::DomStorageHost; | 
| using dom_storage::DomStorageSession; | 
| using webkit_database::DatabaseUtil; | 
| +using WebKit::WebStorageArea; | 
| using WebKit::WebStorageNamespace; | 
| -using WebKit::WebStorageArea; | 
| +using WebKit::WebStorageEventDispatcher; | 
| using WebKit::WebString; | 
| using WebKit::WebURL; | 
|  | 
| @@ -34,7 +36,7 @@ | 
| virtual ~NamespaceImpl(); | 
| virtual WebStorageArea* createStorageArea(const WebString& origin) OVERRIDE; | 
| virtual WebStorageNamespace* copy() OVERRIDE; | 
| -  virtual void close() OVERRIDE; | 
| +  virtual bool isSameNamespace(const WebStorageNamespace&) const OVERRIDE; | 
|  | 
| private: | 
| DomStorageContext* Context() { | 
| @@ -110,8 +112,10 @@ | 
| return new NamespaceImpl(parent_, new_id); | 
| } | 
|  | 
| -void SimpleDomStorageSystem::NamespaceImpl::close() { | 
| -  // TODO(michaeln): remove this deprecated method. | 
| +bool SimpleDomStorageSystem::NamespaceImpl::isSameNamespace( | 
| +    const WebStorageNamespace& other) const { | 
| +  const NamespaceImpl* other_impl = static_cast<const NamespaceImpl*>(&other); | 
| +  return namespace_id_ == other_impl->namespace_id_; | 
| } | 
|  | 
| // AreaImpl ----------------------------- | 
| @@ -158,6 +162,7 @@ | 
| if (!Host()) | 
| return; | 
|  | 
| +  AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this); | 
| NullableString16 old_value; | 
| if (!Host()->SetAreaItem(connection_id_, key, newValue, pageUrl, | 
| &old_value)) | 
| @@ -173,6 +178,7 @@ | 
| if (!Host()) | 
| return; | 
|  | 
| +  AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this); | 
| string16 old_value; | 
| if (!Host()->RemoveAreaItem(connection_id_, key, pageUrl, &old_value)) | 
| return; | 
| @@ -182,10 +188,12 @@ | 
|  | 
| void SimpleDomStorageSystem::AreaImpl::clear( | 
| const WebURL& pageUrl, bool& somethingCleared) { | 
| -  if (Host()) | 
| +  if (Host()) { | 
| +    AutoReset<AreaImpl*> auto_reset(&parent_->area_being_processed_, this); | 
| somethingCleared = Host()->ClearArea(connection_id_, pageUrl); | 
| -  else | 
| -    somethingCleared = false; | 
| +    return; | 
| +  } | 
| +  somethingCleared = false; | 
| } | 
|  | 
| // SimpleDomStorageSystem ----------------------------- | 
| @@ -196,14 +204,17 @@ | 
| : weak_factory_(this), | 
| context_(new DomStorageContext(FilePath(), FilePath(), NULL, NULL)), | 
| host_(new DomStorageHost(context_)), | 
| +      area_being_processed_(NULL), | 
| next_connection_id_(1) { | 
| DCHECK(!g_instance_); | 
| g_instance_ = this; | 
| +  context_->AddEventObserver(this); | 
| } | 
|  | 
| SimpleDomStorageSystem::~SimpleDomStorageSystem() { | 
| g_instance_ = NULL; | 
| host_.reset(); | 
| +  context_->RemoveEventObserver(this); | 
| } | 
|  | 
| WebStorageNamespace* SimpleDomStorageSystem::CreateLocalStorageNamespace() { | 
| @@ -215,3 +226,66 @@ | 
| context_->CreateSessionNamespace(id); | 
| return new NamespaceImpl(weak_factory_.GetWeakPtr(), id); | 
| } | 
| + | 
| +void SimpleDomStorageSystem::OnDomStorageItemSet( | 
| +    const dom_storage::DomStorageArea* area, | 
| +    const string16& key, | 
| +    const string16& new_value, | 
| +    const NullableString16& old_value, | 
| +    const GURL& page_url) { | 
| +  DispatchDomStorageEvent(area, page_url, | 
| +                          NullableString16(key, false), | 
| +                          NullableString16(new_value, false), | 
| +                          old_value); | 
| +} | 
| + | 
| +void SimpleDomStorageSystem::OnDomStorageItemRemoved( | 
| +    const dom_storage::DomStorageArea* area, | 
| +    const string16& key, | 
| +    const string16& old_value, | 
| +    const GURL& page_url) { | 
| +  DispatchDomStorageEvent(area, page_url, | 
| +                          NullableString16(key, false), | 
| +                          NullableString16(true), | 
| +                          NullableString16(old_value, false)); | 
| +} | 
| + | 
| +void SimpleDomStorageSystem::OnDomStorageAreaCleared( | 
| +    const dom_storage::DomStorageArea* area, | 
| +    const GURL& page_url) { | 
| +  DispatchDomStorageEvent(area, page_url, | 
| +                          NullableString16(true), | 
| +                          NullableString16(true), | 
| +                          NullableString16(true)); | 
| +} | 
| + | 
| +void SimpleDomStorageSystem::DispatchDomStorageEvent( | 
| +    const dom_storage::DomStorageArea* area, | 
| +    const GURL& page_url, | 
| +    const NullableString16& key, | 
| +    const NullableString16& new_value, | 
| +    const NullableString16& old_value) { | 
| +  DCHECK(area_being_processed_); | 
| +  if (area->namespace_id() == dom_storage::kLocalStorageNamespaceId) { | 
| +    WebStorageEventDispatcher::dispatchLocalStorageEvent( | 
| +        key, | 
| +        old_value, | 
| +        new_value, | 
| +        area->origin(), | 
| +        page_url, | 
| +        area_being_processed_, | 
| +        true  /* originatedInProcess */); | 
| +  } else { | 
| +    NamespaceImpl session_namespace_for_event_dispatch( | 
| +        base::WeakPtr<SimpleDomStorageSystem>(), area->namespace_id()); | 
| +    WebStorageEventDispatcher::dispatchSessionStorageEvent( | 
| +        key, | 
| +        old_value, | 
| +        new_value, | 
| +        area->origin(), | 
| +        page_url, | 
| +        session_namespace_for_event_dispatch, | 
| +        area_being_processed_, | 
| +        true  /* originatedInProcess */); | 
| +  } | 
| +} | 
|  |