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

Side by Side Diff: content/browser/service_worker/service_worker_storage.cc

Issue 1152543002: ServiceWorker: Migrate the script cache backend from BlockFile to Simple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporate falken@'s comments Created 5 years, 6 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/service_worker/service_worker_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include "base/barrier_closure.h"
7 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
8 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
15 #include "content/browser/service_worker/service_worker_context_core.h" 16 #include "content/browser/service_worker/service_worker_context_core.h"
16 #include "content/browser/service_worker/service_worker_disk_cache.h" 17 #include "content/browser/service_worker/service_worker_disk_cache.h"
18 #include "content/browser/service_worker/service_worker_disk_cache_migrator.h"
17 #include "content/browser/service_worker/service_worker_info.h" 19 #include "content/browser/service_worker/service_worker_info.h"
18 #include "content/browser/service_worker/service_worker_metrics.h"
19 #include "content/browser/service_worker/service_worker_registration.h" 20 #include "content/browser/service_worker/service_worker_registration.h"
20 #include "content/browser/service_worker/service_worker_utils.h" 21 #include "content/browser/service_worker/service_worker_utils.h"
21 #include "content/browser/service_worker/service_worker_version.h" 22 #include "content/browser/service_worker/service_worker_version.h"
22 #include "content/common/service_worker/service_worker_types.h" 23 #include "content/common/service_worker/service_worker_types.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "net/base/completion_callback.h" 25 #include "net/base/completion_callback.h"
25 #include "net/base/io_buffer.h" 26 #include "net/base/io_buffer.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "storage/browser/quota/quota_manager_proxy.h" 28 #include "storage/browser/quota/quota_manager_proxy.h"
28 #include "storage/browser/quota/special_storage_policy.h" 29 #include "storage/browser/quota/special_storage_policy.h"
(...skipping 24 matching lines...) Expand all
53 const scoped_refptr<ServiceWorkerRegistration>& registration, 54 const scoped_refptr<ServiceWorkerRegistration>& registration,
54 ServiceWorkerStatusCode status, 55 ServiceWorkerStatusCode status,
55 const ServiceWorkerStorage::FindRegistrationCallback& callback) { 56 const ServiceWorkerStorage::FindRegistrationCallback& callback) {
56 RunSoon(from_here, 57 RunSoon(from_here,
57 base::Bind(&CompleteFindNow, registration, status, callback)); 58 base::Bind(&CompleteFindNow, registration, status, callback));
58 } 59 }
59 60
60 const base::FilePath::CharType kDatabaseName[] = 61 const base::FilePath::CharType kDatabaseName[] =
61 FILE_PATH_LITERAL("Database"); 62 FILE_PATH_LITERAL("Database");
62 const base::FilePath::CharType kDiskCacheName[] = 63 const base::FilePath::CharType kDiskCacheName[] =
63 FILE_PATH_LITERAL("Cache"); 64 FILE_PATH_LITERAL("ScriptCache");
65 const base::FilePath::CharType kOldDiskCacheName[] = FILE_PATH_LITERAL("Cache");
64 66
65 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; 67 const int kMaxMemDiskCacheSize = 10 * 1024 * 1024;
66 const int kMaxDiskCacheSize = 250 * 1024 * 1024; 68 const int kMaxDiskCacheSize = 250 * 1024 * 1024;
67 69
68 ServiceWorkerStatusCode DatabaseStatusToStatusCode( 70 ServiceWorkerStatusCode DatabaseStatusToStatusCode(
69 ServiceWorkerDatabase::Status status) { 71 ServiceWorkerDatabase::Status status) {
70 switch (status) { 72 switch (status) {
71 case ServiceWorkerDatabase::STATUS_OK: 73 case ServiceWorkerDatabase::STATUS_OK:
72 return SERVICE_WORKER_OK; 74 return SERVICE_WORKER_OK;
73 case ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND: 75 case ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND:
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 : next_registration_id_(kInvalidServiceWorkerRegistrationId), 924 : next_registration_id_(kInvalidServiceWorkerRegistrationId),
923 next_version_id_(kInvalidServiceWorkerVersionId), 925 next_version_id_(kInvalidServiceWorkerVersionId),
924 next_resource_id_(kInvalidServiceWorkerResourceId), 926 next_resource_id_(kInvalidServiceWorkerResourceId),
925 state_(UNINITIALIZED), 927 state_(UNINITIALIZED),
926 path_(path), 928 path_(path),
927 context_(context), 929 context_(context),
928 database_task_manager_(database_task_manager.Pass()), 930 database_task_manager_(database_task_manager.Pass()),
929 disk_cache_thread_(disk_cache_thread), 931 disk_cache_thread_(disk_cache_thread),
930 quota_manager_proxy_(quota_manager_proxy), 932 quota_manager_proxy_(quota_manager_proxy),
931 special_storage_policy_(special_storage_policy), 933 special_storage_policy_(special_storage_policy),
934 needs_disk_cache_migration_(false),
932 is_purge_pending_(false), 935 is_purge_pending_(false),
933 has_checked_for_stale_resources_(false), 936 has_checked_for_stale_resources_(false),
934 weak_factory_(this) { 937 weak_factory_(this) {
935 database_.reset(new ServiceWorkerDatabase(GetDatabasePath())); 938 database_.reset(new ServiceWorkerDatabase(GetDatabasePath()));
936 } 939 }
937 940
938 base::FilePath ServiceWorkerStorage::GetDatabasePath() { 941 base::FilePath ServiceWorkerStorage::GetDatabasePath() {
939 if (path_.empty()) 942 if (path_.empty())
940 return base::FilePath(); 943 return base::FilePath();
941 return path_.Append(ServiceWorkerContextCore::kServiceWorkerDirectory) 944 return path_.Append(ServiceWorkerContextCore::kServiceWorkerDirectory)
942 .Append(kDatabaseName); 945 .Append(kDatabaseName);
943 } 946 }
944 947
945 base::FilePath ServiceWorkerStorage::GetDiskCachePath() { 948 base::FilePath ServiceWorkerStorage::GetDiskCachePath() {
946 if (path_.empty()) 949 if (path_.empty())
947 return base::FilePath(); 950 return base::FilePath();
948 return path_.Append(ServiceWorkerContextCore::kServiceWorkerDirectory) 951 return path_.Append(ServiceWorkerContextCore::kServiceWorkerDirectory)
949 .Append(kDiskCacheName); 952 .Append(kDiskCacheName);
950 } 953 }
951 954
955 base::FilePath ServiceWorkerStorage::GetOldDiskCachePath() {
956 if (path_.empty())
957 return base::FilePath();
958 return path_.Append(ServiceWorkerContextCore::kServiceWorkerDirectory)
959 .Append(kOldDiskCacheName);
960 }
961
952 bool ServiceWorkerStorage::LazyInitialize(const base::Closure& callback) { 962 bool ServiceWorkerStorage::LazyInitialize(const base::Closure& callback) {
953 if (!context_) 963 if (!context_)
954 return false; 964 return false;
955 965
956 switch (state_) { 966 switch (state_) {
957 case INITIALIZED: 967 case INITIALIZED:
958 return true; 968 return true;
959 case DISABLED: 969 case DISABLED:
960 return false; 970 return false;
961 case INITIALIZING: 971 case INITIALIZING:
962 pending_tasks_.push_back(callback); 972 pending_tasks_.push_back(callback);
963 return false; 973 return false;
964 case UNINITIALIZED: 974 case UNINITIALIZED:
965 pending_tasks_.push_back(callback); 975 pending_tasks_.push_back(callback);
966 // Fall-through. 976 // Fall-through.
967 } 977 }
968 978
969 state_ = INITIALIZING; 979 state_ = INITIALIZING;
970 database_task_manager_->GetTaskRunner()->PostTask( 980 database_task_manager_->GetTaskRunner()->PostTask(
971 FROM_HERE, 981 FROM_HERE,
972 base::Bind(&ReadInitialDataFromDB, 982 base::Bind(&ReadInitialDataFromDB, database_.get(),
973 database_.get(), 983 base::ThreadTaskRunnerHandle::Get(), GetOldDiskCachePath(),
974 base::ThreadTaskRunnerHandle::Get(),
975 base::Bind(&ServiceWorkerStorage::DidReadInitialData, 984 base::Bind(&ServiceWorkerStorage::DidReadInitialData,
976 weak_factory_.GetWeakPtr()))); 985 weak_factory_.GetWeakPtr())));
977 return false; 986 return false;
978 } 987 }
979 988
980 void ServiceWorkerStorage::DidReadInitialData( 989 void ServiceWorkerStorage::DidReadInitialData(
981 InitialData* data, 990 InitialData* data,
991 bool needs_disk_cache_migration,
982 ServiceWorkerDatabase::Status status) { 992 ServiceWorkerDatabase::Status status) {
983 DCHECK(data); 993 DCHECK(data);
984 DCHECK_EQ(INITIALIZING, state_); 994 DCHECK_EQ(INITIALIZING, state_);
985 995
986 if (status == ServiceWorkerDatabase::STATUS_OK) { 996 if (status == ServiceWorkerDatabase::STATUS_OK) {
987 next_registration_id_ = data->next_registration_id; 997 next_registration_id_ = data->next_registration_id;
988 next_version_id_ = data->next_version_id; 998 next_version_id_ = data->next_version_id;
989 next_resource_id_ = data->next_resource_id; 999 next_resource_id_ = data->next_resource_id;
990 registered_origins_.swap(data->origins); 1000 registered_origins_.swap(data->origins);
991 state_ = INITIALIZED; 1001 state_ = INITIALIZED;
1002 needs_disk_cache_migration_ = needs_disk_cache_migration;
michaeln 2015/06/08 21:36:33 Curiosity: I wish we didn't have to migrate at all
nhiroki 2015/06/09 15:41:56 Yeah... it's definitely simpler and easier to achi
992 } else { 1003 } else {
993 DVLOG(2) << "Failed to initialize: " 1004 DVLOG(2) << "Failed to initialize: "
994 << ServiceWorkerDatabase::StatusToString(status); 1005 << ServiceWorkerDatabase::StatusToString(status);
995 ScheduleDeleteAndStartOver(); 1006 ScheduleDeleteAndStartOver();
996 } 1007 }
997 1008
998 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); 1009 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin();
999 it != pending_tasks_.end(); ++it) { 1010 it != pending_tasks_.end(); ++it) {
1000 RunSoon(FROM_HERE, *it); 1011 RunSoon(FROM_HERE, *it);
1001 } 1012 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 ServiceWorkerStorage::FindInstallingRegistrationForId( 1372 ServiceWorkerStorage::FindInstallingRegistrationForId(
1362 int64 registration_id) { 1373 int64 registration_id) {
1363 RegistrationRefsById::const_iterator found = 1374 RegistrationRefsById::const_iterator found =
1364 installing_registrations_.find(registration_id); 1375 installing_registrations_.find(registration_id);
1365 if (found == installing_registrations_.end()) 1376 if (found == installing_registrations_.end())
1366 return NULL; 1377 return NULL;
1367 return found->second.get(); 1378 return found->second.get();
1368 } 1379 }
1369 1380
1370 ServiceWorkerDiskCache* ServiceWorkerStorage::disk_cache() { 1381 ServiceWorkerDiskCache* ServiceWorkerStorage::disk_cache() {
1382 DCHECK_EQ(INITIALIZED, state_);
1371 if (disk_cache_) 1383 if (disk_cache_)
1372 return disk_cache_.get(); 1384 return disk_cache_.get();
1373 1385
1374 disk_cache_ = ServiceWorkerDiskCache::CreateWithBlockFileBackend(); 1386 disk_cache_ = ServiceWorkerDiskCache::CreateWithSimpleBackend();
1375 1387
1376 base::FilePath path = GetDiskCachePath(); 1388 if (GetDiskCachePath().empty()) {
1377 if (path.empty()) {
1378 int rv = disk_cache_->InitWithMemBackend(kMaxMemDiskCacheSize, 1389 int rv = disk_cache_->InitWithMemBackend(kMaxMemDiskCacheSize,
1379 net::CompletionCallback()); 1390 net::CompletionCallback());
1380 DCHECK_EQ(net::OK, rv); 1391 DCHECK_EQ(net::OK, rv);
1381 return disk_cache_.get(); 1392 return disk_cache_.get();
1382 } 1393 }
1383 1394
1395 if (needs_disk_cache_migration_) {
1396 // Defer the start of initialization until the migration is complete.
1397 disk_cache_->set_is_waiting_to_initialize(true);
1398 PrepareDiskCacheForMigration();
1399 return disk_cache_.get();
1400 }
1401
1402 // DiskCache has already been migrated.
1403 ServiceWorkerMetrics::RecordDiskCacheMigrationResult(
1404 ServiceWorkerMetrics::MIGRATION_NOT_NECESSARY);
1405 InitializeDiskCache();
1406
1407 return disk_cache_.get();
1408 }
1409
1410 void ServiceWorkerStorage::PrepareDiskCacheForMigration() {
1411 scoped_ptr<ServiceWorkerDiskCache> src_disk_cache =
1412 ServiceWorkerDiskCache::CreateWithBlockFileBackend();
1413 ServiceWorkerDiskCache* src_disk_cache_ptr = src_disk_cache.get();
1414 scoped_ptr<ServiceWorkerDiskCache> dest_disk_cache =
1415 ServiceWorkerDiskCache::CreateWithSimpleBackend();
1416 ServiceWorkerDiskCache* dest_disk_cache_ptr = dest_disk_cache.get();
1417 bool* is_failed = new bool(false);
1418
1419 // This closure is called when both diskcaches are initialized.
1420 base::Closure barrier_closure = base::BarrierClosure(
1421 2, base::Bind(
1422 &ServiceWorkerStorage::DidPrepareDiskCacheForMigration,
1423 weak_factory_.GetWeakPtr(), base::Passed(src_disk_cache.Pass()),
1424 base::Passed(dest_disk_cache.Pass()), base::Owned(is_failed)));
1425
1426 // Initialize the src DiskCache.
1427 net::CompletionCallback src_callback =
1428 base::Bind(&ServiceWorkerStorage::DidInitializeDiskCacheForMigration,
1429 weak_factory_.GetWeakPtr(), is_failed, barrier_closure);
1430 int result = src_disk_cache_ptr->InitWithDiskBackend(
1431 GetOldDiskCachePath(), kMaxDiskCacheSize, false /* force */,
1432 disk_cache_thread_, src_callback);
1433 if (result != net::ERR_IO_PENDING)
1434 src_callback.Run(result);
1435
1436 // Initialize the dest DiskCache.
michaeln 2015/06/08 21:36:33 Since a migration attempt can be started multiple
nhiroki 2015/06/09 15:41:56 Done.
1437 net::CompletionCallback dest_callback =
1438 base::Bind(&ServiceWorkerStorage::DidInitializeDiskCacheForMigration,
1439 weak_factory_.GetWeakPtr(), is_failed, barrier_closure);
1440 result = dest_disk_cache_ptr->InitWithDiskBackend(
1441 GetDiskCachePath(), kMaxDiskCacheSize, false /* force */,
1442 disk_cache_thread_, dest_callback);
1443 if (result != net::ERR_IO_PENDING)
1444 dest_callback.Run(result);
1445 }
1446
1447 void ServiceWorkerStorage::DidInitializeDiskCacheForMigration(
1448 bool* is_failed,
1449 const base::Closure& barrier_closure,
1450 int result) {
1451 if (result != net::OK)
1452 *is_failed = true;
1453 barrier_closure.Run();
1454 }
1455
1456 void ServiceWorkerStorage::DidPrepareDiskCacheForMigration(
1457 scoped_ptr<ServiceWorkerDiskCache> src_disk_cache,
1458 scoped_ptr<ServiceWorkerDiskCache> dest_disk_cache,
1459 bool* is_failed) {
1460 if (*is_failed) {
1461 LOG(ERROR) << "Failed to initialize the diskcache.";
1462 src_disk_cache.reset();
1463 dest_disk_cache.reset();
1464 AbortDiskCacheMigration(ServiceWorkerMetrics::MIGRATION_ERROR_INITIALIZE);
1465 return;
1466 }
1467
1468 // Start migrating resources stored in the src DiskCache.
1469 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator(
1470 new ServiceWorkerDiskCacheMigrator(src_disk_cache.get(),
1471 dest_disk_cache.get()));
1472 ServiceWorkerDiskCacheMigrator* migrator_ptr = migrator.get();
1473 migrator_ptr->Start(base::Bind(
michaeln 2015/06/08 21:36:33 The migrator will continue to run even after Servi
nhiroki 2015/06/09 15:41:56 I changed the storage to own the migrator. When th
1474 &ServiceWorkerStorage::DidMigrateDiskCache, weak_factory_.GetWeakPtr(),
1475 base::Passed(migrator.Pass()), base::Passed(src_disk_cache.Pass()),
1476 base::Passed(dest_disk_cache.Pass())));
michaeln 2015/06/08 21:36:33 having ownership of src and dst bound into the clo
nhiroki 2015/06/09 15:41:57 Moved the initialization code from storage to migr
1477 }
1478
1479 void ServiceWorkerStorage::DidMigrateDiskCache(
1480 scoped_ptr<ServiceWorkerDiskCacheMigrator> migrator,
1481 scoped_ptr<ServiceWorkerDiskCache> src_disk_cache,
1482 scoped_ptr<ServiceWorkerDiskCache> dest_disk_cache,
1483 ServiceWorkerStatusCode status) {
1484 migrator.reset();
1485 src_disk_cache.reset();
1486 dest_disk_cache.reset();
1487
1488 if (status != SERVICE_WORKER_OK) {
1489 LOG(ERROR) << "Failed to migrate the diskcache: "
1490 << ServiceWorkerStatusToString(status);
1491 AbortDiskCacheMigration(ServiceWorkerMetrics::MIGRATION_ERROR_FAILED);
1492 return;
1493 }
1494
1495 // Delete the old DiskCache directory.
1496 PostTaskAndReplyWithResult(
1497 disk_cache_thread_.get(), FROM_HERE,
1498 base::Bind(&base::DeleteFile, GetOldDiskCachePath(), true),
1499 base::Bind(&ServiceWorkerStorage::DidDeleteOldDiskCache,
1500 weak_factory_.GetWeakPtr()));
1501 }
1502
1503 void ServiceWorkerStorage::DidDeleteOldDiskCache(bool deleted) {
1504 if (!deleted) {
1505 LOG(ERROR) << "Failed to delete the old diskcache directory";
1506 AbortDiskCacheMigration(
michaeln 2015/06/08 21:36:33 Seems unfortunate to let this error prevent migrat
nhiroki 2015/06/09 15:41:57 Changed this sequence. The latest patchset records
1507 ServiceWorkerMetrics::MIGRATION_ERROR_DELETE_DISK_CACHE);
1508 return;
1509 }
1510 ServiceWorkerMetrics::RecordDiskCacheMigrationResult(
1511 ServiceWorkerMetrics::MIGRATION_OK);
1512 InitializeDiskCache();
1513 }
1514
1515 void ServiceWorkerStorage::AbortDiskCacheMigration(
michaeln 2015/06/08 21:36:33 This method doesn't actually abort anything, it ha
nhiroki 2015/06/09 15:41:57 (This function is gone)
1516 ServiceWorkerMetrics::DiskCacheMigrationResult result) {
1517 ServiceWorkerMetrics::RecordDiskCacheMigrationResult(result);
1518
1519 // Give up initialization and recreate the whole storage.
1520 ScheduleDeleteAndStartOver();
1521
1522 // Delete the old disk directory because DeleteAndStartOver doesn't.
1523 disk_cache_thread_->PostTask(FROM_HERE,
1524 base::Bind(base::IgnoreResult(&base::DeleteFile),
1525 GetOldDiskCachePath(), true));
1526 }
1527
1528 void ServiceWorkerStorage::InitializeDiskCache() {
1529 disk_cache_->set_is_waiting_to_initialize(false);
1384 int rv = disk_cache_->InitWithDiskBackend( 1530 int rv = disk_cache_->InitWithDiskBackend(
1385 path, 1531 GetDiskCachePath(), kMaxDiskCacheSize, false, disk_cache_thread_,
1386 kMaxDiskCacheSize,
1387 false,
1388 disk_cache_thread_,
1389 base::Bind(&ServiceWorkerStorage::OnDiskCacheInitialized, 1532 base::Bind(&ServiceWorkerStorage::OnDiskCacheInitialized,
1390 weak_factory_.GetWeakPtr())); 1533 weak_factory_.GetWeakPtr()));
1391 if (rv != net::ERR_IO_PENDING) 1534 if (rv != net::ERR_IO_PENDING)
1392 OnDiskCacheInitialized(rv); 1535 OnDiskCacheInitialized(rv);
1393
1394 return disk_cache_.get();
1395 } 1536 }
1396 1537
1397 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) { 1538 void ServiceWorkerStorage::OnDiskCacheInitialized(int rv) {
1398 if (rv != net::OK) { 1539 if (rv != net::OK) {
1399 LOG(ERROR) << "Failed to open the serviceworker diskcache: " 1540 LOG(ERROR) << "Failed to open the serviceworker diskcache: "
1400 << net::ErrorToString(rv); 1541 << net::ErrorToString(rv);
1401 ScheduleDeleteAndStartOver(); 1542 ScheduleDeleteAndStartOver();
1402 } 1543 }
1403 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK); 1544 ServiceWorkerMetrics::CountInitDiskCacheResult(rv == net::OK);
1404 } 1545 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 ids.clear(); 1668 ids.clear();
1528 status = database->GetPurgeableResourceIds(&ids); 1669 status = database->GetPurgeableResourceIds(&ids);
1529 original_task_runner->PostTask( 1670 original_task_runner->PostTask(
1530 FROM_HERE, 1671 FROM_HERE,
1531 base::Bind(callback, std::vector<int64>(ids.begin(), ids.end()), status)); 1672 base::Bind(callback, std::vector<int64>(ids.begin(), ids.end()), status));
1532 } 1673 }
1533 1674
1534 void ServiceWorkerStorage::ReadInitialDataFromDB( 1675 void ServiceWorkerStorage::ReadInitialDataFromDB(
1535 ServiceWorkerDatabase* database, 1676 ServiceWorkerDatabase* database,
1536 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 1677 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
1678 const base::FilePath& old_disk_cache_path,
1537 const InitializeCallback& callback) { 1679 const InitializeCallback& callback) {
1538 DCHECK(database); 1680 DCHECK(database);
1539 scoped_ptr<ServiceWorkerStorage::InitialData> data( 1681 scoped_ptr<ServiceWorkerStorage::InitialData> data(
1540 new ServiceWorkerStorage::InitialData()); 1682 new ServiceWorkerStorage::InitialData());
1541 1683
1542 ServiceWorkerDatabase::Status status = 1684 ServiceWorkerDatabase::Status status =
1543 database->GetNextAvailableIds(&data->next_registration_id, 1685 database->GetNextAvailableIds(&data->next_registration_id,
1544 &data->next_version_id, 1686 &data->next_version_id,
1545 &data->next_resource_id); 1687 &data->next_resource_id);
1546 if (status != ServiceWorkerDatabase::STATUS_OK) { 1688 if (status != ServiceWorkerDatabase::STATUS_OK) {
1547 original_task_runner->PostTask( 1689 original_task_runner->PostTask(
1548 FROM_HERE, base::Bind(callback, base::Owned(data.release()), status)); 1690 FROM_HERE, base::Bind(callback, base::Owned(data.release()),
1691 false /* needs_disk_cache_migration */, status));
1549 return; 1692 return;
1550 } 1693 }
1551 1694
1695 bool needs_disk_cache_migration = false;
1696 if (!old_disk_cache_path.empty())
1697 needs_disk_cache_migration = base::DirectoryExists(old_disk_cache_path);
michaeln 2015/06/08 21:36:33 I'm wondering about pathological cases where migra
nhiroki 2015/06/09 15:41:57 Added INITDATA_DISKCACHE_VERSION field in the data
1698
1552 status = database->GetOriginsWithRegistrations(&data->origins); 1699 status = database->GetOriginsWithRegistrations(&data->origins);
1553 original_task_runner->PostTask( 1700 original_task_runner->PostTask(
1554 FROM_HERE, base::Bind(callback, base::Owned(data.release()), status)); 1701 FROM_HERE, base::Bind(callback, base::Owned(data.release()),
1702 needs_disk_cache_migration, status));
1555 } 1703 }
1556 1704
1557 void ServiceWorkerStorage::DeleteRegistrationFromDB( 1705 void ServiceWorkerStorage::DeleteRegistrationFromDB(
1558 ServiceWorkerDatabase* database, 1706 ServiceWorkerDatabase* database,
1559 scoped_refptr<base::SequencedTaskRunner> original_task_runner, 1707 scoped_refptr<base::SequencedTaskRunner> original_task_runner,
1560 int64 registration_id, 1708 int64 registration_id,
1561 const GURL& origin, 1709 const GURL& origin,
1562 const DeleteRegistrationCallback& callback) { 1710 const DeleteRegistrationCallback& callback) {
1563 DCHECK(database); 1711 DCHECK(database);
1564 1712
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1959 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1812 return; 1960 return;
1813 } 1961 }
1814 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1962 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1815 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 1963 ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
1816 ServiceWorkerMetrics::DELETE_OK); 1964 ServiceWorkerMetrics::DELETE_OK);
1817 callback.Run(SERVICE_WORKER_OK); 1965 callback.Run(SERVICE_WORKER_OK);
1818 } 1966 }
1819 1967
1820 } // namespace content 1968 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698