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

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context.h

Issue 650180: Initial Geolocation location bar icons. (Closed)
Patch Set: Addresses Peter and Brett's comments. Created 10 years, 9 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 12
13 class GeolocationDispatcherHost; 13 class GeolocationDispatcherHost;
14 class Profile; 14 class GURL;
15 class HostContentSettingsMap;
15 class RenderViewHost; 16 class RenderViewHost;
17 class TabContents;
16 18
17 // GeolocationPermissionContext manages Geolocation permissions per host. 19 // GeolocationPermissionContext manages Geolocation permissions via
18 // It keeps an in-memory cache of permissions, and if not available, loads 20 // HostContentSettingsMap.
19 // from disk. If there's no data, it'll trigger the UI elements to ask the
20 // user for permission.
21 // Regardless of where the permission data came from, it always notifies the
22 // requesting render_view asynchronously via ViewMsg_Geolocation_PermissionSet.
23 class GeolocationPermissionContext 21 class GeolocationPermissionContext
24 : public base::RefCountedThreadSafe<GeolocationPermissionContext> { 22 : public base::RefCountedThreadSafe<GeolocationPermissionContext> {
25 public: 23 public:
26 explicit GeolocationPermissionContext(Profile* profile); 24 explicit GeolocationPermissionContext(
25 HostContentSettingsMap* host_content_settings_map);
27 26
28 // The render is requesting permission to use Geolocation. 27 // The render is requesting permission to use Geolocation.
29 // Response will be sent asynchronously as ViewMsg_Geolocation_PermissionSet. 28 // Response will be sent asynchronously as ViewMsg_Geolocation_PermissionSet.
30 // Must be called from the IO thread. 29 // Must be called from the IO thread.
31 void RequestGeolocationPermission( 30 void RequestGeolocationPermission(
32 int render_process_id, int render_view_id, int bridge_id, 31 int render_process_id, int render_view_id, int bridge_id,
33 const std::string& host); 32 const std::string& host);
34 33
35 // Called once the user sets the geolocation permission. 34 // Called once the user sets the geolocation permission from the infobar.
36 // It'll update the internal state on different threads via 35 void SetPermissionFromInfobar(
37 // SetPermissionMemoryCacheOnIOThread and SetPermissionOnFileThread.
38 void SetPermission(
39 int render_process_id, int render_view_id, int bridge_id, 36 int render_process_id, int render_view_id, int bridge_id,
40 const std::string& host, bool allowed); 37 const std::string& host, bool allowed);
41 38
39 // Called once the user sets the geolocation permission from the content
40 // bubble.
41 void SetPermissionFromContentBubble(
42 TabContents* tab_contents, const std::string& host, bool allowed);
43
42 private: 44 private:
43 friend class base::RefCountedThreadSafe<GeolocationPermissionContext>; 45 friend class base::RefCountedThreadSafe<GeolocationPermissionContext>;
44 virtual ~GeolocationPermissionContext(); 46 virtual ~GeolocationPermissionContext();
45 47
46 // This is initially called on the IO thread by the public API
47 // RequestGeolocationPermission when there's no data available in the
48 // in-memory cache.
49 // It forwards a call to the FILE thread which tries to load permission data
50 // from disk:
51 // - If available, it will call SetPermissionMemoryCacheOnIOThread() to write
52 // the in-memory cache in the IO thread, and NotifyPermissionSet to send the
53 // message to the corresponding render.
54 // - If not available, it'll delegate to RequestPermissionDataFromUI.
55 void HandlePermissionMemoryCacheMiss(
56 int render_process_id, int render_view_id, int bridge_id,
57 const std::string& host);
58
59 // Triggers the associated UI element to request permission. 48 // Triggers the associated UI element to request permission.
60 void RequestPermissionFromUI( 49 void RequestPermissionFromUI(
61 int render_process_id, int render_view_id, int bridge_id, 50 int render_process_id, int render_view_id, int bridge_id,
62 const std::string& host); 51 const std::string& host);
63 52
64 // Notifies whether or not the corresponding render is allowed to use 53 // Notifies whether or not the corresponding render is allowed to use
65 // geolocation. 54 // geolocation.
66 void NotifyPermissionSet( 55 void NotifyPermissionSet(
67 int render_process_id, int render_view_id, int bridge_id, 56 int render_process_id, int render_view_id, int bridge_id,
68 bool allowed); 57 const std::string& host, bool allowed);
69 58
70 // Sets permissions_ cache (if not on IO thread, will forward to it). 59 // Used to persist permission settings.
71 void SetPermissionMemoryCacheOnIOThread( 60 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
72 const std::string& host, bool allowed);
73 // Sets permissions file data (if not on FILE thread, will forward to it).
74 void SetPermissionOnFileThread(const std::string& host, bool allowed);
75
76 // This should only be accessed from the UI thread.
77 Profile* const profile_;
78 // Indicates whether profile_ is off the record.
79 bool const is_off_the_record_;
80 // The path where geolocation permission data is stored.
81 FilePath const permissions_path_;
82 // This should only be accessed from the UI thread.
83 std::map<std::string, bool> permissions_;
84 61
85 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext); 62 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContext);
86 }; 63 };
87 64
88 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_ 65 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_browsertest.cc ('k') | chrome/browser/geolocation/geolocation_permission_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698