OLD | NEW |
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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/metrics/histogram_macros.h" |
8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/time/time.h" |
9 #include "content/common/service_worker/service_worker_types.h" | 11 #include "content/common/service_worker/service_worker_types.h" |
10 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
12 #include "net/disk_cache/disk_cache.h" | 14 #include "net/disk_cache/disk_cache.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // Disk cache entry data indices (Copied from appcache_diskcache.cc). | 20 // Disk cache entry data indices (Copied from appcache_diskcache.cc). |
19 enum { kResponseInfoIndex, kResponseContentIndex, kResponseMetadataIndex }; | 21 enum { kResponseInfoIndex, kResponseContentIndex, kResponseMetadataIndex }; |
20 | 22 |
| 23 void RecordMigrationResult(ServiceWorkerStatusCode status) { |
| 24 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCacheMigrator.MigrationResult", |
| 25 status, SERVICE_WORKER_ERROR_MAX_VALUE); |
| 26 } |
| 27 |
| 28 void RecordNumberOfMigratedResources(size_t migrated_resources) { |
| 29 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 30 "ServiceWorker.DiskCacheMigrator.NumberOfMigratedResources", |
| 31 migrated_resources, 1, 1000, 50); |
| 32 } |
| 33 |
| 34 void RecordMigrationTime(const base::TimeDelta& time) { |
| 35 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.DiskCacheMigrator.MigrationTime", |
| 36 time); |
| 37 } |
| 38 |
21 } // namespace | 39 } // namespace |
22 | 40 |
23 // A task to move a cached resource from the src DiskCache to the dest | 41 // A task to move a cached resource from the src DiskCache to the dest |
24 // DiskCache. This is owned by ServiceWorkerDiskCacheMigrator. | 42 // DiskCache. This is owned by ServiceWorkerDiskCacheMigrator. |
25 class ServiceWorkerDiskCacheMigrator::Task { | 43 class ServiceWorkerDiskCacheMigrator::Task { |
26 public: | 44 public: |
27 Task(InflightTaskMap::KeyType task_id, | 45 Task(InflightTaskMap::KeyType task_id, |
28 int64 resource_id, | 46 int64 resource_id, |
29 int32 data_size, | 47 int32 data_size, |
30 ServiceWorkerDiskCache* src, | 48 ServiceWorkerDiskCache* src, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 DCHECK(!src_->is_disabled()); | 249 DCHECK(!src_->is_disabled()); |
232 DCHECK(!dest_->is_disabled()); | 250 DCHECK(!dest_->is_disabled()); |
233 } | 251 } |
234 | 252 |
235 ServiceWorkerDiskCacheMigrator::~ServiceWorkerDiskCacheMigrator() { | 253 ServiceWorkerDiskCacheMigrator::~ServiceWorkerDiskCacheMigrator() { |
236 } | 254 } |
237 | 255 |
238 void ServiceWorkerDiskCacheMigrator::Start(const StatusCallback& callback) { | 256 void ServiceWorkerDiskCacheMigrator::Start(const StatusCallback& callback) { |
239 callback_ = callback; | 257 callback_ = callback; |
240 iterator_ = src_->disk_cache()->CreateIterator(); | 258 iterator_ = src_->disk_cache()->CreateIterator(); |
| 259 start_time_ = base::TimeTicks::Now(); |
241 OpenNextEntry(); | 260 OpenNextEntry(); |
242 } | 261 } |
243 | 262 |
244 void ServiceWorkerDiskCacheMigrator::OpenNextEntry() { | 263 void ServiceWorkerDiskCacheMigrator::OpenNextEntry() { |
245 DCHECK(!pending_task_); | 264 DCHECK(!pending_task_); |
246 DCHECK(!is_iterating_); | 265 DCHECK(!is_iterating_); |
247 is_iterating_ = true; | 266 is_iterating_ = true; |
248 | 267 |
249 scoped_ptr<WrappedEntry> wrapped_entry(new WrappedEntry); | 268 scoped_ptr<WrappedEntry> wrapped_entry(new WrappedEntry); |
250 disk_cache::Entry** entry_ptr = wrapped_entry->GetPtr(); | 269 disk_cache::Entry** entry_ptr = wrapped_entry->GetPtr(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 ServiceWorkerStatusCode status) { | 333 ServiceWorkerStatusCode status) { |
315 DCHECK(inflight_tasks_.Lookup(task_id)); | 334 DCHECK(inflight_tasks_.Lookup(task_id)); |
316 inflight_tasks_.Remove(task_id); | 335 inflight_tasks_.Remove(task_id); |
317 | 336 |
318 if (status != SERVICE_WORKER_OK) { | 337 if (status != SERVICE_WORKER_OK) { |
319 inflight_tasks_.Clear(); | 338 inflight_tasks_.Clear(); |
320 Complete(status); | 339 Complete(status); |
321 return; | 340 return; |
322 } | 341 } |
323 | 342 |
| 343 ++number_of_migrated_resources_; |
| 344 |
324 if (pending_task_) { | 345 if (pending_task_) { |
325 RunPendingTask(); | 346 RunPendingTask(); |
326 OpenNextEntry(); | 347 OpenNextEntry(); |
327 return; | 348 return; |
328 } | 349 } |
329 | 350 |
330 if (is_iterating_) | 351 if (is_iterating_) |
331 return; | 352 return; |
332 | 353 |
333 if (inflight_tasks_.IsEmpty()) | 354 if (inflight_tasks_.IsEmpty()) |
334 Complete(SERVICE_WORKER_OK); | 355 Complete(SERVICE_WORKER_OK); |
335 } | 356 } |
336 | 357 |
337 void ServiceWorkerDiskCacheMigrator::Complete(ServiceWorkerStatusCode status) { | 358 void ServiceWorkerDiskCacheMigrator::Complete(ServiceWorkerStatusCode status) { |
338 DCHECK(inflight_tasks_.IsEmpty()); | 359 DCHECK(inflight_tasks_.IsEmpty()); |
339 // TODO(nhiroki): Add UMA for the result of migration. | 360 if (status == SERVICE_WORKER_OK) { |
| 361 RecordMigrationTime(base::TimeTicks().Now() - start_time_); |
| 362 RecordNumberOfMigratedResources(number_of_migrated_resources_); |
| 363 } |
| 364 RecordMigrationResult(status); |
340 callback_.Run(status); | 365 callback_.Run(status); |
341 } | 366 } |
342 | 367 |
343 } // namespace content | 368 } // namespace content |
OLD | NEW |