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

Side by Side Diff: content/browser/service_worker/service_worker_cache.h

Issue 545533002: Move ServiceWorkerCache backend creation to a lazy init function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_pointers_keys
Patch Set: Rebase Created 6 years, 3 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 RequestsCallback; 52 RequestsCallback;
53 53
54 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( 54 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache(
55 net::URLRequestContext* request_context, 55 net::URLRequestContext* request_context,
56 base::WeakPtr<storage::BlobStorageContext> blob_context); 56 base::WeakPtr<storage::BlobStorageContext> blob_context);
57 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( 57 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache(
58 const base::FilePath& path, 58 const base::FilePath& path,
59 net::URLRequestContext* request_context, 59 net::URLRequestContext* request_context,
60 base::WeakPtr<storage::BlobStorageContext> blob_context); 60 base::WeakPtr<storage::BlobStorageContext> blob_context);
61 61
62 // Operations in progress will complete after the cache is deleted but pending
63 // operations (those operations waiting for init to finish) won't.
62 virtual ~ServiceWorkerCache(); 64 virtual ~ServiceWorkerCache();
63 65
64 // Loads the backend and calls the callback with the result (true for
65 // success). This must be called before member functions that require a
66 // backend are called. The callback will always be called.
67 void CreateBackend(const ErrorCallback& callback);
68
69 // Returns ErrorTypeNotFound if not found. The callback will always be called. 66 // Returns ErrorTypeNotFound if not found. The callback will always be called.
70 // |request| must remain valid until the callback is called. 67 // |request| must remain valid until the callback is called.
71 void Match(scoped_ptr<ServiceWorkerFetchRequest> request, 68 void Match(scoped_ptr<ServiceWorkerFetchRequest> request,
72 const ResponseCallback& callback); 69 const ResponseCallback& callback);
73 70
74 // Puts the request and response object in the cache. The response body (if 71 // Puts the request and response object in the cache. The response body (if
75 // present) is stored in the cache, but not the request body. Returns 72 // present) is stored in the cache, but not the request body. Returns
76 // ErrorTypeOK on success. The callback will always be called. |request| and 73 // ErrorTypeOK on success. The callback will always be called. |request| and
77 // |response| must remain valid until the callback is called. 74 // |response| must remain valid until the callback is called.
78 void Put(scoped_ptr<ServiceWorkerFetchRequest> request, 75 void Put(scoped_ptr<ServiceWorkerFetchRequest> request,
79 scoped_ptr<ServiceWorkerResponse> response, 76 scoped_ptr<ServiceWorkerResponse> response,
80 const ErrorCallback& callback); 77 const ErrorCallback& callback);
81 78
82 // Returns ErrorNotFound if not found. Otherwise deletes and returns 79 // Returns ErrorNotFound if not found. Otherwise deletes and returns
83 // ErrorTypeOK. The callback will always be called. |request| must remain 80 // ErrorTypeOK. The callback will always be called. |request| must remain
84 // valid until the callback is called. 81 // valid until the callback is called.
85 void Delete(scoped_ptr<ServiceWorkerFetchRequest> request, 82 void Delete(scoped_ptr<ServiceWorkerFetchRequest> request,
86 const ErrorCallback& callback); 83 const ErrorCallback& callback);
87 84
88 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest. 85 // TODO(jkarlin): Have keys take an optional ServiceWorkerFetchRequest.
89 // Returns ErrorTypeOK and a vector of requests if there are no errors. The 86 // Returns ErrorTypeOK and a vector of requests if there are no errors. The
90 // callback will always be called. 87 // callback will always be called.
91 void Keys(const RequestsCallback& callback); 88 void Keys(const RequestsCallback& callback);
92 89
93 // Call to determine if CreateBackend must be called.
94 bool HasCreatedBackend() const;
95
96 void set_backend(scoped_ptr<disk_cache::Backend> backend) { 90 void set_backend(scoped_ptr<disk_cache::Backend> backend) {
97 backend_ = backend.Pass(); 91 backend_ = backend.Pass();
98 } 92 }
99 93
100 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); 94 base::WeakPtr<ServiceWorkerCache> AsWeakPtr();
101 95
102 private: 96 private:
103 struct KeysContext; 97 struct KeysContext;
104 typedef std::vector<disk_cache::Entry*> Entries; 98 typedef std::vector<disk_cache::Entry*> Entries;
105 99
106 ServiceWorkerCache(const base::FilePath& path, 100 ServiceWorkerCache(const base::FilePath& path,
107 net::URLRequestContext* request_context, 101 net::URLRequestContext* request_context,
108 base::WeakPtr<storage::BlobStorageContext> blob_context); 102 base::WeakPtr<storage::BlobStorageContext> blob_context);
109 103
104 void PutImpl(scoped_ptr<ServiceWorkerFetchRequest> request,
105 scoped_ptr<ServiceWorkerResponse> response,
106 scoped_ptr<storage::BlobDataHandle> blob_data_handle,
107 const ErrorCallback& callback);
108
110 // Static callbacks for the Keys function. 109 // Static callbacks for the Keys function.
111 static void KeysDidOpenNextEntry(scoped_ptr<KeysContext> keys_context, 110 static void KeysDidOpenNextEntry(scoped_ptr<KeysContext> keys_context,
112 int rv); 111 int rv);
113 static void KeysProcessNextEntry(scoped_ptr<KeysContext> keys_context, 112 static void KeysProcessNextEntry(scoped_ptr<KeysContext> keys_context,
114 const Entries::iterator& iter); 113 const Entries::iterator& iter);
115 static void KeysDidReadHeaders( 114 static void KeysDidReadHeaders(
116 scoped_ptr<KeysContext> keys_context, 115 scoped_ptr<KeysContext> keys_context,
117 const Entries::iterator& iter, 116 const Entries::iterator& iter,
118 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers); 117 scoped_ptr<ServiceWorkerRequestResponseHeaders> headers);
119 118
119 // Loads the backend and calls the callback with the result (true for
120 // success). The callback will always be called.
121 void CreateBackend(const ErrorCallback& callback);
122
123 void Init(const base::Closure& callback);
124 void InitDone(ErrorType error);
125
120 scoped_ptr<disk_cache::Backend> backend_; 126 scoped_ptr<disk_cache::Backend> backend_;
121 base::FilePath path_; 127 base::FilePath path_;
122 net::URLRequestContext* request_context_; 128 net::URLRequestContext* request_context_;
123 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; 129 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_;
130 bool initialized_;
131 std::vector<base::Closure> init_callbacks_;
124 132
125 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; 133 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_;
126 134
127 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); 135 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache);
128 }; 136 };
129 137
130 } // namespace content 138 } // namespace content
131 139
132 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ 140 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698