- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / appcache / appcache_dispatcher_host.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_
7
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/process/process.h"
13 #include "content/browser/appcache/appcache_frontend_proxy.h"
14 #include "content/public/browser/browser_message_filter.h"
15 #include "webkit/browser/appcache/appcache_backend_impl.h"
16
17 namespace content {
18 class ChromeAppCacheService;
19
20 // Handles appcache related messages sent to the main browser process from
21 // its child processes. There is a distinct host for each child process.
22 // Messages are handled on the IO thread. The BrowserRenderProcessHost and
23 // WorkerProcessHost create an instance and delegates calls to it.
24 class AppCacheDispatcherHost : public BrowserMessageFilter {
25  public:
26   AppCacheDispatcherHost(ChromeAppCacheService* appcache_service,
27                          int process_id);
28
29   // BrowserIOMessageFilter implementation
30   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
31   virtual bool OnMessageReceived(const IPC::Message& message,
32                                  bool* message_was_ok) OVERRIDE;
33
34  protected:
35   virtual ~AppCacheDispatcherHost();
36
37   // BrowserMessageFilter override.
38   virtual void BadMessageReceived() OVERRIDE;
39
40  private:
41   // IPC message handlers
42   void OnRegisterHost(int host_id);
43   void OnUnregisterHost(int host_id);
44   void OnSetSpawningHostId(int host_id, int spawning_host_id);
45   void OnSelectCache(int host_id, const GURL& document_url,
46                      int64 cache_document_was_loaded_from,
47                      const GURL& opt_manifest_url);
48   void OnSelectCacheForWorker(int host_id, int parent_process_id,
49                               int parent_host_id);
50   void OnSelectCacheForSharedWorker(int host_id, int64 appcache_id);
51   void OnMarkAsForeignEntry(int host_id, const GURL& document_url,
52                             int64 cache_document_was_loaded_from);
53   void OnGetStatus(int host_id, IPC::Message* reply_msg);
54   void OnStartUpdate(int host_id, IPC::Message* reply_msg);
55   void OnSwapCache(int host_id, IPC::Message* reply_msg);
56   void OnGetResourceList(
57       int host_id,
58       std::vector<appcache::AppCacheResourceInfo>* resource_infos);
59   void GetStatusCallback(appcache::Status status, void* param);
60   void StartUpdateCallback(bool result, void* param);
61   void SwapCacheCallback(bool result, void* param);
62
63
64   scoped_refptr<ChromeAppCacheService> appcache_service_;
65   AppCacheFrontendProxy frontend_proxy_;
66   appcache::AppCacheBackendImpl backend_impl_;
67
68   appcache::GetStatusCallback get_status_callback_;
69   appcache::StartUpdateCallback start_update_callback_;
70   appcache::SwapCacheCallback swap_cache_callback_;
71   scoped_ptr<IPC::Message> pending_reply_msg_;
72
73   // The corresponding ChildProcessHost object's id().
74   int process_id_;
75
76   DISALLOW_COPY_AND_ASSIGN(AppCacheDispatcherHost);
77 };
78
79 }  // namespace content
80
81 #endif  // CONTENT_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_