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

Side by Side Diff: chrome/browser/android/search_geolocation/search_geolocation_service.h

Issue 2612993002: Make geolocation API and X-Geo header access consistent (Closed)
Patch Set: Fix some things; rebase Created 3 years, 11 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
(Empty)
1 // Copyright 2017 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 CHROME_BROWSER_ANDROID_SEARCH_GEOLOCATION_SEARCH_GEOLOCATION_SERVICE_H_
6 #define CHROME_BROWSER_ANDROID_SEARCH_GEOLOCATION_SEARCH_GEOLOCATION_SERVICE_H_
7
8 #include "base/memory/singleton.h"
9 #include "components/content_settings/core/common/content_settings.h"
10 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "components/search_engines/template_url_service_observer.h"
13 #include "url/gurl.h"
raymes 2017/01/09 05:47:26 nit: I don't think this is needed anymore
benwells 2017/01/09 21:02:22 Done.
14 #include "url/origin.h"
15
16 namespace content{
17 class BrowserContext;
18 }
19
20 namespace user_prefs {
21 class PrefRegistrySyncable;
22 }
23
24 class HostContentSettingsMap;
25 class PrefService;
26 class Profile;
27 class TemplateURLService;
28
29 // Helper class to manage the DSE Geolocation setting. It keeps the setting
30 // valid by watching change to the CCTLD and DSE, and also provides logic for
31 // whether the setting should be used and it's current value.
raymes 2017/01/09 05:47:26 nit: not sure if it's important to explain what CC
benwells 2017/01/09 21:02:22 Done.
32 class SearchGeolocationService
33 : public TemplateURLServiceObserver,
34 public KeyedService {
35 public:
36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
37
38 explicit SearchGeolocationService(Profile* profile);
39
40 // Returns whether the DSE geolocation setting is applicable for geolocation
41 // requests for the given origin.
raymes 2017/01/09 05:47:26 nit: might want to clarify that this is the top le
benwells 2017/01/09 21:02:22 Done.
42 bool UseDSEGeolocationSetting(const url::Origin& requesting_origin);
43
44 // Returns the DSE geolocation setting, after applying any updates needed to
45 // make it valid.
46 bool GetDSEGeolocationSetting();
47
48 // Changes the DSE geolocation setting.
49 void SetDSEGeolocationSetting(bool setting);
50
51 // KeyedService:
52 void Shutdown() override;
53
54 // Factory implementation will not create a service in incognito.
55 class Factory : public BrowserContextKeyedServiceFactory {
raymes 2017/01/09 05:47:26 nit: I think inner classes tend to go before the m
benwells 2017/01/09 21:02:22 Done.
56 public:
57 static SearchGeolocationService* GetForBrowserContext(
58 content::BrowserContext* context);
59
60 static Factory* GetInstance();
61 private:
62 friend struct base::DefaultSingletonTraits<Factory>;
63
64 Factory();
65 ~Factory() override;
66
67 // BrowserContextKeyedServiceFactory
68 bool ServiceIsCreatedWithBrowserContext() const override;
69 KeyedService* BuildServiceInstanceFor(
70 content::BrowserContext* profile) const override;
71 };
72
73 private:
74 struct PrefValue;
75
76 ~SearchGeolocationService() override;
77
78 // TemplateURLServiceObserver
79 // When the DSE CCTLD changes (either by changing their DSE or by changing
80 // their CCTLD, and their DSE supports geolocation:
81 // * If the DSE CCTLD origin permission is BLOCK, but the DSE geolocation
82 // setting is on, change the DSE geolocation setting to off
83 // * If the DSE CCTLD origin permission is ALLOW, but the DSE geolocation
84 // setting is off, reset the DSE CCTLD origin permission to ASK.
85 // Also, if the previous DSE did not support geolocation, and the new one
86 // does, and the geolocation setting is on, reset whether the DSE geolocation
87 // disclosure has been shown.
88 void OnTemplateURLServiceChanged() override;
89
90 // Initialize the DSE geolocation setting if it hasn't already been
91 // initialized. Also, if it hasn't been initialized, reset whether the DSE
92 // geolocation disclosure has been shown to ensure user who may have seen it
93 // on earlier versions (due to Finch experiments) see it again.
94 void InitializeDSEGeolocationSettingIfNeeded();
95
96 // Check that the DSE geolocation setting is valid with respect to the content
97 // setting. The rules of vaidity are:
98 // * If the content setting is BLOCK, the DSE geolocation setting must
99 // be false.
100 // * If the content setting is ALLOW, the DSE geolocation setting must be
101 // true.
102 // * If the content setting is ASK, the DSE geolocation setting can be true or
103 // false.
104 // One way the setting could become invalid is if the feature enabling the
105 // setting was disabled (via Finch or flags), content settings were changed,
106 // and the feature enabled again.
107 // Another way is if the setting was changed while enterprise policy is in
raymes 2017/01/09 05:47:27 nit: fill the previous line to 80chars
benwells 2017/01/09 21:02:22 Done. I also updated the text a bit.
108 // effect.
109 void EnsureDSEGeolocationSettingIsValid();
110
111 // Returns true if the current DSE is Google.
raymes 2017/01/09 05:47:26 nit: might want to mention that Google is currentl
benwells 2017/01/09 21:02:22 Done.
112 bool IsGoogleSearchEngine();
113
114 // Returns the origin of the current CCTLD of the default search engine. If
115 // the default search engine is not Google, will return a unique Origin.
116 url::Origin GetDSECCTLD();
117
118 PrefValue GetDSEGeolocationPref();
119 void SetDSEGeolocationPref(const PrefValue& pref);
120
121 ContentSetting GetCurrentContentSetting();
raymes 2017/01/09 05:47:27 nit: might want to clairfy that these apply to the
benwells 2017/01/09 21:02:22 Done.
122 void ResetContentSetting();
123
124 // Whether the feature/experiment setup is enabling the consistent search
125 // geolocation system.
126 bool UseConsistentSearchGeolocation();
127
128 Profile* profile_;
129 PrefService* pref_service_;
130 HostContentSettingsMap* host_content_settings_map_;
131 TemplateURLService* template_url_service_;
132 };
133
134 #endif // CHROME_BROWSER_ANDROID_SEARCH_GEOLOCATION_SEARCH_GEOLOCATION_SERVICE_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698