| Index: webkit/dom_storage/dom_storage_host.cc
|
| ===================================================================
|
| --- webkit/dom_storage/dom_storage_host.cc (revision 0)
|
| +++ webkit/dom_storage/dom_storage_host.cc (revision 0)
|
| @@ -0,0 +1,103 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "webkit/dom_storage/dom_storage_host.h"
|
| +
|
| +#include "googleurl/src/gurl.h"
|
| +#include "webkit/dom_storage/dom_storage_area.h"
|
| +#include "webkit/dom_storage/dom_storage_context.h"
|
| +#include "webkit/dom_storage/dom_storage_namespace.h"
|
| +
|
| +namespace dom_storage {
|
| +
|
| +DOMStorageHost::DOMStorageHost(DOMStorageContext* context)
|
| + : last_connection_id_(0),
|
| + context_(context) {
|
| +}
|
| +
|
| +DOMStorageHost::~DOMStorageHost() {
|
| +}
|
| +
|
| +// TODO(michaeln): have the caller pass in the 'connection_id' value
|
| +// instead of generating them here, avoids a sync ipc on open.
|
| +int DOMStorageHost::OpenStorageArea(int namespace_id, const GURL& origin) {
|
| + DOMStorageNamespace* name_space = context_->GetStorageNamespace(namespace_id);
|
| + if (!name_space)
|
| + return -1;
|
| + DOMStorageArea* area = name_space->GetStorageArea(origin);
|
| + if (!area)
|
| + return -1;
|
| + int id = ++last_connection_id_;
|
| + connections_[id] = area;
|
| + return id;
|
| +}
|
| +
|
| +void DOMStorageHost::CloseStorageArea(int connection_id) {
|
| + connections_.erase(connection_id);
|
| +}
|
| +
|
| +int DOMStorageHost::GetAreaLength(int connection_id) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return 0;
|
| + return area->Length();
|
| +}
|
| +
|
| +NullableString16 DOMStorageHost::GetKey(int connection_id, int index) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return NullableString16();
|
| + return area->Key(index);
|
| +}
|
| +
|
| +NullableString16 DOMStorageHost::GetItem(int connection_id,
|
| + const string16& key) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return NullableString16();
|
| + return area->GetItem(key);
|
| +}
|
| +
|
| +bool DOMStorageHost::SetItem(int connection_id, const string16& key,
|
| + const string16& value, const GURL& page_url,
|
| + NullableString16* old_value) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return false;
|
| + if (!area->SetItem(key, value, old_value))
|
| + return false;
|
| + context_->NotifyEventListeners();
|
| + return true;
|
| +}
|
| +
|
| +bool DOMStorageHost::RemoveItem(int connection_id, const string16& key,
|
| + const GURL& page_url,
|
| + NullableString16* old_value) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return false;
|
| + if (!area->RemoveItem(key, old_value))
|
| + return false;
|
| + context_->NotifyEventListeners();
|
| + return true;
|
| +}
|
| +
|
| +bool DOMStorageHost::ClearArea(int connection_id, const GURL& page_url) {
|
| + DOMStorageArea* area = GetOpenArea(connection_id);
|
| + if (!area)
|
| + return false;
|
| + if (!area->Clear())
|
| + return false;
|
| + context_->NotifyEventListeners();
|
| + return true;
|
| +}
|
| +
|
| +DOMStorageArea* DOMStorageHost::GetOpenArea(int connection_id) {
|
| + AreaMap::iterator found = connections_.find(connection_id);
|
| + if (found == connections_.end())
|
| + return NULL;
|
| + return found->second;
|
| +}
|
| +
|
| +} // namespace dom_storage
|
|
|
| Property changes on: webkit\dom_storage\dom_storage_host.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|