Chromium Code Reviews| Index: chrome/browser/managed_mode/managed_mode.cc |
| diff --git a/chrome/browser/managed_mode/managed_mode.cc b/chrome/browser/managed_mode/managed_mode.cc |
| index f1acb3bb8d0ffcd1605fd03699af7a25c2bd6c2c..654516fe208a5deaa2d35eac7b02cb1177d1a315 100644 |
| --- a/chrome/browser/managed_mode/managed_mode.cc |
| +++ b/chrome/browser/managed_mode/managed_mode.cc |
| @@ -12,7 +12,9 @@ |
| #include "chrome/browser/extensions/extension_system.h" |
| #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| +#include "chrome/browser/policy/url_blacklist_manager.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/prefs/scoped_user_pref_update.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| @@ -63,6 +65,28 @@ class ManagedMode::URLFilterContext { |
| base::Bind(&base::DoNothing))); |
| } |
| + void LoadManualLists(scoped_ptr<ListValue> whitelist, |
|
Bernhard Bauer
2013/01/07 12:34:19
Can you name this SetManualLists? It's in line wit
Sergiu
2013/01/07 16:25:05
Done.
|
| + scoped_ptr<ListValue> blacklist) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&ManagedModeURLFilter::SetManualLists, |
| + base::Unretained(&url_filter_), |
| + base::Passed(&whitelist), |
| + base::Passed(&blacklist), |
| + base::Bind(&base::DoNothing))); |
| + } |
| + |
| + void AddURLPatternToManualList(const bool isWhitelist, |
| + const std::string& url) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&ManagedModeURLFilter::AddURLPatternToManualList, |
| + base::Unretained(&url_filter_), |
| + isWhitelist, |
| + url, |
| + base::Bind(&base::DoNothing))); |
| + } |
| + |
| void ShutdownOnUIThread() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| bool result = task_runner_->DeleteSoon(FROM_HERE, this); |
| @@ -213,6 +237,79 @@ const ManagedModeURLFilter* ManagedMode::GetURLFilterForUIThreadImpl() { |
| return ui_url_filter_context_->url_filter(); |
| } |
| +// static |
| +void ManagedMode::AddToManualList(const bool isWhitelist, |
| + const URLPatternList& list) { |
| + GetInstance()->AddToManualListImpl(isWhitelist, list); |
| +} |
| + |
| +void ManagedMode::AddToManualListImpl(const bool isWhitelist, |
| + const URLPatternList& list) { |
| + if (!managed_profile_) |
| + return; |
| + |
| + ListPrefUpdate pref_update(managed_profile_->GetPrefs(), |
| + isWhitelist ? prefs::kManagedModeWhitelist : |
| + prefs::kManagedModeBlacklist); |
| + ListValue* pref_list = pref_update.Get(); |
| + |
| + for (size_t i = 0; i < list.GetSize(); ++i) { |
| + std::string url_pattern; |
| + list.GetString(i, &url_pattern); |
| + |
| + if (!IsInManualList(isWhitelist, url_pattern)) { |
| + pref_list->AppendString(url_pattern); |
| + AddURLPatternToManualList(isWhitelist, url_pattern); |
| + } |
| + } |
| +} |
| + |
| +// static |
| +void ManagedMode::RemoveFromManualList(const bool isWhitelist, |
| + const URLPatternList& list) { |
| + GetInstance()->RemoveFromManualListImpl(isWhitelist, list); |
| +} |
| + |
| +void ManagedMode::RemoveFromManualListImpl(const bool isWhitelist, |
| + const URLPatternList& list) { |
| + ListPrefUpdate pref_update(managed_profile_->GetPrefs(), |
| + isWhitelist ? prefs::kManagedModeWhitelist : |
| + prefs::kManagedModeBlacklist); |
| + ListValue* pref_list = pref_update.Get(); |
| + |
| + for (size_t i = 0; i < list.GetSize(); ++i) { |
| + std::string pattern; |
| + size_t out_index; |
| + list.GetString(i, &pattern); |
| + StringValue value_to_remove(pattern); |
| + DLOG(ERROR) << "Removing " << pattern; |
| + |
| + pref_list->Remove(value_to_remove, &out_index); |
| + } |
| +} |
| + |
| +// static |
| +bool ManagedMode::IsInManualList(const bool isWhitelist, |
| + const std::string& url_pattern) { |
| + return GetInstance()->IsInManualListImpl(isWhitelist, url_pattern); |
| +} |
| + |
| +bool ManagedMode::IsInManualListImpl(const bool isWhitelist, |
| + const std::string& url_pattern) { |
| + StringValue pattern(url_pattern); |
| + const ListValue* list = managed_profile_->GetPrefs()->GetList( |
| + isWhitelist ? prefs::kManagedModeWhitelist : |
| + prefs::kManagedModeBlacklist); |
| + return list->Find(pattern) != list->end(); |
| +} |
| + |
| +// static |
| +scoped_ptr<ManagedMode::URLPatternList> ManagedMode::GetBlacklist() { |
| + return scoped_ptr<URLPatternList>( |
| + GetInstance()->managed_profile_->GetPrefs()->GetList( |
| + prefs::kManagedModeBlacklist)->DeepCopy()).Pass(); |
| +} |
| + |
| std::string ManagedMode::GetDebugPolicyProviderName() const { |
| // Save the string space in official builds. |
| #ifdef NDEBUG |
| @@ -385,7 +482,7 @@ void ManagedMode::SetInManagedMode(Profile* newly_managed_profile) { |
| g_browser_process->local_state()->SetBoolean(prefs::kInManagedMode, |
| in_managed_mode); |
| if (in_managed_mode) |
| - UpdateWhitelist(); |
| + UpdateWhitelistImpl(); |
| // This causes the avatar and the profile menu to get updated. |
| content::NotificationService::current()->Notify( |
| @@ -412,7 +509,29 @@ void ManagedMode::OnDefaultFilteringBehaviorChanged() { |
| ui_url_filter_context_->SetDefaultFilteringBehavior(behavior); |
| } |
| +// Static |
| void ManagedMode::UpdateWhitelist() { |
| + GetInstance()->UpdateWhitelistImpl(); |
| +} |
| + |
| +void ManagedMode::UpdateWhitelistImpl() { |
| io_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); |
| ui_url_filter_context_->LoadWhitelists(GetActiveSiteLists()); |
| + io_url_filter_context_->LoadManualLists(GetWhitelist(), GetBlacklist()); |
| + ui_url_filter_context_->LoadManualLists(GetWhitelist(), GetBlacklist()); |
| +} |
| + |
| +scoped_ptr<ManagedMode::URLPatternList> ManagedMode::GetWhitelist() { |
| + return make_scoped_ptr( |
| + managed_profile_->GetPrefs()->GetList( |
| + prefs::kManagedModeWhitelist)->DeepCopy()); |
| +} |
| + |
| +void ManagedMode::AddURLPatternToManualList( |
|
Bernhard Bauer
2013/01/07 12:34:19
Please keep this method consistent with the style
Sergiu
2013/01/07 16:25:05
You were right, sorry.. it doesn't need to be stat
|
| + const bool isWhitelist, |
| + const std::string& url_pattern) { |
| + GetInstance()->io_url_filter_context_->AddURLPatternToManualList( |
| + true, url_pattern); |
| + GetInstance()->ui_url_filter_context_->AddURLPatternToManualList( |
| + true, url_pattern); |
| } |