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

Side by Side Diff: webkit/appcache/appcache_service.h

Issue 192043: AppCacheHost cache selection algorithm (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_request_handler.cc ('k') | webkit/appcache/appcache_service.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 (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 "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 18
18 namespace appcache { 19 namespace appcache {
19 20
20 class AppCache; 21 class AppCache;
21 class AppCacheBackendImpl; 22 class AppCacheBackendImpl;
22 class AppCacheGroup; 23 class AppCacheGroup;
23 24
24 // Class that manages the application cache service. Sends notifications 25 // Class that manages the application cache service. Sends notifications
25 // to many frontends. One instance per user-profile. Each instance has 26 // to many frontends. One instance per user-profile. Each instance has
26 // exclusive access to it's cache_directory on disk. 27 // exclusive access to it's cache_directory on disk.
27 class AppCacheService { 28 class AppCacheService {
28 public: 29 public:
30
31 class LoadClient {
32 public:
33 virtual ~LoadClient() {}
34
35 // If a load fails the object pointer will be NULL.
36 virtual void CacheLoadedCallback(AppCache* cache, int64 cache_id) = 0;
37 virtual void GroupLoadedCallback(AppCacheGroup* cache,
38 const GURL& manifest_url) = 0;
39 };
40
29 AppCacheService(); 41 AppCacheService();
30 virtual ~AppCacheService(); 42 virtual ~AppCacheService();
31 43
32 void Initialize(const FilePath& cache_directory); 44 void Initialize(const FilePath& cache_directory);
33 45
34 // Context for use during cache updates, should only be accessed 46 // Context for use during cache updates, should only be accessed
35 // on the IO thread. 47 // on the IO thread.
36 URLRequestContext* request_context() { return request_context_.get(); } 48 URLRequestContext* request_context() { return request_context_.get(); }
37 void set_request_context(URLRequestContext* context) { 49 void set_request_context(URLRequestContext* context) {
38 // TODO(michaeln): need to look into test failures that occur 50 // TODO(michaeln): need to look into test failures that occur
39 // when we take this reference? Stubbing out for now. 51 // when we take this reference? Stubbing out for now.
40 // request_context_ = context; 52 // request_context_ = context;
41 } 53 }
42 54
43 // 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
44 56
45 // track which processes are using this appcache service 57 // Track which processes are using this appcache service.
46 void RegisterBackend(AppCacheBackendImpl* backend_impl); 58 void RegisterBackend(AppCacheBackendImpl* backend_impl);
47 void UnregisterBackend(AppCacheBackendImpl* backend_impl); 59 void UnregisterBackend(AppCacheBackendImpl* backend_impl);
48
49 void AddCache(AppCache* cache);
50 void RemoveCache(AppCache* cache);
51 void AddGroup(AppCacheGroup* group);
52 void RemoveGroup(AppCacheGroup* group);
53
54 AppCacheBackendImpl* GetBackend(int id) { 60 AppCacheBackendImpl* GetBackend(int id) {
55 BackendMap::iterator it = backends_.find(id); 61 BackendMap::iterator it = backends_.find(id);
56 return (it != backends_.end()) ? it->second : NULL; 62 return (it != backends_.end()) ? it->second : NULL;
57 } 63 }
58 64
65 // Track what we have in or in-memory cache.
66 void AddCache(AppCache* cache);
67 void RemoveCache(AppCache* cache);
68 void AddGroup(AppCacheGroup* group);
69 void RemoveGroup(AppCacheGroup* group);
59 AppCache* GetCache(int64 id) { 70 AppCache* GetCache(int64 id) {
60 CacheMap::iterator it = caches_.find(id); 71 CacheMap::iterator it = caches_.find(id);
61 return (it != caches_.end()) ? it->second : NULL; 72 return (it != caches_.end()) ? it->second : NULL;
62 } 73 }
63
64 AppCacheGroup* GetGroup(const GURL& manifest_url) { 74 AppCacheGroup* GetGroup(const GURL& manifest_url) {
65 GroupMap::iterator it = groups_.find(manifest_url); 75 GroupMap::iterator it = groups_.find(manifest_url);
66 return (it != groups_.end()) ? it->second : NULL; 76 return (it != groups_.end()) ? it->second : NULL;
67 } 77 }
68 78
79 // Load caches and groups from storage. If the request object
80 // is already in memory, the client is called immediately
81 // without returning to the message loop.
82 void LoadCache(int64 id, LoadClient* client);
83 void LoadOrCreateGroup(const GURL& manifest_url,
84 LoadClient* client);
85
86 // Cancels pending callbacks for this client.
87 void CancelLoads(LoadClient* client);
88
89 // Updates in memory and persistent storage.
90 void MarkAsForeignEntry(const GURL& entry_url, int64 cache_id);
91
69 // The service generates unique storage ids for different object types. 92 // The service generates unique storage ids for different object types.
70 int64 NewCacheId() { return ++last_cache_id_; } 93 int64 NewCacheId() { return ++last_cache_id_; }
71 int64 NewGroupId() { return ++last_group_id_; } 94 int64 NewGroupId() { return ++last_group_id_; }
72 int64 NewEntryId() { return ++last_entry_id_; } 95 int64 NewEntryId() { return ++last_entry_id_; }
73 int64 NewResponseId() { return ++last_response_id_; } 96 int64 NewResponseId() { return ++last_response_id_; }
74 97
75 private: 98 private:
76 // In-memory representation of stored appcache data. Represents a subset 99 // In-memory representation of stored appcache data. Represents a subset
77 // of the appcache database currently in use. 100 // of the appcache database currently in use.
78 typedef base::hash_map<int64, AppCache*> CacheMap; 101 typedef base::hash_map<int64, AppCache*> CacheMap;
79 typedef std::map<GURL, AppCacheGroup*> GroupMap; 102 typedef std::map<GURL, AppCacheGroup*> GroupMap;
80 CacheMap caches_; 103 CacheMap caches_;
81 GroupMap groups_; 104 GroupMap groups_;
82 105
83 // The last storage id used for different object types. 106 // The last storage id used for different object types.
84 int64 last_cache_id_; 107 int64 last_cache_id_;
85 int64 last_group_id_; 108 int64 last_group_id_;
86 int64 last_entry_id_; 109 int64 last_entry_id_;
87 int64 last_response_id_; 110 int64 last_response_id_;
88 111
89 // Track current processes. One 'backend' per child process. 112 // Track current processes. One 'backend' per child process.
90 typedef std::map<int, AppCacheBackendImpl*> BackendMap; 113 typedef std::map<int, AppCacheBackendImpl*> BackendMap;
91 BackendMap backends_; 114 BackendMap backends_;
92 115
116 // Where we save our data.
93 FilePath cache_directory_; 117 FilePath cache_directory_;
94 118
95 // Context for use during cache updates. 119 // Context for use during cache updates.
96 scoped_refptr<URLRequestContext> request_context_; 120 scoped_refptr<URLRequestContext> request_context_;
97 121
98 // TODO(jennb): info about appcache storage 122 // TODO(michaeln): cache and group loading book keeping.
99 // AppCacheDatabase db_; 123 // TODO(michaeln): database and response storage
100 // DiskCache response_storage_;
101
102 // TODO(jennb): service state: e.g. reached quota? 124 // TODO(jennb): service state: e.g. reached quota?
103 }; 125 };
104 126
105 } // namespace appcache 127 } // namespace appcache
106 128
107 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_ 129 #endif // WEBKIT_APPCACHE_APPCACHE_SERVICE_H_
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_request_handler.cc ('k') | webkit/appcache/appcache_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698