| 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 | 11 |
| 11 namespace content { | 12 namespace content { |
| 12 | 13 |
| 13 // TODO(jkarlin): Fill this in with a real Cache implementation as | 14 // TODO(jkarlin): Fill this in with a real Cache implementation as |
| 14 // specified in | 15 // specified in |
| 15 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. | 16 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. |
| 16 // TODO(jkarlin): Unload cache backend from memory once the cache object is no | 17 // TODO(jkarlin): Unload cache backend from memory once the cache object is no |
| 17 // longer referenced in javascript. | 18 // longer referenced in javascript. |
| 18 | 19 |
| 19 // Represents a ServiceWorker Cache as seen in | 20 // Represents a ServiceWorker Cache as seen in |
| 20 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. | 21 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html. |
| 21 // InitializeIfNeeded must be called before calling the other public members. | 22 // InitializeIfNeeded must be called before calling the other public members. |
| 22 class ServiceWorkerCache { | 23 class ServiceWorkerCache { |
| 23 public: | 24 public: |
| 24 static ServiceWorkerCache* CreateMemoryCache(const std::string& name); | 25 static scoped_ptr<ServiceWorkerCache> CreateMemoryCache( |
| 25 static ServiceWorkerCache* CreatePersistentCache(const base::FilePath& path, | 26 const std::string& name); |
| 26 const std::string& name); | 27 static scoped_ptr<ServiceWorkerCache> CreatePersistentCache( |
| 28 const base::FilePath& path, |
| 29 const std::string& name); |
| 27 virtual ~ServiceWorkerCache(); | 30 virtual ~ServiceWorkerCache(); |
| 28 | 31 |
| 29 // Loads the backend and calls the callback with the result (true for | 32 // Loads the backend and calls the callback with the result (true for |
| 30 // success). This must be called before member functions that require a | 33 // success). This must be called before member functions that require a |
| 31 // backend are called. | 34 // backend are called. |
| 32 void CreateBackend(const base::Callback<void(bool)>& callback); | 35 void CreateBackend(const base::Callback<void(bool)>& callback); |
| 33 | 36 |
| 34 void set_name(const std::string& name) { name_ = name; } | 37 void set_name(const std::string& name) { name_ = name; } |
| 35 const std::string& name() const { return name_; } | 38 const std::string& name() const { return name_; } |
| 36 int32 id() const { return id_; } | 39 int32 id() const { return id_; } |
| 37 void set_id(int32 id) { id_ = id; } | 40 void set_id(int32 id) { id_ = id; } |
| 38 | 41 |
| 42 base::WeakPtr<ServiceWorkerCache> AsWeakPtr(); |
| 43 |
| 39 private: | 44 private: |
| 40 ServiceWorkerCache(const base::FilePath& path, const std::string& name); | 45 ServiceWorkerCache(const base::FilePath& path, const std::string& name); |
| 41 | 46 |
| 42 base::FilePath path_; | 47 base::FilePath path_; |
| 43 std::string name_; | 48 std::string name_; |
| 44 int32 id_; | 49 int32 id_; |
| 45 | 50 |
| 51 base::WeakPtrFactory<ServiceWorkerCache> weak_ptr_factory_; |
| 52 |
| 46 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); | 53 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerCache); |
| 47 }; | 54 }; |
| 48 | 55 |
| 49 } // namespace content | 56 } // namespace content |
| 50 | 57 |
| 51 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ | 58 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CACHE_H_ |
| OLD | NEW |