Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 | 11 |
| 12 namespace net { | |
| 13 class URLRequestContext; | |
| 14 } | |
| 15 | |
| 16 namespace webkit_blob { | |
| 17 class BlobStorageContext; | |
| 18 } | |
| 19 | |
| 12 namespace content { | 20 namespace content { |
| 13 | 21 |
| 22 class ChromeBlobStorageContext; | |
|
jkarlin
2014/08/12 19:22:15
I'll remove this.
jkarlin
2014/08/13 00:14:00
Done.
| |
| 23 | |
| 14 // TODO(jkarlin): Fill this in with a real Cache implementation as | 24 // TODO(jkarlin): Fill this in with a real Cache implementation as |
| 15 // specified in | 25 // specified in |
| 16 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. | 26 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. |
| 17 // TODO(jkarlin): Unload cache backend from memory once the cache object is no | 27 // TODO(jkarlin): Unload cache backend from memory once the cache object is no |
| 18 // longer referenced in javascript. | 28 // longer referenced in javascript. |
| 19 | 29 |
| 20 // Represents a ServiceWorker Cache as seen in | 30 // Represents a ServiceWorker Cache as seen in |
| 21 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. | 31 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. |
| 22 // InitializeIfNeeded must be called before calling the other public members. | 32 // InitializeIfNeeded must be called before calling the other public members. |
| 23 class ServiceWorkerCache { | 33 class ServiceWorkerCache { |
| 24 public: | 34 public: |
| 25 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( | 35 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( |
| 26 const std::string& name); | 36 const std::string& name, |
| 37 net::URLRequestContext* request_context, | |
| 38 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context); | |
| 27 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( | 39 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( |
| 28 const base::FilePath& path, | 40 const base::FilePath& path, |
| 29 const std::string& name); | 41 const std::string& name, |
| 42 net::URLRequestContext* request_context, | |
| 43 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context); | |
| 44 | |
| 30 virtual ~ServiceWorkerCache(); | 45 virtual ~ServiceWorkerCache(); |
| 31 | 46 |
| 32 // Loads the backend and calls the callback with the result (true for | 47 // Loads the backend and calls the callback with the result (true for |
| 33 // success). This must be called before member functions that require a | 48 // success). This must be called before member functions that require a |
| 34 // backend are called. | 49 // backend are called. |
| 35 void CreateBackend(const base::Callback<void(bool)>& callback); | 50 void CreateBackend(const base::Callback<void(bool)>& callback); |
| 36 | 51 |
| 37 void set_name(const std::string& name) { name_ = name; } | 52 void set_name(const std::string& name) { name_ = name; } |
| 38 const std::string& name() const { return name_; } | 53 const std::string& name() const { return name_; } |
| 39 int32 id() const { return id_; } | 54 int32 id() const { return id_; } |
| 40 void set_id(int32 id) { id_ = id; } | 55 void set_id(int32 id) { id_ = id; } |
| 41 | 56 |
| 42 base::WeakPtr<ServiceWorkerCache> GetWeakPtr() { | 57 base::WeakPtr<ServiceWorkerCache> GetWeakPtr() { |
| 43 return weak_ptr_factory_.GetWeakPtr(); | 58 return weak_ptr_factory_.GetWeakPtr(); |
| 44 } | 59 } |
| 45 | 60 |
| 46 private: | 61 private: |
| 47 ServiceWorkerCache(const base::FilePath& path, const std::string& name); | 62 ServiceWorkerCache( |
| 63 const base::FilePath& path, | |
| 64 const std::string& name, | |
| 65 net::URLRequestContext* request_context, | |
| 66 base::WeakPtr<webkit_blob::BlobStorageContext> blob_context); | |
| 48 | 67 |
| 49 base::FilePath path_; | 68 base::FilePath path_; |
| 50 std::string name_; | 69 std::string name_; |
| 70 net::URLRequestContext* request_context_; | |
| 71 base::WeakPtr<webkit_blob::BlobStorageContext> blob_storage_context_; | |
| 51 int32 id_; | 72 int32 id_; |
| 52 | 73 |
| 53 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; | 74 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; |
| 54 | 75 |
| 55 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); | 76 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); |
| 56 }; | 77 }; |
| 57 | 78 |
| 58 } // namespace content | 79 } // namespace content |
| 59 | 80 |
| 60 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 81 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
| OLD | NEW |