OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/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/single_thread_task_runner.h" | |
11 #include "base/thread_task_runner_handle.h" | |
12 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
13 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 11 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
14 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 12 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
15 | 13 |
16 namespace content { | 14 namespace content { |
17 | 15 |
18 namespace { | |
19 | |
20 void PostMergeTaskResult( | |
21 const SessionStorageNamespace::MergeResultCallback& callback, | |
22 SessionStorageNamespace::MergeResult result) { | |
23 callback.Run(result); | |
24 } | |
25 | |
26 void RunMergeTaskAndPostResult( | |
27 const base::Callback<SessionStorageNamespace::MergeResult(void)>& task, | |
28 scoped_refptr<base::SingleThreadTaskRunner> result_loop, | |
29 const SessionStorageNamespace::MergeResultCallback& callback) { | |
30 SessionStorageNamespace::MergeResult result = task.Run(); | |
31 result_loop->PostTask( | |
32 FROM_HERE, base::Bind(&PostMergeTaskResult, callback, result)); | |
33 } | |
34 | |
35 } // namespace | |
36 | |
37 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context) | 16 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context) |
38 : context_(context), | 17 : context_(context), |
39 namespace_id_(context->AllocateSessionId()), | 18 namespace_id_(context->AllocateSessionId()), |
40 persistent_namespace_id_(context->AllocatePersistentSessionId()), | 19 persistent_namespace_id_(context->AllocatePersistentSessionId()), |
41 should_persist_(false) { | 20 should_persist_(false) { |
42 context->task_runner()->PostTask( | 21 context->task_runner()->PostTask( |
43 FROM_HERE, | 22 FROM_HERE, |
44 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, | 23 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, |
45 context_, namespace_id_, persistent_namespace_id_)); | 24 context_, namespace_id_, persistent_namespace_id_)); |
46 } | 25 } |
47 | 26 |
48 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context, | 27 DOMStorageSession::DOMStorageSession(DOMStorageContextImpl* context, |
49 const std::string& persistent_namespace_id) | 28 const std::string& persistent_namespace_id) |
50 : context_(context), | 29 : context_(context), |
51 namespace_id_(context->AllocateSessionId()), | 30 namespace_id_(context->AllocateSessionId()), |
52 persistent_namespace_id_(persistent_namespace_id), | 31 persistent_namespace_id_(persistent_namespace_id), |
53 should_persist_(false) { | 32 should_persist_(false) { |
54 context->task_runner()->PostTask( | 33 context->task_runner()->PostTask( |
55 FROM_HERE, | 34 FROM_HERE, |
56 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, | 35 base::Bind(&DOMStorageContextImpl::CreateSessionNamespace, |
57 context_, namespace_id_, persistent_namespace_id_)); | 36 context_, namespace_id_, persistent_namespace_id_)); |
58 } | 37 } |
59 | 38 |
60 DOMStorageSession::DOMStorageSession( | |
61 DOMStorageSession* master_dom_storage_session) | |
62 : context_(master_dom_storage_session->context_), | |
63 namespace_id_(master_dom_storage_session->context_->AllocateSessionId()), | |
64 persistent_namespace_id_( | |
65 master_dom_storage_session->persistent_namespace_id()), | |
66 should_persist_(false) { | |
67 context_->task_runner()->PostTask( | |
68 FROM_HERE, | |
69 base::Bind(&DOMStorageContextImpl::CreateAliasSessionNamespace, | |
70 context_, | |
71 master_dom_storage_session->namespace_id(), | |
72 namespace_id_, | |
73 persistent_namespace_id_)); | |
74 } | |
75 | |
76 void DOMStorageSession::SetShouldPersist(bool should_persist) { | 39 void DOMStorageSession::SetShouldPersist(bool should_persist) { |
77 should_persist_ = should_persist; | 40 should_persist_ = should_persist; |
78 } | 41 } |
79 | 42 |
80 bool DOMStorageSession::should_persist() const { | 43 bool DOMStorageSession::should_persist() const { |
81 return should_persist_; | 44 return should_persist_; |
82 } | 45 } |
83 | 46 |
84 bool DOMStorageSession::IsFromContext(DOMStorageContextImpl* context) { | 47 bool DOMStorageSession::IsFromContext(DOMStorageContextImpl* context) { |
85 return context_.get() == context; | 48 return context_.get() == context; |
(...skipping 25 matching lines...) Expand all Loading... |
111 // This ctor is intended for use by the Clone() method. | 74 // This ctor is intended for use by the Clone() method. |
112 } | 75 } |
113 | 76 |
114 DOMStorageSession::~DOMStorageSession() { | 77 DOMStorageSession::~DOMStorageSession() { |
115 context_->task_runner()->PostTask( | 78 context_->task_runner()->PostTask( |
116 FROM_HERE, | 79 FROM_HERE, |
117 base::Bind(&DOMStorageContextImpl::DeleteSessionNamespace, | 80 base::Bind(&DOMStorageContextImpl::DeleteSessionNamespace, |
118 context_, namespace_id_, should_persist_)); | 81 context_, namespace_id_, should_persist_)); |
119 } | 82 } |
120 | 83 |
121 void DOMStorageSession::AddTransactionLogProcessId(int process_id) { | |
122 context_->task_runner()->PostTask( | |
123 FROM_HERE, | |
124 base::Bind(&DOMStorageContextImpl::AddTransactionLogProcessId, | |
125 context_, namespace_id_, process_id)); | |
126 } | |
127 | |
128 void DOMStorageSession::RemoveTransactionLogProcessId(int process_id) { | |
129 context_->task_runner()->PostTask( | |
130 FROM_HERE, | |
131 base::Bind(&DOMStorageContextImpl::RemoveTransactionLogProcessId, | |
132 context_, namespace_id_, process_id)); | |
133 } | |
134 | |
135 void DOMStorageSession::Merge( | |
136 bool actually_merge, | |
137 int process_id, | |
138 DOMStorageSession* other, | |
139 const SessionStorageNamespace::MergeResultCallback& callback) { | |
140 scoped_refptr<base::SingleThreadTaskRunner> current_loop( | |
141 base::ThreadTaskRunnerHandle::Get()); | |
142 SessionStorageNamespace::MergeResultCallback cb = | |
143 base::Bind(&DOMStorageSession::ProcessMergeResult, | |
144 this, | |
145 actually_merge, | |
146 callback, | |
147 other->persistent_namespace_id()); | |
148 context_->task_runner()->PostTask( | |
149 FROM_HERE, | |
150 base::Bind(&RunMergeTaskAndPostResult, | |
151 base::Bind(&DOMStorageContextImpl::MergeSessionStorage, | |
152 context_, namespace_id_, actually_merge, process_id, | |
153 other->namespace_id_), | |
154 current_loop, | |
155 cb)); | |
156 } | |
157 | |
158 void DOMStorageSession::ProcessMergeResult( | |
159 bool actually_merge, | |
160 const SessionStorageNamespace::MergeResultCallback& callback, | |
161 const std::string& new_persistent_namespace_id, | |
162 SessionStorageNamespace::MergeResult result) { | |
163 if (actually_merge && | |
164 (result == SessionStorageNamespace::MERGE_RESULT_MERGEABLE || | |
165 result == SessionStorageNamespace::MERGE_RESULT_NO_TRANSACTIONS)) { | |
166 persistent_namespace_id_ = new_persistent_namespace_id; | |
167 } | |
168 callback.Run(result); | |
169 } | |
170 | |
171 } // namespace content | 84 } // namespace content |
OLD | NEW |