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

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

Issue 931173002: Implement EmbeddedWorkerContextClient.setCachedMetadata/clearCachedMetadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix clang failure Created 5 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_script_cache_map.h" 5 #include "content/browser/service_worker/service_worker_script_cache_map.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/service_worker/service_worker_context_core.h" 8 #include "content/browser/service_worker/service_worker_context_core.h"
9 #include "content/browser/service_worker/service_worker_disk_cache.h"
9 #include "content/browser/service_worker/service_worker_storage.h" 10 #include "content/browser/service_worker/service_worker_storage.h"
10 #include "content/browser/service_worker/service_worker_version.h" 11 #include "content/browser/service_worker/service_worker_version.h"
11 #include "content/common/service_worker/service_worker_types.h" 12 #include "content/common/service_worker/service_worker_types.h"
13 #include "net/base/io_buffer.h"
14 #include "net/base/net_errors.h"
12 15
13 namespace content { 16 namespace content {
14 17
15 ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap( 18 ServiceWorkerScriptCacheMap::ServiceWorkerScriptCacheMap(
16 ServiceWorkerVersion* owner, 19 ServiceWorkerVersion* owner,
17 base::WeakPtr<ServiceWorkerContextCore> context) 20 base::WeakPtr<ServiceWorkerContextCore> context)
18 : owner_(owner), 21 : owner_(owner), context_(context), weak_factory_(this) {
19 context_(context) {
20 } 22 }
21 23
22 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() { 24 ServiceWorkerScriptCacheMap::~ServiceWorkerScriptCacheMap() {
23 } 25 }
24 26
25 int64 ServiceWorkerScriptCacheMap::LookupResourceId(const GURL& url) { 27 int64 ServiceWorkerScriptCacheMap::LookupResourceId(const GURL& url) {
26 ResourceMap::const_iterator found = resource_map_.find(url); 28 ResourceMap::const_iterator found = resource_map_.find(url);
27 if (found == resource_map_.end()) 29 if (found == resource_map_.end())
28 return kInvalidServiceWorkerResponseId; 30 return kInvalidServiceWorkerResponseId;
29 return found->second.resource_id; 31 return found->second.resource_id;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void ServiceWorkerScriptCacheMap::SetResources( 85 void ServiceWorkerScriptCacheMap::SetResources(
84 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) { 86 const std::vector<ServiceWorkerDatabase::ResourceRecord>& resources) {
85 DCHECK(resource_map_.empty()); 87 DCHECK(resource_map_.empty());
86 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector; 88 typedef std::vector<ServiceWorkerDatabase::ResourceRecord> RecordVector;
87 for (RecordVector::const_iterator it = resources.begin(); 89 for (RecordVector::const_iterator it = resources.begin();
88 it != resources.end(); ++it) { 90 it != resources.end(); ++it) {
89 resource_map_[it->url] = *it; 91 resource_map_[it->url] = *it;
90 } 92 }
91 } 93 }
92 94
95 void ServiceWorkerScriptCacheMap::WriteMetadata(
96 const GURL& url,
97 const std::vector<char>& data,
98 const net::CompletionCallback& callback) {
99 ResourceMap::iterator found = resource_map_.find(url);
100 if (found == resource_map_.end() ||
101 found->second.resource_id == kInvalidServiceWorkerResponseId) {
102 callback.Run(net::ERR_FILE_NOT_FOUND);
103 return;
104 }
105 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(data.size()));
106 if (data.size())
107 memmove(buffer->data(), &data[0], data.size());
108 scoped_ptr<ServiceWorkerResponseMetadataWriter> writer;
109 writer = context_->storage()->CreateResponseMetadataWriter(
110 found->second.resource_id);
111 ServiceWorkerResponseMetadataWriter* raw_writer = writer.get();
112 raw_writer->WriteMetadata(
113 buffer.get(), data.size(),
114 base::Bind(&ServiceWorkerScriptCacheMap::OnMetadataWritten,
115 weak_factory_.GetWeakPtr(), Passed(&writer), callback));
116 }
117
118 void ServiceWorkerScriptCacheMap::ClearMetadata(
119 const GURL& url,
120 const net::CompletionCallback& callback) {
121 WriteMetadata(url, std::vector<char>(), callback);
122 }
123
124 void ServiceWorkerScriptCacheMap::OnMetadataWritten(
125 scoped_ptr<ServiceWorkerResponseMetadataWriter> writer,
126 const net::CompletionCallback& callback,
127 int result) {
128 callback.Run(result);
129 }
130
93 } // namespace content 131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698