| 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 CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ |
| 6 #define CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/process.h" | 11 #include "base/process.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "chrome/browser/appcache/appcache_frontend_proxy.h" | 14 #include "chrome/browser/appcache/appcache_frontend_proxy.h" |
| 15 #include "chrome/browser/browser_io_message_filter.h" |
| 15 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 16 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 17 #include "webkit/appcache/appcache_backend_impl.h" | 18 #include "webkit/appcache/appcache_backend_impl.h" |
| 18 | 19 |
| 19 class ChromeAppCacheService; | 20 class ChromeAppCacheService; |
| 20 class URLRequestContext; | 21 class URLRequestContext; |
| 21 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
| 22 | 23 |
| 23 // Handles appcache related messages sent to the main browser process from | 24 // Handles appcache related messages sent to the main browser process from |
| 24 // its child processes. There is a distinct host for each child process. | 25 // its child processes. There is a distinct host for each child process. |
| 25 // Messages are handled on the IO thread. The ResourceMessageFilter and | 26 // Messages are handled on the IO thread. The ResourceMessageFilter and |
| 26 // WorkerProcessHost create an instance and delegates calls to it. | 27 // WorkerProcessHost create an instance and delegates calls to it. |
| 27 class AppCacheDispatcherHost { | 28 class AppCacheDispatcherHost : public BrowserIOMessageFilter { |
| 28 public: | 29 public: |
| 29 // Constructor for use on the IO thread. | 30 // Constructor for use on the IO thread. |
| 30 explicit AppCacheDispatcherHost( | 31 AppCacheDispatcherHost(URLRequestContext* request_context, |
| 31 URLRequestContext* request_context); | 32 int process_id); |
| 32 | 33 |
| 33 // Constructor for use on the UI thread. | 34 // Constructor for use on the UI thread. |
| 34 explicit AppCacheDispatcherHost( | 35 AppCacheDispatcherHost(URLRequestContextGetter* request_context_getter, |
| 35 URLRequestContextGetter* request_context_getter); | 36 int process_id); |
| 36 | 37 |
| 37 ~AppCacheDispatcherHost(); | 38 ~AppCacheDispatcherHost(); |
| 38 | 39 |
| 39 void Initialize(ResourceDispatcherHost::Receiver* receiver); | 40 // BrowserIOMessageFilter implementation |
| 40 bool OnMessageReceived(const IPC::Message& msg, bool* msg_is_ok); | 41 virtual bool OnMessageReceived(const IPC::Message& message); |
| 41 | 42 virtual void OnChannelConnected(int32 peer_pid); |
| 42 int process_id() const { return backend_impl_.process_id(); } | |
| 43 | |
| 44 // Note: needed to satisfy ipc message dispatching macros. | |
| 45 bool Send(IPC::Message* msg) { | |
| 46 return frontend_proxy_.sender()->Send(msg); | |
| 47 } | |
| 48 | 43 |
| 49 private: | 44 private: |
| 50 // Ipc message handlers | 45 // IPC message handlers |
| 51 void OnRegisterHost(int host_id); | 46 void OnRegisterHost(int host_id); |
| 52 void OnUnregisterHost(int host_id); | 47 void OnUnregisterHost(int host_id); |
| 53 void OnSelectCache(int host_id, const GURL& document_url, | 48 void OnSelectCache(int host_id, const GURL& document_url, |
| 54 int64 cache_document_was_loaded_from, | 49 int64 cache_document_was_loaded_from, |
| 55 const GURL& opt_manifest_url); | 50 const GURL& opt_manifest_url); |
| 56 void OnSelectCacheForWorker(int host_id, int parent_process_id, | 51 void OnSelectCacheForWorker(int host_id, int parent_process_id, |
| 57 int parent_host_id); | 52 int parent_host_id); |
| 58 void OnSelectCacheForSharedWorker(int host_id, int64 appcache_id); | 53 void OnSelectCacheForSharedWorker(int host_id, int64 appcache_id); |
| 59 void OnMarkAsForeignEntry(int host_id, const GURL& document_url, | 54 void OnMarkAsForeignEntry(int host_id, const GURL& document_url, |
| 60 int64 cache_document_was_loaded_from); | 55 int64 cache_document_was_loaded_from); |
| 61 void OnGetStatus(int host_id, IPC::Message* reply_msg); | 56 void OnGetStatus(int host_id, IPC::Message* reply_msg); |
| 62 void OnStartUpdate(int host_id, IPC::Message* reply_msg); | 57 void OnStartUpdate(int host_id, IPC::Message* reply_msg); |
| 63 void OnSwapCache(int host_id, IPC::Message* reply_msg); | 58 void OnSwapCache(int host_id, IPC::Message* reply_msg); |
| 64 void OnGetResourceList( | 59 void OnGetResourceList( |
| 65 int host_id, | 60 int host_id, |
| 66 std::vector<appcache::AppCacheResourceInfo>* resource_infos); | 61 std::vector<appcache::AppCacheResourceInfo>* resource_infos); |
| 67 void GetStatusCallback(appcache::Status status, void* param); | 62 void GetStatusCallback(appcache::Status status, void* param); |
| 68 void StartUpdateCallback(bool result, void* param); | 63 void StartUpdateCallback(bool result, void* param); |
| 69 void SwapCacheCallback(bool result, void* param); | 64 void SwapCacheCallback(bool result, void* param); |
| 70 | 65 |
| 71 void ReceivedBadMessage(uint32 msg_type); | 66 // This is only valid once Initialize() has been called. This MUST be defined |
| 67 // before backend_impl_ since the latter maintains a (non-refcounted) pointer |
| 68 // to it. |
| 69 scoped_refptr<ChromeAppCacheService> appcache_service_; |
| 72 | 70 |
| 73 AppCacheFrontendProxy frontend_proxy_; | 71 AppCacheFrontendProxy frontend_proxy_; |
| 74 appcache::AppCacheBackendImpl backend_impl_; | 72 appcache::AppCacheBackendImpl backend_impl_; |
| 75 | 73 |
| 76 // Temporary until Initialize() can be called from the IO thread, | 74 // Temporary until OnChannelConnected() can be called from the IO thread, |
| 77 // which will extract the AppCacheService from the URLRequestContext. | 75 // which will extract the AppCacheService from the URLRequestContext. |
| 78 scoped_refptr<URLRequestContext> request_context_; | 76 scoped_refptr<URLRequestContext> request_context_; |
| 79 scoped_refptr<URLRequestContextGetter> request_context_getter_; | 77 scoped_refptr<URLRequestContextGetter> request_context_getter_; |
| 80 | 78 |
| 81 // This is only valid once Initialize() has been called. | |
| 82 scoped_refptr<ChromeAppCacheService> appcache_service_; | |
| 83 | |
| 84 scoped_ptr<appcache::GetStatusCallback> get_status_callback_; | 79 scoped_ptr<appcache::GetStatusCallback> get_status_callback_; |
| 85 scoped_ptr<appcache::StartUpdateCallback> start_update_callback_; | 80 scoped_ptr<appcache::StartUpdateCallback> start_update_callback_; |
| 86 scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_; | 81 scoped_ptr<appcache::SwapCacheCallback> swap_cache_callback_; |
| 87 scoped_ptr<IPC::Message> pending_reply_msg_; | 82 scoped_ptr<IPC::Message> pending_reply_msg_; |
| 88 | 83 |
| 89 ResourceDispatcherHost::Receiver* receiver_; | 84 // The corresponding ChildProcessHost object's id(). |
| 85 int process_id_; |
| 90 | 86 |
| 91 DISALLOW_COPY_AND_ASSIGN(AppCacheDispatcherHost); | 87 DISALLOW_COPY_AND_ASSIGN(AppCacheDispatcherHost); |
| 92 }; | 88 }; |
| 93 | 89 |
| 94 #endif // CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ | 90 #endif // CHROME_BROWSER_APPCACHE_APPCACHE_DISPATCHER_HOST_H_ |
| OLD | NEW |