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

Side by Side Diff: chrome/browser/content_settings/content_settings_extension_provider.cc

Issue 7344008: Make the hcsm and its providers communicate via an observer interface. (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 #include "chrome/browser/content_settings/content_settings_extension_provider.h" 5 #include "chrome/browser/content_settings/content_settings_extension_provider.h"
6 6
7 #include "chrome/browser/content_settings/content_settings_details.h" 7 #include "chrome/browser/content_settings/content_settings_details.h"
8 #include "chrome/browser/extensions/extension_content_settings_store.h" 8 #include "chrome/browser/extensions/extension_content_settings_store.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "content/common/notification_details.h" 11 #include "content/common/notification_details.h"
12 #include "content/common/notification_service.h" 12 #include "content/common/notification_service.h"
13 #include "content/common/notification_source.h" 13 #include "content/common/notification_source.h"
14 14
15 namespace content_settings { 15 namespace content_settings {
16 16
17 ExtensionProvider::ExtensionProvider( 17 ExtensionProvider::ExtensionProvider(
18 HostContentSettingsMap* map, 18 content_settings::Observer* observer,
19 ExtensionContentSettingsStore* extensions_settings, 19 ExtensionContentSettingsStore* extensions_settings,
20 bool incognito) 20 bool incognito)
21 : map_(map), 21 : incognito_(incognito),
22 incognito_(incognito),
23 extensions_settings_(extensions_settings) { 22 extensions_settings_(extensions_settings) {
23 AddObserver(observer);
24 extensions_settings_->AddObserver(this); 24 extensions_settings_->AddObserver(this);
25 } 25 }
26 26
27 ExtensionProvider::~ExtensionProvider() { 27 ExtensionProvider::~ExtensionProvider() {
28 DCHECK(!map_);
29 } 28 }
30 29
31 ContentSetting ExtensionProvider::GetContentSetting( 30 ContentSetting ExtensionProvider::GetContentSetting(
32 const GURL& embedded_url, 31 const GURL& embedded_url,
33 const GURL& top_level_url, 32 const GURL& top_level_url,
34 ContentSettingsType content_type, 33 ContentSettingsType content_type,
35 const ResourceIdentifier& resource_identifier) const { 34 const ResourceIdentifier& resource_identifier) const {
36 // TODO(markusheintz): Instead of getting the effective setting every time 35 // TODO(markusheintz): Instead of getting the effective setting every time
37 // effective patterns could be cached in here. 36 // effective patterns could be cached in here.
38 DCHECK(extensions_settings_); 37 DCHECK(extensions_settings_);
39 return extensions_settings_->GetEffectiveContentSetting( 38 return extensions_settings_->GetEffectiveContentSetting(
40 embedded_url, 39 embedded_url,
41 top_level_url, 40 top_level_url,
42 content_type, 41 content_type,
43 resource_identifier, 42 resource_identifier,
44 incognito_); 43 incognito_);
45 } 44 }
46 45
47 void ExtensionProvider::GetAllContentSettingsRules( 46 void ExtensionProvider::GetAllContentSettingsRules(
48 ContentSettingsType content_type, 47 ContentSettingsType content_type,
49 const ResourceIdentifier& resource_identifier, 48 const ResourceIdentifier& resource_identifier,
50 Rules* content_setting_rules) const { 49 Rules* content_setting_rules) const {
51 return extensions_settings_->GetContentSettingsForContentType( 50 return extensions_settings_->GetContentSettingsForContentType(
52 content_type, resource_identifier, incognito_, content_setting_rules); 51 content_type, resource_identifier, incognito_, content_setting_rules);
53 } 52 }
54 53
55 void ExtensionProvider::ShutdownOnUIThread() { 54 void ExtensionProvider::ShutdownOnUIThread() {
55 RemoveAllObserver();
56 extensions_settings_->RemoveObserver(this); 56 extensions_settings_->RemoveObserver(this);
57 map_ = NULL;
58 }
59
60 void ExtensionProvider::NotifyObservers(
61 const ContentSettingsDetails& details) {
62 DCHECK(map_);
63 NotificationService::current()->Notify(
64 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
65 Source<HostContentSettingsMap>(map_),
66 Details<const ContentSettingsDetails>(&details));
67 } 57 }
68 58
69 void ExtensionProvider::OnContentSettingChanged( 59 void ExtensionProvider::OnContentSettingChanged(
70 const std::string& extension_id, 60 const std::string& extension_id,
71 bool incognito) { 61 bool incognito) {
72 if (incognito_ != incognito) 62 if (incognito_ != incognito)
73 return; 63 return;
74 // TODO(markusheintz): Be more concise. 64 // TODO(markusheintz): Be more concise.
75 ContentSettingsDetails details(ContentSettingsPattern(), 65 ContentSettingsDetails details(ContentSettingsPattern(),
76 ContentSettingsPattern(), 66 ContentSettingsPattern(),
77 CONTENT_SETTINGS_TYPE_DEFAULT, 67 CONTENT_SETTINGS_TYPE_DEFAULT,
78 std::string()); 68 std::string());
79 NotifyObservers(details); 69 NotifyObservers(details);
80 } 70 }
81 71
82 } // namespace content_settings 72 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698