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

Side by Side Diff: chrome/browser/geolocation/geolocation_content_settings_map.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Implementation of the geolocation content settings map. Styled on 5 // Implementation of the geolocation content settings map. Styled on
6 // HostContentSettingsMap however unlike that class, this one does not hold 6 // HostContentSettingsMap however unlike that class, this one does not hold
7 // an additional in-memory copy of the settings as it does not need to support 7 // an additional in-memory copy of the settings as it does not need to support
8 // thread safe synchronous access to the settings; all geolocation permissions 8 // thread safe synchronous access to the settings; all geolocation permissions
9 // are read and written in the UI thread. (If in future this is no longer the 9 // are read and written in the UI thread. (If in future this is no longer the
10 // case, refer to http://codereview.chromium.org/1525018 for a previous version 10 // case, refer to http://codereview.chromium.org/1525018 for a previous version
11 // with caching. Note that as we must observe the prefs store for settings 11 // with caching. Note that as we must observe the prefs store for settings
12 // changes, e.g. coming from the sync engine, the simplest design would be to 12 // changes, e.g. coming from the sync engine, the simplest design would be to
13 // always write-through changes straight to the prefs store, and rely on the 13 // always write-through changes straight to the prefs store, and rely on the
14 // notification observer to subsequently update any cached copy). 14 // notification observer to subsequently update any cached copy).
15 15
16 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 16 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
17 17
18 #include <string> 18 #include <string>
19 19
20 #include "base/string_piece.h" 20 #include "base/string_piece.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "chrome/browser/content_settings/content_settings_details.h" 22 #include "chrome/browser/content_settings/content_settings_details.h"
23 #include "chrome/browser/content_settings/content_settings_pattern.h" 23 #include "chrome/browser/content_settings/content_settings_pattern.h"
24 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/prefs/scoped_user_pref_update.h" 25 #include "chrome/browser/prefs/scoped_user_pref_update.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
29 #include "content/browser/browser_thread.h" 30 #include "content/browser/browser_thread.h"
30 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
31 #include "content/common/notification_source.h" 32 #include "content/common/notification_source.h"
32 #include "content/common/notification_type.h"
33 #include "net/base/dns_util.h" 33 #include "net/base/dns_util.h"
34 #include "net/base/static_cookie_policy.h" 34 #include "net/base/static_cookie_policy.h"
35 35
36 // static 36 // static
37 const ContentSetting 37 const ContentSetting
38 GeolocationContentSettingsMap::kDefaultSetting = CONTENT_SETTING_ASK; 38 GeolocationContentSettingsMap::kDefaultSetting = CONTENT_SETTING_ASK;
39 39
40 GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile) 40 GeolocationContentSettingsMap::GeolocationContentSettingsMap(Profile* profile)
41 : profile_(profile) { 41 : profile_(profile) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43 prefs_registrar_.Init(profile_->GetPrefs()); 43 prefs_registrar_.Init(profile_->GetPrefs());
44 prefs_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this); 44 prefs_registrar_.Add(prefs::kGeolocationDefaultContentSetting, this);
45 prefs_registrar_.Add(prefs::kGeolocationContentSettings, this); 45 prefs_registrar_.Add(prefs::kGeolocationContentSettings, this);
46 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, 46 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
47 Source<Profile>(profile_)); 47 Source<Profile>(profile_));
48 } 48 }
49 49
50 // static 50 // static
51 void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) { 51 void GeolocationContentSettingsMap::RegisterUserPrefs(PrefService* prefs) {
52 prefs->RegisterIntegerPref(prefs::kGeolocationDefaultContentSetting, 52 prefs->RegisterIntegerPref(prefs::kGeolocationDefaultContentSetting,
53 CONTENT_SETTING_ASK, 53 CONTENT_SETTING_ASK,
54 PrefService::SYNCABLE_PREF); 54 PrefService::SYNCABLE_PREF);
55 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings, 55 prefs->RegisterDictionaryPref(prefs::kGeolocationContentSettings,
56 PrefService::SYNCABLE_PREF); 56 PrefService::SYNCABLE_PREF);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 if (!profile_) 192 if (!profile_)
193 return; 193 return;
194 PrefService* prefs = profile_->GetPrefs(); 194 PrefService* prefs = profile_->GetPrefs();
195 prefs->ClearPref(prefs::kGeolocationDefaultContentSetting); 195 prefs->ClearPref(prefs::kGeolocationDefaultContentSetting);
196 prefs->ClearPref(prefs::kGeolocationContentSettings); 196 prefs->ClearPref(prefs::kGeolocationContentSettings);
197 } 197 }
198 198
199 void GeolocationContentSettingsMap::NotifyObservers( 199 void GeolocationContentSettingsMap::NotifyObservers(
200 const ContentSettingsDetails& details) { 200 const ContentSettingsDetails& details) {
201 NotificationService::current()->Notify( 201 NotificationService::current()->Notify(
202 NotificationType::GEOLOCATION_SETTINGS_CHANGED, 202 chrome::NOTIFICATION_GEOLOCATION_SETTINGS_CHANGED,
203 Source<GeolocationContentSettingsMap>(this), 203 Source<GeolocationContentSettingsMap>(this),
204 Details<const ContentSettingsDetails>(&details)); 204 Details<const ContentSettingsDetails>(&details));
205 } 205 }
206 206
207 void GeolocationContentSettingsMap::Observe( 207 void GeolocationContentSettingsMap::Observe(
208 NotificationType type, 208 int type,
209 const NotificationSource& source, 209 const NotificationSource& source,
210 const NotificationDetails& details) { 210 const NotificationDetails& details) {
211 if (type == NotificationType::PREF_CHANGED) { 211 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
212 const std::string& name = *Details<std::string>(details).ptr(); 212 const std::string& name = *Details<std::string>(details).ptr();
213 if (name == prefs::kGeolocationDefaultContentSetting) { 213 if (name == prefs::kGeolocationDefaultContentSetting) {
214 ContentSettingsDetails details(ContentSettingsPattern(), 214 ContentSettingsDetails details(ContentSettingsPattern(),
215 ContentSettingsPattern(), 215 ContentSettingsPattern(),
216 CONTENT_SETTINGS_TYPE_DEFAULT, 216 CONTENT_SETTINGS_TYPE_DEFAULT,
217 std::string()); 217 std::string());
218 NotifyObservers(details); 218 NotifyObservers(details);
219 } 219 }
220 } else if (NotificationType::PROFILE_DESTROYED == type) { 220 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) {
221 UnregisterObservers(); 221 UnregisterObservers();
222 } else { 222 } else {
223 NOTREACHED(); 223 NOTREACHED();
224 } 224 }
225 } 225 }
226 226
227 void GeolocationContentSettingsMap::UnregisterObservers() { 227 void GeolocationContentSettingsMap::UnregisterObservers() {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
229 if (!profile_) 229 if (!profile_)
230 return; 230 return;
231 prefs_registrar_.RemoveAll(); 231 prefs_registrar_.RemoveAll();
232 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, 232 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
233 Source<Profile>(profile_)); 233 Source<Profile>(profile_));
234 profile_ = NULL; 234 profile_ = NULL;
235 } 235 }
236 236
237 GeolocationContentSettingsMap::~GeolocationContentSettingsMap() { 237 GeolocationContentSettingsMap::~GeolocationContentSettingsMap() {
238 UnregisterObservers(); 238 UnregisterObservers();
239 } 239 }
240 240
241 // static 241 // static
242 void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary( 242 void GeolocationContentSettingsMap::GetOneOriginSettingsFromDictionary(
243 const DictionaryValue* dictionary, 243 const DictionaryValue* dictionary,
244 OneOriginSettings* one_origin_settings) { 244 OneOriginSettings* one_origin_settings) {
245 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); 245 for (DictionaryValue::key_iterator i(dictionary->begin_keys());
246 i != dictionary->end_keys(); ++i) { 246 i != dictionary->end_keys(); ++i) {
247 const std::string& target(*i); 247 const std::string& target(*i);
248 int setting = kDefaultSetting; 248 int setting = kDefaultSetting;
249 bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting); 249 bool found = dictionary->GetIntegerWithoutPathExpansion(target, &setting);
250 DCHECK(found); 250 DCHECK(found);
251 GURL target_url(target); 251 GURL target_url(target);
252 // An empty URL has a special meaning (wildcard), so only accept invalid 252 // An empty URL has a special meaning (wildcard), so only accept invalid
253 // URLs if the original version was empty (avoids treating corrupted prefs 253 // URLs if the original version was empty (avoids treating corrupted prefs
254 // as the wildcard entry; see http://crbug.com/39685) 254 // as the wildcard entry; see http://crbug.com/39685)
255 if (target_url.is_valid() || target.empty()) 255 if (target_url.is_valid() || target.empty())
256 (*one_origin_settings)[target_url] = IntToContentSetting(setting); 256 (*one_origin_settings)[target_url] = IntToContentSetting(setting);
257 } 257 }
258 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698