15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_
6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h"
9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/appcache/appcache_host.h"
10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/common/content_export.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace content {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class AppCacheServiceImpl;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass CONTENT_EXPORT AppCacheBackendImpl {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AppCacheBackendImpl();
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ~AppCacheBackendImpl();
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void Initialize(AppCacheServiceImpl* service,
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  AppCacheFrontend* frontend,
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  int process_id);
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int process_id() const { return process_id_; }
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Methods to support the AppCacheBackend interface. A false return
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // value indicates an invalid host_id and that no action was taken
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // by the backend impl.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool RegisterHost(int host_id);
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool UnregisterHost(int host_id);
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetSpawningHostId(int host_id, int spawning_host_id);
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SelectCache(int host_id,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const GURL& document_url,
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const int64 cache_document_was_loaded_from,
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const GURL& manifest_url);
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetResourceList(
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int host_id, std::vector<AppCacheResourceInfo>* resource_infos);
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SelectCacheForWorker(int host_id, int parent_process_id,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int parent_host_id);
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SelectCacheForSharedWorker(int host_id, int64 appcache_id);
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool MarkAsForeignEntry(int host_id, const GURL& document_url,
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          int64 cache_document_was_loaded_from);
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetStatusWithCallback(int host_id, const GetStatusCallback& callback,
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             void* callback_param);
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool StartUpdateWithCallback(int host_id, const StartUpdateCallback& callback,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               void* callback_param);
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SwapCacheWithCallback(int host_id, const SwapCacheCallback& callback,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             void* callback_param);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a pointer to a registered host. The backend retains ownership.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AppCacheHost* GetHost(int host_id) {
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HostMap::iterator it = hosts_.find(host_id);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return (it != hosts_.end()) ? (it->second) : NULL;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::hash_map<int, AppCacheHost*> HostMap;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HostMap& hosts() { return hosts_; }
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Methods to support cross site navigations. Hosts are transferred
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // from process to process accordingly, deparented from the old
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // processes backend and reparented to the new.
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<AppCacheHost> TransferHostOut(int host_id);
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void TransferHostIn(int new_host_id, scoped_ptr<AppCacheHost> host);
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  AppCacheServiceImpl* service_;
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AppCacheFrontend* frontend_;
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int process_id_;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HostMap hosts_;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif  // CONTENT_BROWSER_APPCACHE_APPCACHE_BACKEND_IMPL_H_
76