Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: content/browser/geolocation/geolocation_dispatcher_host.h

Issue 273523007: Dispatch geolocation IPCs on the UI thread. Aside from simplifying the code to avoid a lot of threa… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: benm comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
7 7
8 #include <map>
9 #include <set>
10
11 #include "content/browser/geolocation/geolocation_provider_impl.h" 8 #include "content/browser/geolocation/geolocation_provider_impl.h"
12 #include "content/public/browser/browser_message_filter.h" 9 #include "content/public/browser/web_contents_observer.h"
13 10
14 class GURL; 11 class GURL;
15 12
16 namespace content { 13 namespace content {
17 14
18 class GeolocationPermissionContext; 15 class GeolocationPermissionContext;
19 16
20 // GeolocationDispatcherHost is a browser filter for Geolocation messages. 17 // GeolocationDispatcherHost is an observer for Geolocation messages.
21 // It's the complement of GeolocationDispatcher (owned by RenderView). 18 // It's the complement of GeolocationDispatcher (owned by RenderView).
22 class GeolocationDispatcherHost : public BrowserMessageFilter { 19 class GeolocationDispatcherHost : public WebContentsObserver {
bulach 2014/05/08 17:29:26 heheh, this class is showing its age :) does it ma
jam 2014/05/08 19:09:53 We have various naming conventions for this stuff.
bulach 2014/05/09 09:50:17 I think we have a few other FooWebContentsObserver
23 public: 20 public:
24 GeolocationDispatcherHost( 21 explicit GeolocationDispatcherHost(WebContents* web_contents);
25 int render_process_id, 22 virtual ~GeolocationDispatcherHost();
26 GeolocationPermissionContext* geolocation_permission_context);
27 23
28 // Pause or resumes geolocation for the given |render_view_id|. Should 24 // Pause or resumes geolocation. Resuming when nothing is paused is a no-op.
29 // be called on the IO thread. Resuming when nothing is paused is a no-op. 25 // If the web contents is paused while not currently using geolocation but
30 // If a renderer is paused while not currently using geolocation but 26 // then goes on to do so before being resumed, then it will not get
31 // then goes on to do so before being resumed, then that renderer will 27 // geolocation updates until it is resumed.
32 // not get geolocation updates until it is resumed. 28 void PauseOrResume(bool should_pause);
33 void PauseOrResume(int render_view_id, bool should_pause);
34 29
35 private: 30 private:
36 virtual ~GeolocationDispatcherHost(); 31 // WebContentsObserver
37 32 virtual void RenderViewHostChanged(RenderViewHost* old_host,
38 // GeolocationDispatcherHost 33 RenderViewHost* new_host) OVERRIDE;
39 virtual bool OnMessageReceived(const IPC::Message& msg, 34 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
40 bool* msg_was_ok) OVERRIDE;
41 35
42 // Message handlers: 36 // Message handlers:
43 void OnRequestPermission(int render_view_id, 37 void OnRequestPermission(int bridge_id,
44 int bridge_id,
45 const GURL& requesting_frame, 38 const GURL& requesting_frame,
46 bool user_gesture); 39 bool user_gesture);
47 void OnCancelPermissionRequest(int render_view_id, 40 void OnCancelPermissionRequest(int bridge_id,
48 int bridge_id,
49 const GURL& requesting_frame); 41 const GURL& requesting_frame);
50 void OnStartUpdating(int render_view_id, 42 void OnStartUpdating(const GURL& requesting_frame,
51 const GURL& requesting_frame,
52 bool enable_high_accuracy); 43 bool enable_high_accuracy);
53 void OnStopUpdating(int render_view_id); 44 void OnStopUpdating();
54 45
55 // Updates the |geolocation_provider_| with the currently required update 46 // Updates the geolocation provider with the currently required update
56 // options. 47 // options.
57 void RefreshGeolocationOptions(); 48 void RefreshGeolocationOptions();
58 49
59 void OnLocationUpdate(const Geoposition& position); 50 void OnLocationUpdate(const Geoposition& position);
60 51
61 int render_process_id_;
62 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; 52 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_;
63 53
64 struct RendererGeolocationOptions { 54 bool watching_requested_;
65 bool high_accuracy; 55 bool paused_;
66 bool is_paused; 56 bool high_accuracy_;
67 };
68 57
69 // Used to keep track of the renderers in this process that are using 58 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_;
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 59
89 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost); 60 DISALLOW_COPY_AND_ASSIGN(GeolocationDispatcherHost);
90 }; 61 };
91 62
92 } // namespace content 63 } // namespace content
93 64
94 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_ 65 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698