Upstream version 7.36.153.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / runtime_resource_dispatcher_host_delegate_android.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_RUNTIME_BROWSER_RUNTIME_RESOURCE_DISPATCHER_HOST_DELEGATE_ANDROID_H_
6 #define XWALK_RUNTIME_BROWSER_RUNTIME_RESOURCE_DISPATCHER_HOST_DELEGATE_ANDROID_H_
7
8 #include <map>
9 #include <utility>
10
11 #include "base/lazy_instance.h"
12 #include "content/public/browser/content_browser_client.h"
13 #include "xwalk/runtime/browser/runtime_resource_dispatcher_host_delegate.h"
14
15 namespace content {
16 class ResourceDispatcherHostLoginDelegate;
17 struct ResourceResponse;
18 }  // namespace content
19
20 namespace IPC {
21 class Sender;
22 }  // namespace IPC
23
24 namespace xwalk {
25
26 class IoThreadClientThrottle;
27
28 class RuntimeResourceDispatcherHostDelegateAndroid
29     : public RuntimeResourceDispatcherHostDelegate {
30  public:
31   RuntimeResourceDispatcherHostDelegateAndroid();
32   virtual ~RuntimeResourceDispatcherHostDelegateAndroid();
33
34   static void ResourceDispatcherHostCreated();
35
36   virtual void RequestBeginning(
37       net::URLRequest* request,
38       content::ResourceContext* resource_context,
39       appcache::AppCacheService* appcache_service,
40       ResourceType::Type resource_type,
41       int child_id,
42       int route_id,
43       ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
44   virtual void DownloadStarting(
45       net::URLRequest* request,
46       content::ResourceContext* resource_context,
47       int child_id,
48       int route_id,
49       int request_id,
50       bool is_content_initiated,
51       bool must_download,
52       ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
53   virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(
54       net::AuthChallengeInfo* auth_info,
55       net::URLRequest* request) OVERRIDE;
56   virtual bool HandleExternalProtocol(
57       const GURL& url,
58       int child_id,
59       int route_id) OVERRIDE;
60   virtual void OnResponseStarted(
61       net::URLRequest* request,
62       content::ResourceContext* resource_context,
63       content::ResourceResponse* response,
64       IPC::Sender* sender) OVERRIDE;
65
66   void RemovePendingThrottleOnIoThread(IoThreadClientThrottle* throttle);
67
68   static void OnIoThreadClientReady(int new_render_process_id,
69                                     int new_render_frame_id);
70   static void AddPendingThrottle(int render_process_id,
71                                  int render_frame_id,
72                                  IoThreadClientThrottle* pending_throttle);
73  private:
74   friend struct base::DefaultLazyInstanceTraits<
75       RuntimeResourceDispatcherHostDelegateAndroid>;
76   // These methods must be called on IO thread.
77   void OnIoThreadClientReadyInternal(int new_render_process_id,
78                                      int new_render_frame_id);
79   void AddPendingThrottleOnIoThread(int render_process_id,
80                                     int render_frame_id,
81                                     IoThreadClientThrottle* pending_throttle);
82
83   typedef std::pair<int, int> FrameRouteIDPair;
84   typedef std::map<FrameRouteIDPair, IoThreadClientThrottle*>
85       PendingThrottleMap;
86
87   // Only accessed on the IO thread.
88   PendingThrottleMap pending_throttles_;
89
90   DISALLOW_COPY_AND_ASSIGN(RuntimeResourceDispatcherHostDelegateAndroid);
91 };
92
93 }  // namespace xwalk
94
95 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_RESOURCE_DISPATCHER_HOST_DELEGATE_ANDROID_H_