Upstream version 9.37.193.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,
60       bool initiated_by_user_gesture) OVERRIDE;
61   virtual void OnResponseStarted(
62       net::URLRequest* request,
63       content::ResourceContext* resource_context,
64       content::ResourceResponse* response,
65       IPC::Sender* sender) OVERRIDE;
66
67   void RemovePendingThrottleOnIoThread(IoThreadClientThrottle* throttle);
68
69   static void OnIoThreadClientReady(int new_render_process_id,
70                                     int new_render_frame_id);
71   static void AddPendingThrottle(int render_process_id,
72                                  int render_frame_id,
73                                  IoThreadClientThrottle* pending_throttle);
74  private:
75   friend struct base::DefaultLazyInstanceTraits<
76       RuntimeResourceDispatcherHostDelegateAndroid>;
77   // These methods must be called on IO thread.
78   void OnIoThreadClientReadyInternal(int new_render_process_id,
79                                      int new_render_frame_id);
80   void AddPendingThrottleOnIoThread(int render_process_id,
81                                     int render_frame_id,
82                                     IoThreadClientThrottle* pending_throttle);
83
84   typedef std::pair<int, int> FrameRouteIDPair;
85   typedef std::map<FrameRouteIDPair, IoThreadClientThrottle*>
86       PendingThrottleMap;
87
88   // Only accessed on the IO thread.
89   PendingThrottleMap pending_throttles_;
90
91   DISALLOW_COPY_AND_ASSIGN(RuntimeResourceDispatcherHostDelegateAndroid);
92 };
93
94 }  // namespace xwalk
95
96 #endif  // XWALK_RUNTIME_BROWSER_RUNTIME_RESOURCE_DISPATCHER_HOST_DELEGATE_ANDROID_H_