Chromium Code Reviews| 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/service_worker/service_worker_storage.h" | 5 #include "content/browser/service_worker/service_worker_storage.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 ServiceWorkerDatabase::Status status) { | 552 ServiceWorkerDatabase::Status status) { |
| 553 DCHECK(registrations); | 553 DCHECK(registrations); |
| 554 if (status != ServiceWorkerDatabase::STATUS_OK) { | 554 if (status != ServiceWorkerDatabase::STATUS_OK) { |
| 555 // TODO(nhiroki): Handle database error (http://crbug.com/371675). | 555 // TODO(nhiroki): Handle database error (http://crbug.com/371675). |
| 556 callback.Run(SERVICE_WORKER_ERROR_FAILED, | 556 callback.Run(SERVICE_WORKER_ERROR_FAILED, |
| 557 scoped_refptr<ServiceWorkerRegistration>()); | 557 scoped_refptr<ServiceWorkerRegistration>()); |
| 558 return; | 558 return; |
| 559 } | 559 } |
| 560 | 560 |
| 561 // Find one with a pattern match. | 561 // Find one with a pattern match. |
| 562 ServiceWorkerDatabase::RegistrationData match; | |
| 562 for (RegistrationList::const_iterator it = registrations->begin(); | 563 for (RegistrationList::const_iterator it = registrations->begin(); |
| 563 it != registrations->end(); ++it) { | 564 it != registrations->end(); ++it) { |
| 564 // TODO(michaeln): if there are multiple matches the one with | 565 ServiceWorkerUtils::MatchResult result = |
|
dominicc (has gone to gerrit)
2014/05/22 05:03:31
From an API design point of view would it make sen
| |
| 565 // the longest scope should win. | 566 ServiceWorkerUtils::ScopeMatches(it->scope, document_url); |
| 566 if (ServiceWorkerUtils::ScopeMatches(it->scope, document_url)) { | 567 if (result == ServiceWorkerUtils::SCOPE_NO_MATCH) |
| 567 scoped_refptr<ServiceWorkerRegistration> registration = | 568 continue; |
| 568 context_->GetLiveRegistration(it->registration_id); | 569 if (result == ServiceWorkerUtils::SCOPE_EXACT_MATCH) { |
|
jsbell
2014/05/21 19:20:03
Same as previous, exact vs. longest-wildcard
michaeln
2014/05/22 00:56:29
agree with jsbell length of scope trumps exact vs
| |
| 569 if (registration) { | 570 match = *it; |
| 570 callback.Run(SERVICE_WORKER_OK, registration); | 571 break; |
| 571 return; | 572 } |
| 572 } | 573 |
| 573 callback.Run(SERVICE_WORKER_OK, CreateRegistration(*it)); | 574 DCHECK_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, result); |
| 574 return; | 575 if (match.scope.is_empty() || |
| 576 ServiceWorkerUtils::CompareScopePriorities( | |
| 577 it->scope, match.scope) >= 0) { | |
|
jsbell
2014/05/21 19:20:03
Same: if comparison == 0, the scopes must be the s
| |
| 578 match = *it; | |
| 575 } | 579 } |
| 576 } | 580 } |
| 577 | 581 |
| 582 if (!match.scope.is_empty()) { | |
| 583 scoped_refptr<ServiceWorkerRegistration> registration = | |
| 584 context_->GetLiveRegistration(match.registration_id); | |
| 585 if (registration) { | |
| 586 callback.Run(SERVICE_WORKER_OK, registration); | |
| 587 return; | |
| 588 } | |
| 589 callback.Run(SERVICE_WORKER_OK, CreateRegistration(match)); | |
| 590 return; | |
| 591 } | |
| 592 | |
| 578 // Look for something currently being installed. | 593 // Look for something currently being installed. |
| 579 // TODO(michaeln): Should be mixed in with the stored registrations | 594 // TODO(michaeln): Should be mixed in with the stored registrations |
| 580 // for this test. | 595 // for this test. |
| 581 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 596 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
| 582 FindInstallingRegistrationForDocument(document_url); | 597 FindInstallingRegistrationForDocument(document_url); |
| 583 if (installing_registration) { | 598 if (installing_registration) { |
| 584 callback.Run(SERVICE_WORKER_OK, installing_registration); | 599 callback.Run(SERVICE_WORKER_OK, installing_registration); |
| 585 return; | 600 return; |
| 586 } | 601 } |
| 587 | 602 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 NOTREACHED(); | 740 NOTREACHED(); |
| 726 // TODO(michaeln): Hmmm, what if DeleteReg was invoked after | 741 // TODO(michaeln): Hmmm, what if DeleteReg was invoked after |
| 727 // the Find result we're returning here? NOTREACHED condition? | 742 // the Find result we're returning here? NOTREACHED condition? |
| 728 | 743 |
| 729 return registration; | 744 return registration; |
| 730 } | 745 } |
| 731 | 746 |
| 732 ServiceWorkerRegistration* | 747 ServiceWorkerRegistration* |
| 733 ServiceWorkerStorage::FindInstallingRegistrationForDocument( | 748 ServiceWorkerStorage::FindInstallingRegistrationForDocument( |
| 734 const GURL& document_url) { | 749 const GURL& document_url) { |
| 735 // TODO(michaeln): if there are multiple matches the one with | 750 ServiceWorkerRegistration* match = NULL; |
| 736 // the longest scope should win, and these should on equal footing | |
| 737 // with the stored registrations in FindRegistrationForDocument(). | |
| 738 for (RegistrationRefsById::const_iterator it = | 751 for (RegistrationRefsById::const_iterator it = |
| 739 installing_registrations_.begin(); | 752 installing_registrations_.begin(); |
| 740 it != installing_registrations_.end(); ++it) { | 753 it != installing_registrations_.end(); ++it) { |
| 741 if (ServiceWorkerUtils::ScopeMatches( | 754 ServiceWorkerUtils::MatchResult result = |
| 742 it->second->pattern(), document_url)) { | 755 ServiceWorkerUtils::ScopeMatches(it->second->pattern(), document_url); |
| 743 return it->second; | 756 if (result == ServiceWorkerUtils::SCOPE_NO_MATCH) |
| 757 continue; | |
| 758 if (result == ServiceWorkerUtils::SCOPE_EXACT_MATCH) { | |
| 759 match = it->second; | |
| 760 break; | |
| 761 } | |
| 762 | |
| 763 DCHECK_EQ(ServiceWorkerUtils::SCOPE_WILDCARD_MATCH, result); | |
| 764 if (!match || ServiceWorkerUtils::CompareScopePriorities( | |
| 765 it->second->pattern(), match->pattern()) >= 0) { | |
| 766 match = it->second; | |
| 744 } | 767 } |
| 745 } | 768 } |
| 746 return NULL; | 769 return match; |
| 747 } | 770 } |
| 748 | 771 |
| 749 ServiceWorkerRegistration* | 772 ServiceWorkerRegistration* |
| 750 ServiceWorkerStorage::FindInstallingRegistrationForPattern( | 773 ServiceWorkerStorage::FindInstallingRegistrationForPattern( |
| 751 const GURL& scope) { | 774 const GURL& scope) { |
| 752 for (RegistrationRefsById::const_iterator it = | 775 for (RegistrationRefsById::const_iterator it = |
| 753 installing_registrations_.begin(); | 776 installing_registrations_.begin(); |
| 754 it != installing_registrations_.end(); ++it) { | 777 it != installing_registrations_.end(); ++it) { |
| 755 if (it->second->pattern() == scope) | 778 if (it->second->pattern() == scope) |
| 756 return it->second; | 779 return it->second; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 775 // TODO(michaeln): Store data on disk and do error checking. | 798 // TODO(michaeln): Store data on disk and do error checking. |
| 776 disk_cache_.reset(new ServiceWorkerDiskCache); | 799 disk_cache_.reset(new ServiceWorkerDiskCache); |
| 777 int rv = disk_cache_->InitWithMemBackend( | 800 int rv = disk_cache_->InitWithMemBackend( |
| 778 kMaxMemDiskCacheSize, | 801 kMaxMemDiskCacheSize, |
| 779 base::Bind(&EmptyCompletionCallback)); | 802 base::Bind(&EmptyCompletionCallback)); |
| 780 DCHECK_EQ(net::OK, rv); | 803 DCHECK_EQ(net::OK, rv); |
| 781 return disk_cache_.get(); | 804 return disk_cache_.get(); |
| 782 } | 805 } |
| 783 | 806 |
| 784 } // namespace content | 807 } // namespace content |
| OLD | NEW |