| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/browser/dom_storage/dom_storage_session.h" | 5 #include "content/browser/dom_storage/dom_storage_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
| 11 #include "webkit/browser/dom_storage/dom_storage_context.h" | 11 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 12 #include "webkit/browser/dom_storage/dom_storage_task_runner.h" | 12 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 13 | 13 |
| 14 namespace dom_storage { | 14 namespace content { |
| 15 | 15 |
| 16 DomStorageSession::DomStorageSession(DomStorageContext* context) | 16 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context) |
| 17 : context_(context), | 17 : context_(context), |
| 18 namespace_id_(context->AllocateSessionId()), | 18 namespace_id_(context->AllocateSessionId()), |
| 19 persistent_namespace_id_(context->AllocatePersistentSessionId()), | 19 persistent_namespace_id_(context->AllocatePersistentSessionId()), |
| 20 should_persist_(false) { | 20 should_persist_(false) { |
| 21 context->task_runner()->PostTask( | 21 context->task_runner()->PostTask( |
| 22 FROM_HERE, | 22 FROM_HERE, |
| 23 base::Bind(&DomStorageContext::CreateSessionNamespace, | 23 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, |
| 24 context_, namespace_id_, persistent_namespace_id_)); | 24 context_, namespace_id_, persistent_namespace_id_)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 DomStorageSession::DomStorageSession(DomStorageContext* context, | 27 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context, |
| 28 const std::string& persistent_namespace_id) | 28 const std::string& persistent_namespace_id) |
| 29 : context_(context), | 29 : context_(context), |
| 30 namespace_id_(context->AllocateSessionId()), | 30 namespace_id_(context->AllocateSessionId()), |
| 31 persistent_namespace_id_(persistent_namespace_id), | 31 persistent_namespace_id_(persistent_namespace_id), |
| 32 should_persist_(false) { | 32 should_persist_(false) { |
| 33 context->task_runner()->PostTask( | 33 context->task_runner()->PostTask( |
| 34 FROM_HERE, | 34 FROM_HERE, |
| 35 base::Bind(&DomStorageContext::CreateSessionNamespace, | 35 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, |
| 36 context_, namespace_id_, persistent_namespace_id_)); | 36 context_, namespace_id_, persistent_namespace_id_)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void DomStorageSession::SetShouldPersist(bool should_persist) { | 39 void DOMStorageSession::SetShouldPersist(bool should_persist) { |
| 40 should_persist_ = should_persist; | 40 should_persist_ = should_persist; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool DomStorageSession::should_persist() const { | 43 bool DOMStorageSession::should_persist() const { |
| 44 return should_persist_; | 44 return should_persist_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool DomStorageSession::IsFromContext(DomStorageContext* context) { | 47 bool DOMStorageSession::IsFromContext(DOMStorageContextImpl* context) { |
| 48 return context_.get() == context; | 48 return context_.get() == context; |
| 49 } | 49 } |
| 50 | 50 |
| 51 DomStorageSession* DomStorageSession::Clone() { | 51 DOMStorageSession* DOMStorageSession::Clone() { |
| 52 return CloneFrom(context_.get(), namespace_id_); | 52 return CloneFrom(context_.get(), namespace_id_); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // static | 55 // static |
| 56 DomStorageSession* DomStorageSession::CloneFrom(DomStorageContext* context, | 56 DOMStorageSession* DOMStorageSession::CloneFrom(DOMStorageContextImpl* context, |
| 57 int64 namepace_id_to_clone) { | 57 int64 namepace_id_to_clone) { |
| 58 int64 clone_id = context->AllocateSessionId(); | 58 int64 clone_id = context->AllocateSessionId(); |
| 59 std::string persistent_clone_id = context->AllocatePersistentSessionId(); | 59 std::string persistent_clone_id = context->AllocatePersistentSessionId(); |
| 60 context->task_runner()->PostTask( | 60 context->task_runner()->PostTask( |
| 61 FROM_HERE, | 61 FROM_HERE, |
| 62 base::Bind(&DomStorageContext::CloneSessionNamespace, | 62 base::Bind(&DOMStorageContextImpl::CloneSessionNamespace, |
| 63 context, namepace_id_to_clone, clone_id, persistent_clone_id)); | 63 context, namepace_id_to_clone, clone_id, persistent_clone_id)); |
| 64 return new DomStorageSession(context, clone_id, persistent_clone_id); | 64 return new DOMStorageSession(context, clone_id, persistent_clone_id); |
| 65 } | 65 } |
| 66 | 66 |
| 67 DomStorageSession::DomStorageSession(DomStorageContext* context, | 67 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context, |
| 68 int64 namespace_id, | 68 int64 namespace_id, |
| 69 const std::string& persistent_namespace_id) | 69 const std::string& persistent_namespace_id) |
| 70 : context_(context), | 70 : context_(context), |
| 71 namespace_id_(namespace_id), | 71 namespace_id_(namespace_id), |
| 72 persistent_namespace_id_(persistent_namespace_id), | 72 persistent_namespace_id_(persistent_namespace_id), |
| 73 should_persist_(false) { | 73 should_persist_(false) { |
| 74 // This ctor is intended for use by the Clone() method. | 74 // This ctor is intended for use by the Clone() method. |
| 75 } | 75 } |
| 76 | 76 |
| 77 DomStorageSession::~DomStorageSession() { | 77 DOMStorageSession::~DOMStorageSession() { |
| 78 context_->task_runner()->PostTask( | 78 context_->task_runner()->PostTask( |
| 79 FROM_HERE, | 79 FROM_HERE, |
| 80 base::Bind(&DomStorageContext::DeleteSessionNamespace, | 80 base::Bind(&DOMStorageContextImpl::DeleteSessionNamespace, |
| 81 context_, namespace_id_, should_persist_)); | 81 context_, namespace_id_, should_persist_)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace dom_storage | 84 } // namespace content |
| OLD | NEW |