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

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 test / merge error 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/origin.h"
14
15 namespace content{
16 class BrowserContext;
17 }
18
19 namespace user_prefs {
20 class PrefRegistrySyncable;
21 }
22
23 class HostContentSettingsMap;
24 class PrefService;
25 class Profile;
26 class TemplateURLService;
27
28 // Helper class to manage the DSE Geolocation setting. It keeps the setting
29 // valid by watching change to the CCTLD and DSE, and also provides logic for
30 // whether the setting should be used and it's current value.
31 // Glossary:
32 // DSE: Default Search Engine
33 // CCTLD: Country Code Top Level Domain (e.g. google.com.au)
34 class SearchGeolocationService
35 : public TemplateURLServiceObserver,
36 public KeyedService {
37 public:
38 // Factory implementation will not create a service in incognito.
39 class Factory : public BrowserContextKeyedServiceFactory {
40 public:
41 static SearchGeolocationService* GetForBrowserContext(
42 content::BrowserContext* context);
43
44 static Factory* GetInstance();
45 private:
46 friend struct base::DefaultSingletonTraits<Factory>;
47
48 Factory();
49 ~Factory() override;
50
51 // BrowserContextKeyedServiceFactory
52 bool ServiceIsCreatedWithBrowserContext() const override;
53 KeyedService* BuildServiceInstanceFor(
54 content::BrowserContext* profile) const override;
55 };
56
57 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
58
59 explicit SearchGeolocationService(Profile* profile);
60
61 // Returns whether the DSE geolocation setting is applicable for geolocation
62 // requests for the given top level origin.
63 bool UseDSEGeolocationSetting(const url::Origin& requesting_origin);
64
65 // Returns the DSE geolocation setting, after applying any updates needed to
66 // make it valid.
67 bool GetDSEGeolocationSetting();
68
69 // Changes the DSE geolocation setting.
70 void SetDSEGeolocationSetting(bool setting);
71
72 // KeyedService:
73 void Shutdown() override;
74
75 private:
76 struct PrefValue;
77
78 ~SearchGeolocationService() override;
79
80 // TemplateURLServiceObserver
81 // When the DSE CCTLD changes (either by changing their DSE or by changing
82 // their CCTLD, and their DSE supports geolocation:
83 // * If the DSE CCTLD origin permission is BLOCK, but the DSE geolocation
84 // setting is on, change the DSE geolocation setting to off
85 // * If the DSE CCTLD origin permission is ALLOW, but the DSE geolocation
86 // setting is off, reset the DSE CCTLD origin permission to ASK.
87 // Also, if the previous DSE did not support geolocation, and the new one
88 // does, and the geolocation setting is on, reset whether the DSE geolocation
89 // disclosure has been shown.
90 void OnTemplateURLServiceChanged() override;
91
92 // Initialize the DSE geolocation setting if it hasn't already been
93 // initialized. Also, if it hasn't been initialized, reset whether the DSE
94 // geolocation disclosure has been shown to ensure user who may have seen it
95 // on earlier versions (due to Finch experiments) see it again.
96 void InitializeDSEGeolocationSettingIfNeeded();
97
98 // Check that the DSE geolocation setting is valid with respect to the content
99 // setting. The rules of vaidity are:
100 // * If the content setting is BLOCK, the DSE geolocation setting must
101 // be false.
102 // * If the content setting is ALLOW, the DSE geolocation setting must be
103 // true.
104 // * If the content setting is ASK, the DSE geolocation setting can be true or
105 // false.
106 // One way the setting could become invalid is if the feature enabling the
107 // setting was disabled (via Finch or flags), content settings were changed,
108 // and the feature enabled again. Or the enterprise policy settings could have
109 // been updated in a way that makes the setting invalid.
110 void EnsureDSEGeolocationSettingIsValid();
111
112 // Returns true if the current DSE is Google (Google is the only search engine
113 // to currently support DSE geolocation).
114 bool IsGoogleSearchEngine();
115
116 // Returns the origin of the current CCTLD of the default search engine. If
117 // the default search engine is not Google, will return a unique Origin.
118 url::Origin GetDSECCTLD();
119
120 PrefValue GetDSEGeolocationPref();
121 void SetDSEGeolocationPref(const PrefValue& pref);
122
123 // Retrieve the geolocation content setting for the current DSE CCTLD.
124 ContentSetting GetCurrentContentSetting();
125
126 // Reset the geolocation content setting for the current DSE CCTLD back to the
127 // default.
128 void ResetContentSetting();
129
130 // Returns whether the user can change the geolocation content setting for the
131 // current DSE CCTLD.
132 bool IsContentSettingUserSettable();
133
134 // Whether the feature/experiment setup is enabling the consistent search
135 // geolocation system.
136 bool UseConsistentSearchGeolocation();
137
138 Profile* profile_;
139 PrefService* pref_service_;
140 HostContentSettingsMap* host_content_settings_map_;
141 TemplateURLService* template_url_service_;
142 };
143
144 #endif // CHROME_BROWSER_ANDROID_SEARCH_GEOLOCATION_SEARCH_GEOLOCATION_SERVICE_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698