Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ |
| 6 #define WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ | 6 #define WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
|
michaeln
2009/09/22 01:59:12
i've removed the #include in my local copy... clas
| |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 namespace appcache { | 19 namespace appcache { |
| 20 | 20 |
| 21 class AppCache; | 21 class AppCache; |
| 22 class AppCacheBackendImpl; | 22 class AppCacheBackendImpl; |
| 23 class AppCacheGroup; | 23 class AppCacheGroup; |
| 24 | 24 |
| 25 // Class that manages the application cache service. Sends notifications | 25 // Class that manages the application cache service. Sends notifications |
| 26 // to many frontends. One instance per user-profile. Each instance has | 26 // to many frontends. One instance per user-profile. Each instance has |
| 27 // exclusive access to it's cache_directory on disk. | 27 // exclusive access to it's cache_directory on disk. |
| 28 class AppCacheService { | 28 class AppCacheService { |
| 29 public: | 29 public: |
| 30 | 30 |
| 31 class LoadClient { | 31 class LoadClient { |
| 32 public: | 32 public: |
| 33 virtual ~LoadClient() {} | 33 virtual ~LoadClient() {} |
| 34 | 34 |
| 35 // If a load fails the object pointer will be NULL. | 35 // If a load fails the object pointer will be NULL. |
| 36 virtual void CacheLoadedCallback(AppCache* cache, int64 cache_id) = 0; | 36 virtual void CacheLoadedCallback(AppCache* cache, int64 cache_id) = 0; |
| 37 virtual void GroupLoadedCallback(AppCacheGroup* cache, | 37 virtual void GroupLoadedCallback(AppCacheGroup* group, |
| 38 const GURL& manifest_url) = 0; | 38 const GURL& manifest_url) = 0; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 AppCacheService(); | 41 AppCacheService(); |
| 42 virtual ~AppCacheService(); | 42 virtual ~AppCacheService(); |
| 43 | 43 |
| 44 void Initialize(const FilePath& cache_directory); | 44 void Initialize(const FilePath& cache_directory); |
| 45 | 45 |
| 46 // Context for use during cache updates, should only be accessed | 46 // Context for use during cache updates, should only be accessed |
| 47 // on the IO thread. | 47 // on the IO thread. We do NOT add a reference to the request context, |
| 48 URLRequestContext* request_context() { return request_context_.get(); } | 48 // it is the callers responsibility to ensure that the pointer |
| 49 // remains valid while set. | |
| 50 URLRequestContext* request_context() const { return request_context_; } | |
| 49 void set_request_context(URLRequestContext* context) { | 51 void set_request_context(URLRequestContext* context) { |
| 50 // TODO(michaeln): need to look into test failures that occur | 52 request_context_ = context; |
| 51 // when we take this reference? Stubbing out for now. | |
| 52 // request_context_ = context; | |
| 53 } | 53 } |
| 54 | 54 |
| 55 // TODO(jennb): API to set service settings, like file paths for storage | 55 // TODO(jennb): API to set service settings, like file paths for storage |
| 56 | 56 |
| 57 // Track which processes are using this appcache service. | 57 // Track which processes are using this appcache service. |
| 58 void RegisterBackend(AppCacheBackendImpl* backend_impl); | 58 void RegisterBackend(AppCacheBackendImpl* backend_impl); |
| 59 void UnregisterBackend(AppCacheBackendImpl* backend_impl); | 59 void UnregisterBackend(AppCacheBackendImpl* backend_impl); |
| 60 AppCacheBackendImpl* GetBackend(int id) { | 60 AppCacheBackendImpl* GetBackend(int id) { |
| 61 BackendMap::iterator it = backends_.find(id); | 61 BackendMap::iterator it = backends_.find(id); |
| 62 return (it != backends_.end()) ? it->second : NULL; | 62 return (it != backends_.end()) ? it->second : NULL; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Track what we have in or in-memory cache. | 65 // Track what we have in our in-memory cache. |
| 66 void AddCache(AppCache* cache); | 66 void AddCache(AppCache* cache); |
| 67 void RemoveCache(AppCache* cache); | 67 void RemoveCache(AppCache* cache); |
| 68 void AddGroup(AppCacheGroup* group); | 68 void AddGroup(AppCacheGroup* group); |
| 69 void RemoveGroup(AppCacheGroup* group); | 69 void RemoveGroup(AppCacheGroup* group); |
| 70 AppCache* GetCache(int64 id) { | 70 AppCache* GetCache(int64 id) { |
| 71 CacheMap::iterator it = caches_.find(id); | 71 CacheMap::iterator it = caches_.find(id); |
| 72 return (it != caches_.end()) ? it->second : NULL; | 72 return (it != caches_.end()) ? it->second : NULL; |
| 73 } | 73 } |
| 74 AppCacheGroup* GetGroup(const GURL& manifest_url) { | 74 AppCacheGroup* GetGroup(const GURL& manifest_url) { |
| 75 GroupMap::iterator it = groups_.find(manifest_url); | 75 GroupMap::iterator it = groups_.find(manifest_url); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 int64 last_response_id_; | 110 int64 last_response_id_; |
| 111 | 111 |
| 112 // Track current processes. One 'backend' per child process. | 112 // Track current processes. One 'backend' per child process. |
| 113 typedef std::map<int, AppCacheBackendImpl*> BackendMap; | 113 typedef std::map<int, AppCacheBackendImpl*> BackendMap; |
| 114 BackendMap backends_; | 114 BackendMap backends_; |
| 115 | 115 |
| 116 // Where we save our data. | 116 // Where we save our data. |
| 117 FilePath cache_directory_; | 117 FilePath cache_directory_; |
| 118 | 118 |
| 119 // Context for use during cache updates. | 119 // Context for use during cache updates. |
| 120 scoped_refptr<URLRequestContext> request_context_; | 120 URLRequestContext* request_context_; |
| 121 | 121 |
| 122 // TODO(michaeln): cache and group loading book keeping. | 122 // TODO(michaeln): cache and group loading book keeping. |
| 123 // TODO(michaeln): database and response storage | 123 // TODO(michaeln): database and response storage |
| 124 // TODO(jennb): service state: e.g. reached quota? | 124 // TODO(jennb): service state: e.g. reached quota? |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // namespace appcache | 127 } // namespace appcache |
| 128 | 128 |
| 129 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ | 129 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ |
| OLD | NEW |