Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / geolocation / geolocation_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_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
7
8 #include <map>
9 #include <set>
10
11 #include "content/browser/geolocation/geolocation_provider_impl.h"
12 #include "content/public/browser/browser_message_filter.h"
13
14 class GURL;
15
16 namespace content {
17
18 class GeolocationPermissionContext;
19
20 // GeolocationDispatcherHost is a browser filter for Geolocation messages.
21 // It's the complement of GeolocationDispatcher (owned by RenderView).
22 class GeolocationDispatcherHost : public BrowserMessageFilter {
23  public:
24   GeolocationDispatcherHost(
25       int render_process_id,
26       GeolocationPermissionContext* geolocation_permission_context);
27
28   // Pause or resumes geolocation for the given |render_view_id|. Should
29   // be called on the IO thread. Resuming when nothing is paused is a no-op.
30   // If a renderer is paused while not currently using geolocation but
31   // then goes on to do so before being resumed, then that renderer will
32   // not get geolocation updates until it is resumed.
33   void PauseOrResume(int render_view_id, bool should_pause);
34
35  private:
36   virtual ~GeolocationDispatcherHost();
37
38   // GeolocationDispatcherHost
39   virtual bool OnMessageReceived(const IPC::Message& msg,
40                                  bool* msg_was_ok) OVERRIDE;
41
42   // Message handlers:
43   void OnRequestPermission(int render_view_id,
44                            int bridge_id,
45                            const GURL& requesting_frame,
46                            bool user_gesture);
47   void OnCancelPermissionRequest(int render_view_id,
48                                  int bridge_id,
49                                  const GURL& requesting_frame);
50   void OnStartUpdating(int render_view_id,
51                        const GURL& requesting_frame,
52                        bool enable_high_accuracy);
53   void OnStopUpdating(int render_view_id);
54
55   // Updates the |geolocation_provider_| with the currently required update
56   // options.
57   void RefreshGeolocationOptions();
58
59   void OnLocationUpdate(const Geoposition& position);
60
61   int render_process_id_;
62   scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
63
64   struct RendererGeolocationOptions {
65     bool high_accuracy;
66     bool is_paused;
67   };
68
69   // Used to keep track of the renderers in this process that are using
70   // geolocation and the options associated with them. The map is iterated
71   // when a location update is available and the fan out to individual bridge
72   // IDs happens renderer side, in order to minimize context switches.
73   // Only used on the IO thread.
74   std::map<int, RendererGeolocationOptions> geolocation_renderers_;
75
76   // Used by Android WebView to support that case that a renderer is in the
77   // 'paused' state but not yet using geolocation. If the renderer does start
78   // using geolocation while paused, we move from this set into
79   // |geolocation_renderers_|. If the renderer doesn't end up wanting to use
80   // geolocation while 'paused' then we remove from this set. A renderer id
81   // can exist only in this set or |geolocation_renderers_|, never both.
82   std::set<int> pending_paused_geolocation_renderers_;
83
84   // Only set whilst we are registered with the geolocation provider.
85   GeolocationProviderImpl* geolocation_provider_;
86
87   GeolocationProviderImpl::LocationUpdateCallback callback_;
88
89   DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
90 };
91
92 }  // namespace content
93
94 #endif  // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_