| 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" |
| 15 #include "net/url_request/url_request_context.h" |
| 14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 15 | 17 |
| 16 namespace appcache { | 18 namespace appcache { |
| 17 | 19 |
| 18 class AppCache; | 20 class AppCache; |
| 19 class AppCacheBackendImpl; | 21 class AppCacheBackendImpl; |
| 20 class AppCacheGroup; | 22 class AppCacheGroup; |
| 21 | 23 |
| 22 // Class that manages the application cache service. Sends notifications | 24 // Class that manages the application cache service. Sends notifications |
| 23 // to many frontends. One instance per user-profile. | 25 // to many frontends. One instance per user-profile. Each instance has |
| 26 // exclusive access to it's cache_directory on disk. |
| 24 class AppCacheService { | 27 class AppCacheService { |
| 25 public: | 28 public: |
| 29 AppCacheService(); |
| 26 virtual ~AppCacheService(); | 30 virtual ~AppCacheService(); |
| 27 | 31 |
| 28 void Initialize(const FilePath& cache_directory); | 32 void Initialize(const FilePath& cache_directory); |
| 29 | 33 |
| 34 // Context for use during cache updates, should only be accessed |
| 35 // on the IO thread. |
| 36 URLRequestContext* request_context() { return request_context_.get(); } |
| 37 void set_request_context(URLRequestContext* context) { |
| 38 // TODO(michaeln): need to look into test failures that occur |
| 39 // when take this reference? Stubbing out for now. |
| 40 // request_context_ = context; |
| 41 } |
| 42 |
| 30 // TODO(jennb): API to set service settings, like file paths for storage | 43 // TODO(jennb): API to set service settings, like file paths for storage |
| 31 | 44 |
| 32 // track which processes are using this appcache service | 45 // track which processes are using this appcache service |
| 33 void RegisterBackend(AppCacheBackendImpl* backend_impl); | 46 void RegisterBackend(AppCacheBackendImpl* backend_impl); |
| 34 void UnregisterBackend(AppCacheBackendImpl* backend_impl); | 47 void UnregisterBackend(AppCacheBackendImpl* backend_impl); |
| 35 | 48 |
| 36 void AddCache(AppCache* cache); | 49 void AddCache(AppCache* cache); |
| 37 void RemoveCache(AppCache* cache); | 50 void RemoveCache(AppCache* cache); |
| 38 void AddGroup(AppCacheGroup* group); | 51 void AddGroup(AppCacheGroup* group); |
| 39 void RemoveGroup(AppCacheGroup* group); | 52 void RemoveGroup(AppCacheGroup* group); |
| 40 | 53 |
| 41 AppCacheBackendImpl* GetBackend(int id) { | 54 AppCacheBackendImpl* GetBackend(int id) { |
| 42 BackendMap::iterator it = backends_.find(id); | 55 BackendMap::iterator it = backends_.find(id); |
| 43 return (it != backends_.end()) ? it->second : NULL; | 56 return (it != backends_.end()) ? it->second : NULL; |
| 44 } | 57 } |
| 45 | 58 |
| 46 AppCache* GetCache(int64 id) { | 59 AppCache* GetCache(int64 id) { |
| 47 CacheMap::iterator it = caches_.find(id); | 60 CacheMap::iterator it = caches_.find(id); |
| 48 return (it != caches_.end()) ? it->second : NULL; | 61 return (it != caches_.end()) ? it->second : NULL; |
| 49 } | 62 } |
| 50 | 63 |
| 51 AppCacheGroup* GetGroup(const GURL& manifest_url) { | 64 AppCacheGroup* GetGroup(const GURL& manifest_url) { |
| 52 GroupMap::iterator it = groups_.find(manifest_url); | 65 GroupMap::iterator it = groups_.find(manifest_url); |
| 53 return (it != groups_.end()) ? it->second : NULL; | 66 return (it != groups_.end()) ? it->second : NULL; |
| 54 } | 67 } |
| 55 | 68 |
| 69 // The service generates unique storage ids for different object types. |
| 70 int64 NewCacheId() { return ++last_cache_id_; } |
| 71 int64 NewGroupId() { return ++last_group_id_; } |
| 72 int64 NewEntryId() { return ++last_entry_id_; } |
| 73 int64 NewResponseId() { return ++last_response_id_; } |
| 74 |
| 56 private: | 75 private: |
| 57 // In-memory representation of stored appcache data. Represents a subset | 76 // In-memory representation of stored appcache data. Represents a subset |
| 58 // of the appcache database currently in use. | 77 // of the appcache database currently in use. |
| 59 typedef base::hash_map<int64, AppCache*> CacheMap; | 78 typedef base::hash_map<int64, AppCache*> CacheMap; |
| 60 typedef std::map<GURL, AppCacheGroup*> GroupMap; | 79 typedef std::map<GURL, AppCacheGroup*> GroupMap; |
| 61 CacheMap caches_; | 80 CacheMap caches_; |
| 62 GroupMap groups_; | 81 GroupMap groups_; |
| 63 | 82 |
| 83 // The last storage id used for different object types. |
| 84 int64 last_cache_id_; |
| 85 int64 last_group_id_; |
| 86 int64 last_entry_id_; |
| 87 int64 last_response_id_; |
| 88 |
| 64 // Track current processes. One 'backend' per child process. | 89 // Track current processes. One 'backend' per child process. |
| 65 typedef std::map<int, AppCacheBackendImpl*> BackendMap; | 90 typedef std::map<int, AppCacheBackendImpl*> BackendMap; |
| 66 BackendMap backends_; | 91 BackendMap backends_; |
| 67 | 92 |
| 68 FilePath cache_directory_; | 93 FilePath cache_directory_; |
| 94 |
| 95 // Context for use during cache updates. |
| 96 scoped_refptr<URLRequestContext> request_context_; |
| 97 |
| 69 // TODO(jennb): info about appcache storage | 98 // TODO(jennb): info about appcache storage |
| 70 // AppCacheDatabase db_; | 99 // AppCacheDatabase db_; |
| 71 // DiskCache response_storage_; | 100 // DiskCache response_storage_; |
| 72 | 101 |
| 73 // TODO(jennb): service settings: e.g. max size of app cache? | |
| 74 // TODO(jennb): service state: e.g. reached quota? | 102 // TODO(jennb): service state: e.g. reached quota? |
| 75 }; | 103 }; |
| 76 | 104 |
| 77 } // namespace appcache | 105 } // namespace appcache |
| 78 | 106 |
| 79 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ | 107 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ |
| OLD | NEW |