Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / browser / geolocation / geolocation_dispatcher_host.h
blobe8bda4026d687001276f562ea5b254ef0a6e64d7
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.
5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
8 #include <map>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/geolocation/geolocation_provider_impl.h"
14 #include "content/public/browser/web_contents_observer.h"
16 class GURL;
18 namespace content {
20 // GeolocationDispatcherHost is an observer for Geolocation messages.
21 // It's the complement of GeolocationDispatcher (owned by RenderView).
22 class GeolocationDispatcherHost : public WebContentsObserver {
23 public:
24 explicit GeolocationDispatcherHost(WebContents* web_contents);
25 virtual ~GeolocationDispatcherHost();
27 // Pause or resumes geolocation. Resuming when nothing is paused is a no-op.
28 // If the web contents is paused while not currently using geolocation but
29 // then goes on to do so before being resumed, then it will not get
30 // geolocation updates until it is resumed.
31 void PauseOrResume(bool should_pause);
33 private:
34 // WebContentsObserver
35 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE;
36 virtual void RenderViewHostChanged(RenderViewHost* old_host,
37 RenderViewHost* new_host) OVERRIDE;
38 virtual bool OnMessageReceived(
39 const IPC::Message& msg, RenderFrameHost* render_frame_host) OVERRIDE;
41 // Message handlers:
42 void OnRequestPermission(RenderFrameHost* render_frame_host,
43 int bridge_id,
44 const GURL& requesting_frame,
45 bool user_gesture);
46 void OnCancelPermissionRequest(RenderFrameHost* render_frame_host,
47 int bridge_id,
48 const GURL& requesting_frame);
49 void OnStartUpdating(RenderFrameHost* render_frame_host,
50 const GURL& requesting_frame,
51 bool enable_high_accuracy);
52 void OnStopUpdating(RenderFrameHost* render_frame_host);
54 // Updates the geolocation provider with the currently required update
55 // options.
56 void RefreshGeolocationOptions();
58 void OnLocationUpdate(const Geoposition& position);
60 void SendGeolocationPermissionResponse(int render_process_id,
61 int render_frame_id,
62 int bridge_id,
63 bool allowed);
65 // A map from the RenderFrameHosts that have requested geolocation updates to
66 // the type of accuracy they requested (true = high accuracy).
67 std::map<RenderFrameHost*, bool> updating_frames_;
68 bool paused_;
70 struct PendingPermission {
71 PendingPermission(int render_frame_id,
72 int render_process_id,
73 int bridge_id);
74 ~PendingPermission();
75 int render_frame_id;
76 int render_process_id;
77 int bridge_id;
78 base::Closure cancel;
80 std::vector<PendingPermission> pending_permissions_;
82 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_;
84 base::WeakPtrFactory<GeolocationDispatcherHost> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
89 } // namespace content
91 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_