[email protected] | e16b8af7 | 2011-03-21 22:11:42 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 7 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 14c1c23 | 2013-06-11 17:52:44 | [diff] [blame] | 10 | #include "base/containers/hash_tables.h" |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 11 | #include "content/browser/appcache/appcache_host.h" |
| 12 | #include "content/common/content_export.h" |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 13 | |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 14 | namespace content { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 15 | |
[email protected] | 63ef8551 | 2014-06-05 14:21:26 | [diff] [blame] | 16 | class AppCacheServiceImpl; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 17 | |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 18 | class CONTENT_EXPORT AppCacheBackendImpl { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 19 | public: |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 20 | AppCacheBackendImpl(); |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 21 | ~AppCacheBackendImpl(); |
| 22 | |
[email protected] | 63ef8551 | 2014-06-05 14:21:26 | [diff] [blame] | 23 | void Initialize(AppCacheServiceImpl* service, |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 24 | AppCacheFrontend* frontend, |
| 25 | int process_id); |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 26 | |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 27 | int process_id() const { return process_id_; } |
| 28 | |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 29 | // Methods to support the AppCacheBackend interface. A false return |
| 30 | // value indicates an invalid host_id and that no action was taken |
| 31 | // by the backend impl. |
| 32 | bool RegisterHost(int host_id); |
| 33 | bool UnregisterHost(int host_id); |
[email protected] | e16b8af7 | 2011-03-21 22:11:42 | [diff] [blame] | 34 | bool SetSpawningHostId(int host_id, int spawning_host_id); |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 35 | bool SelectCache(int host_id, |
| 36 | const GURL& document_url, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 37 | const int64_t cache_document_was_loaded_from, |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 38 | const GURL& manifest_url); |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 39 | void GetResourceList( |
| 40 | int host_id, std::vector<AppCacheResourceInfo>* resource_infos); |
[email protected] | e5390a4 | 2010-05-27 22:43:19 | [diff] [blame] | 41 | bool SelectCacheForWorker(int host_id, int parent_process_id, |
| 42 | int parent_host_id); |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 43 | bool SelectCacheForSharedWorker(int host_id, int64_t appcache_id); |
| 44 | bool MarkAsForeignEntry(int host_id, |
| 45 | const GURL& document_url, |
| 46 | int64_t cache_document_was_loaded_from); |
[email protected] | 2de5530 | 2011-10-10 22:09:58 | [diff] [blame] | 47 | bool GetStatusWithCallback(int host_id, const GetStatusCallback& callback, |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 48 | void* callback_param); |
[email protected] | 2de5530 | 2011-10-10 22:09:58 | [diff] [blame] | 49 | bool StartUpdateWithCallback(int host_id, const StartUpdateCallback& callback, |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 50 | void* callback_param); |
[email protected] | 2de5530 | 2011-10-10 22:09:58 | [diff] [blame] | 51 | bool SwapCacheWithCallback(int host_id, const SwapCacheCallback& callback, |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 52 | void* callback_param); |
| 53 | |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 54 | // Returns a pointer to a registered host. The backend retains ownership. |
| 55 | AppCacheHost* GetHost(int host_id) { |
| 56 | HostMap::iterator it = hosts_.find(host_id); |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 57 | return (it != hosts_.end()) ? (it->second) : NULL; |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 97e3edc | 2009-09-15 22:07:15 | [diff] [blame] | 60 | typedef base::hash_map<int, AppCacheHost*> HostMap; |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 61 | const HostMap& hosts() { return hosts_; } |
| 62 | |
[email protected] | 5fcb289e | 2014-02-04 00:34:19 | [diff] [blame] | 63 | // Methods to support cross site navigations. Hosts are transferred |
| 64 | // from process to process accordingly, deparented from the old |
| 65 | // processes backend and reparented to the new. |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 66 | std::unique_ptr<AppCacheHost> TransferHostOut(int host_id); |
| 67 | void TransferHostIn(int new_host_id, std::unique_ptr<AppCacheHost> host); |
[email protected] | 5fcb289e | 2014-02-04 00:34:19 | [diff] [blame] | 68 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 69 | private: |
[email protected] | 63ef8551 | 2014-06-05 14:21:26 | [diff] [blame] | 70 | AppCacheServiceImpl* service_; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 71 | AppCacheFrontend* frontend_; |
[email protected] | 23f1ef1 | 2009-09-01 22:30:30 | [diff] [blame] | 72 | int process_id_; |
| 73 | HostMap hosts_; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace |
| 77 | |
[email protected] | 98d6d456 | 2014-06-25 20:57:55 | [diff] [blame] | 78 | #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_ |