Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 2847013002: Switch to mojo localstorage backend by default. (Closed)
Patch Set: minor cleanup Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_context_wrapper.h" 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 context_ = new DOMStorageContextImpl( 98 context_ = new DOMStorageContextImpl(
99 data_path.empty() ? data_path 99 data_path.empty() ? data_path
100 : data_path.AppendASCII(kLocalStorageDirectory), 100 : data_path.AppendASCII(kLocalStorageDirectory),
101 data_path.empty() ? data_path 101 data_path.empty() ? data_path
102 : data_path.AppendASCII(kSessionStorageDirectory), 102 : data_path.AppendASCII(kSessionStorageDirectory),
103 special_storage_policy, 103 special_storage_policy,
104 new DOMStorageWorkerPoolTaskRunner(std::move(primary_sequence), 104 new DOMStorageWorkerPoolTaskRunner(std::move(primary_sequence),
105 std::move(commit_sequence))); 105 std::move(commit_sequence)));
106 106
107 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 107 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
108 switches::kMojoLocalStorage)) { 108 switches::kDisableMojoLocalStorage)) {
109 base::FilePath storage_dir; 109 base::FilePath storage_dir;
110 if (!profile_path.empty()) 110 if (!profile_path.empty())
111 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory); 111 storage_dir = local_partition_path.AppendASCII(kLocalStorageDirectory);
112 // TODO(mek): Use a SequencedTaskRunner once mojo no longer requires a 112 // TODO(mek): Use a SequencedTaskRunner once mojo no longer requires a
113 // SingleThreadTaskRunner (http://crbug.com/678155). 113 // SingleThreadTaskRunner (http://crbug.com/678155).
114 mojo_task_runner_ = 114 mojo_task_runner_ =
115 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); 115 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
116 mojo_state_ = new LocalStorageContextMojo( 116 mojo_state_ = new LocalStorageContextMojo(
117 connector, context_->task_runner(), 117 connector, context_->task_runner(),
118 data_path.empty() ? data_path 118 data_path.empty() ? data_path
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 mojo_state_ = nullptr; 264 mojo_state_ = nullptr;
265 } 265 }
266 memory_pressure_listener_.reset(); 266 memory_pressure_listener_.reset();
267 context_->task_runner()->PostShutdownBlockingTask( 267 context_->task_runner()->PostShutdownBlockingTask(
268 FROM_HERE, 268 FROM_HERE,
269 DOMStorageTaskRunner::PRIMARY_SEQUENCE, 269 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
270 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); 270 base::Bind(&DOMStorageContextImpl::Shutdown, context_));
271 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { 271 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
272 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); 272 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
273 } 273 }
274 274 context_ = nullptr;
michaeln 2017/05/26 19:12:44 this might turn up some crashes in odd cases where
Marijn Kruisselbrink 2017/05/26 23:43:02 attempting to post tasks to the TaskScheduler (as
michaeln 2017/05/27 01:59:03 calling contextwrapper methods after shutdown used
275 } 275 }
276 276
277 void DOMStorageContextWrapper::Flush() { 277 void DOMStorageContextWrapper::Flush() {
278 DCHECK(context_.get()); 278 DCHECK(context_.get());
279 279
280 context_->task_runner()->PostShutdownBlockingTask( 280 context_->task_runner()->PostShutdownBlockingTask(
281 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 281 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
282 base::Bind(&DOMStorageContextImpl::Flush, context_)); 282 base::Bind(&DOMStorageContextImpl::Flush, context_));
283 if (mojo_state_) { 283 if (mojo_state_) {
284 // base::Unretained is safe here, because the mojo_state_ won't be deleted 284 // base::Unretained is safe here, because the mojo_state_ won't be deleted
(...skipping 14 matching lines...) Expand all
299 // base::Unretained is safe here, because the mojo_state_ won't be deleted 299 // base::Unretained is safe here, because the mojo_state_ won't be deleted
300 // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and 300 // until a ShutdownAndDelete task has been ran on the mojo_task_runner_, and
301 // as soon as that task is posted, mojo_state_ is set to null, preventing 301 // as soon as that task is posted, mojo_state_ is set to null, preventing
302 // further tasks from being queued. 302 // further tasks from being queued.
303 mojo_task_runner_->PostTask( 303 mojo_task_runner_->PostTask(
304 FROM_HERE, base::BindOnce(&LocalStorageContextMojo::OpenLocalStorage, 304 FROM_HERE, base::BindOnce(&LocalStorageContextMojo::OpenLocalStorage,
305 base::Unretained(mojo_state_), origin, 305 base::Unretained(mojo_state_), origin,
306 std::move(request))); 306 std::move(request)));
307 } 307 }
308 308
309 leveldb::mojom::LevelDBDatabaseAssociatedRequest
310 DOMStorageContextWrapper::LocalStorageDatabaseRequestForTesting() {
311 if (!mojo_state_)
312 return nullptr;
313 return mojo_state_->DatabaseRequestForTesting();
314 }
315
309 void DOMStorageContextWrapper::OnMemoryPressure( 316 void DOMStorageContextWrapper::OnMemoryPressure(
310 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 317 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
311 DOMStorageContextImpl::PurgeOption purge_option = 318 DOMStorageContextImpl::PurgeOption purge_option =
312 DOMStorageContextImpl::PURGE_UNOPENED; 319 DOMStorageContextImpl::PURGE_UNOPENED;
313 if (memory_pressure_level == 320 if (memory_pressure_level ==
314 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 321 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
315 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; 322 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE;
316 } 323 }
317 PurgeMemory(purge_option); 324 PurgeMemory(purge_option);
318 } 325 }
(...skipping 15 matching lines...) Expand all
334 mojo_task_runner_->PostTask( 341 mojo_task_runner_->PostTask(
335 FROM_HERE, base::BindOnce(&LocalStorageContextMojo::PurgeMemory, 342 FROM_HERE, base::BindOnce(&LocalStorageContextMojo::PurgeMemory,
336 base::Unretained(mojo_state_))); 343 base::Unretained(mojo_state_)));
337 } 344 }
338 } 345 }
339 346
340 void DOMStorageContextWrapper::GotMojoLocalStorageUsage( 347 void DOMStorageContextWrapper::GotMojoLocalStorageUsage(
341 GetLocalStorageUsageCallback callback, 348 GetLocalStorageUsageCallback callback,
342 base::SingleThreadTaskRunner* reply_task_runner, 349 base::SingleThreadTaskRunner* reply_task_runner,
343 std::vector<LocalStorageUsageInfo> usage) { 350 std::vector<LocalStorageUsageInfo> usage) {
351 // If we were shutdown in the meantime, just give up.
352 if (!context_)
michaeln 2017/05/26 19:12:44 we might need more early outs like this to protect
Marijn Kruisselbrink 2017/05/26 23:43:02 every other usage (other than the one in PurgeMemo
michaeln 2017/05/27 01:59:03 The dchecks were to document it's non-nullness and
Marijn Kruisselbrink 2017/05/30 20:53:55 I agree that the current CL is somewhat scare in t
353 return;
344 context_->task_runner()->PostShutdownBlockingTask( 354 context_->task_runner()->PostShutdownBlockingTask(
345 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 355 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
346 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage), 356 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage),
347 base::RetainedRef(reply_task_runner), 357 base::RetainedRef(reply_task_runner),
348 base::RetainedRef(context_), callback)); 358 base::RetainedRef(context_), callback));
349 } 359 }
350 360
351 } // namespace content 361 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698