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

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

Issue 189253002: Implement ServiceWorker::postMessage() [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback Created 6 years, 9 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 | Annotate | Revision Log
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 <string> 7 #include <string>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (PatternMatches(it->first, document_url)) { 74 if (PatternMatches(it->first, document_url)) {
75 status = SERVICE_WORKER_OK; 75 status = SERVICE_WORKER_OK;
76 found = it->second; 76 found = it->second;
77 break; 77 break;
78 } 78 }
79 } 79 }
80 // Always simulate asynchronous call for now. 80 // Always simulate asynchronous call for now.
81 RunSoon(base::Bind(callback, status, found)); 81 RunSoon(base::Bind(callback, status, found));
82 } 82 }
83 83
84 void ServiceWorkerStorage::FindRegistrationForId(
85 int64 registration_id,
86 const FindRegistrationCallback& callback) {
87 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_NOT_FOUND;
88 scoped_refptr<ServiceWorkerRegistration> found;
89 for (PatternToRegistrationMap::const_iterator it =
90 registration_by_pattern_.begin();
91 it != registration_by_pattern_.end();
92 ++it) {
93 if (registration_id == it->second->id()) {
94 status = SERVICE_WORKER_OK;
95 found = it->second;
96 break;
97 }
98 }
99 RunSoon(base::Bind(callback, status, found));
100 }
101
84 void ServiceWorkerStorage::StoreRegistration( 102 void ServiceWorkerStorage::StoreRegistration(
85 ServiceWorkerRegistration* registration, 103 ServiceWorkerRegistration* registration,
86 const StatusCallback& callback) { 104 const StatusCallback& callback) {
87 DCHECK(registration); 105 DCHECK(registration);
88 106
89 PatternToRegistrationMap::const_iterator current( 107 PatternToRegistrationMap::const_iterator current(
90 registration_by_pattern_.find(registration->pattern())); 108 registration_by_pattern_.find(registration->pattern()));
91 if (current != registration_by_pattern_.end() && 109 if (current != registration_by_pattern_.end() &&
92 current->second->script_url() != registration->script_url()) { 110 current->second->script_url() != registration->script_url()) {
93 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_EXISTS)); 111 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_EXISTS));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Temporarily borrowed directly from appcache::Namespace::IsMatch(). 146 // Temporarily borrowed directly from appcache::Namespace::IsMatch().
129 // We have to escape '?' characters since MatchPattern also treats those 147 // We have to escape '?' characters since MatchPattern also treats those
130 // as wildcards which we don't want here, we only do '*'s. 148 // as wildcards which we don't want here, we only do '*'s.
131 std::string pattern_spec(pattern.spec()); 149 std::string pattern_spec(pattern.spec());
132 if (pattern.has_query()) 150 if (pattern.has_query())
133 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?"); 151 ReplaceSubstringsAfterOffset(&pattern_spec, 0, "?", "\\?");
134 return MatchPattern(url.spec(), pattern_spec); 152 return MatchPattern(url.spec(), pattern_spec);
135 } 153 }
136 154
137 } // namespace content 155 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698