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

Side by Side Diff: content/browser/service_worker/service_worker_disk_cache_migrator.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: address 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_disk_cache_migrator.h" 5 #include "content/browser/service_worker/service_worker_disk_cache_migrator.h"
6 6
7 #include "base/barrier_closure.h" 7 #include "base/barrier_closure.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/time/time.h"
13 #include "content/common/service_worker/service_worker_types.h" 15 #include "content/common/service_worker/service_worker_types.h"
14 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
15 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
16 #include "net/disk_cache/disk_cache.h" 18 #include "net/disk_cache/disk_cache.h"
17 19
18 namespace content { 20 namespace content {
19 21
20 namespace { 22 namespace {
21 23
22 // Disk cache entry data indices (Copied from appcache_diskcache.cc). 24 // Disk cache entry data indices (Copied from appcache_diskcache.cc).
(...skipping 11 matching lines...) Expand all
34 return SERVICE_WORKER_OK; 36 return SERVICE_WORKER_OK;
35 37
36 // Android has alredy used the Simple backend. Just move the existing 38 // Android has alredy used the Simple backend. Just move the existing
37 // diskcache files to a new location. 39 // diskcache files to a new location.
38 if (base::Move(src_path, dest_path)) 40 if (base::Move(src_path, dest_path))
39 return SERVICE_WORKER_OK; 41 return SERVICE_WORKER_OK;
40 return SERVICE_WORKER_ERROR_FAILED; 42 return SERVICE_WORKER_ERROR_FAILED;
41 } 43 }
42 #endif // defined(OS_ANDROID) 44 #endif // defined(OS_ANDROID)
43 45
46 void RecordMigrationResult(ServiceWorkerStatusCode status) {
47 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCacheMigrator.MigrationResult",
48 status, SERVICE_WORKER_ERROR_MAX_VALUE);
49 }
50
51 void RecordNumberOfMigratedResources(size_t migrated_resources) {
52 UMA_HISTOGRAM_CUSTOM_COUNTS(
53 "ServiceWorker.DiskCacheMigrator.NumberOfMigratedResources",
54 migrated_resources, 1, 1000, 50);
Alexei Svitkine (slow) 2015/06/16 15:31:15 This looks like an UMA_HISTOGRAM_COUNTS_1000, whic
nhiroki 2015/06/16 16:32:26 Done.
55 }
56
57 void RecordMigrationTime(const base::TimeDelta& time) {
58 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.DiskCacheMigrator.MigrationTime",
59 time);
60 }
61
44 } // namespace 62 } // namespace
45 63
46 // A task to move a cached resource from the src DiskCache to the dest 64 // A task to move a cached resource from the src DiskCache to the dest
47 // DiskCache. This is owned by ServiceWorkerDiskCacheMigrator. 65 // DiskCache. This is owned by ServiceWorkerDiskCacheMigrator.
48 class ServiceWorkerDiskCacheMigrator::Task { 66 class ServiceWorkerDiskCacheMigrator::Task {
49 public: 67 public:
50 Task(InflightTaskMap::KeyType task_id, 68 Task(InflightTaskMap::KeyType task_id,
51 int64 resource_id, 69 int64 resource_id,
52 int32 data_size, 70 int32 data_size,
53 ServiceWorkerDiskCache* src, 71 ServiceWorkerDiskCache* src,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 max_disk_cache_size_(max_disk_cache_size), 275 max_disk_cache_size_(max_disk_cache_size),
258 disk_cache_thread_(disk_cache_thread), 276 disk_cache_thread_(disk_cache_thread),
259 weak_factory_(this) { 277 weak_factory_(this) {
260 } 278 }
261 279
262 ServiceWorkerDiskCacheMigrator::~ServiceWorkerDiskCacheMigrator() { 280 ServiceWorkerDiskCacheMigrator::~ServiceWorkerDiskCacheMigrator() {
263 } 281 }
264 282
265 void ServiceWorkerDiskCacheMigrator::Start(const StatusCallback& callback) { 283 void ServiceWorkerDiskCacheMigrator::Start(const StatusCallback& callback) {
266 callback_ = callback; 284 callback_ = callback;
285 start_time_ = base::TimeTicks::Now();
267 286
268 #if defined(OS_ANDROID) 287 #if defined(OS_ANDROID)
269 PostTaskAndReplyWithResult( 288 PostTaskAndReplyWithResult(
270 disk_cache_thread_.get(), FROM_HERE, 289 disk_cache_thread_.get(), FROM_HERE,
271 base::Bind(&MigrateForAndroid, src_path_, dest_path_), 290 base::Bind(&MigrateForAndroid, src_path_, dest_path_),
272 base::Bind(&ServiceWorkerDiskCacheMigrator::Complete, 291 base::Bind(&ServiceWorkerDiskCacheMigrator::Complete,
273 weak_factory_.GetWeakPtr())); 292 weak_factory_.GetWeakPtr()));
274 #else 293 #else
275 PostTaskAndReplyWithResult( 294 PostTaskAndReplyWithResult(
276 disk_cache_thread_.get(), FROM_HERE, 295 disk_cache_thread_.get(), FROM_HERE,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 ServiceWorkerStatusCode status) { 429 ServiceWorkerStatusCode status) {
411 DCHECK(inflight_tasks_.Lookup(task_id)); 430 DCHECK(inflight_tasks_.Lookup(task_id));
412 inflight_tasks_.Remove(task_id); 431 inflight_tasks_.Remove(task_id);
413 432
414 if (status != SERVICE_WORKER_OK) { 433 if (status != SERVICE_WORKER_OK) {
415 inflight_tasks_.Clear(); 434 inflight_tasks_.Clear();
416 Complete(status); 435 Complete(status);
417 return; 436 return;
418 } 437 }
419 438
439 ++number_of_migrated_resources_;
440
420 if (pending_task_) { 441 if (pending_task_) {
421 RunPendingTask(); 442 RunPendingTask();
422 OpenNextEntry(); 443 OpenNextEntry();
423 return; 444 return;
424 } 445 }
425 446
426 if (is_iterating_) 447 if (is_iterating_)
427 return; 448 return;
428 449
429 if (inflight_tasks_.IsEmpty()) 450 if (inflight_tasks_.IsEmpty())
430 Complete(SERVICE_WORKER_OK); 451 Complete(SERVICE_WORKER_OK);
431 } 452 }
432 453
433 void ServiceWorkerDiskCacheMigrator::Complete(ServiceWorkerStatusCode status) { 454 void ServiceWorkerDiskCacheMigrator::Complete(ServiceWorkerStatusCode status) {
434 DCHECK(inflight_tasks_.IsEmpty()); 455 DCHECK(inflight_tasks_.IsEmpty());
435 // TODO(nhiroki): Add UMA for the result of migration. 456 if (status == SERVICE_WORKER_OK) {
457 RecordMigrationTime(base::TimeTicks().Now() - start_time_);
458 RecordNumberOfMigratedResources(number_of_migrated_resources_);
459 }
460 RecordMigrationResult(status);
436 461
437 src_.reset(); 462 src_.reset();
438 dest_.reset(); 463 dest_.reset();
439 callback_.Run(status); 464 callback_.Run(status);
440 } 465 }
441 466
442 } // namespace content 467 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698