Commit 5844aca1 authored by treib's avatar treib Committed by Commit bot

c/b/supervised_user: Use range-based for where appropriate.

We're now allowed to use some C++11 features: http://chromium-cpp.appspot.com/ :)

This CL also includes a few cleanups (mostly includes) courtesy of "git cl lint".

BUG=

Review URL: https://codereview.chromium.org/615493005

Cr-Commit-Position: refs/heads/master@{#297417}
parent 99d0e11b
...@@ -42,18 +42,14 @@ void ManagerPasswordService::Init( ...@@ -42,18 +42,14 @@ void ManagerPasswordService::Init(
SupervisedUserManager* supervised_user_manager = SupervisedUserManager* supervised_user_manager =
ChromeUserManager::Get()->GetSupervisedUserManager(); ChromeUserManager::Get()->GetSupervisedUserManager();
const user_manager::UserList& users = for (const user_manager::User* user :
user_manager::UserManager::Get()->GetUsers(); user_manager::UserManager::Get()->GetUsers()) {
if (user->GetType() != user_manager::USER_TYPE_SUPERVISED)
for (user_manager::UserList::const_iterator it = users.begin();
it != users.end();
++it) {
if ((*it)->GetType() != user_manager::USER_TYPE_SUPERVISED)
continue; continue;
if (user_id != supervised_user_manager->GetManagerUserId((*it)->email())) if (user_id != supervised_user_manager->GetManagerUserId(user->email()))
continue; continue;
OnSharedSettingsChange( OnSharedSettingsChange(
supervised_user_manager->GetUserSyncId((*it)->email()), supervised_user_manager->GetUserSyncId(user->email()),
supervised_users::kChromeOSPasswordData); supervised_users::kChromeOSPasswordData);
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/supervised_user/supervised_user_pref_store.h" #include "chrome/browser/supervised_user/supervised_user_pref_store.h"
#include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/prefs/pref_value_map.h" #include "base/prefs/pref_value_map.h"
#include "base/values.h" #include "base/values.h"
...@@ -120,9 +122,7 @@ void SupervisedUserPrefStore::OnNewSettingsAvailable( ...@@ -120,9 +122,7 @@ void SupervisedUserPrefStore::OnNewSettingsAvailable(
prefs_->GetDifferingKeys(old_prefs.get(), &changed_prefs); prefs_->GetDifferingKeys(old_prefs.get(), &changed_prefs);
// Send out change notifications. // Send out change notifications.
for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); for (const std::string& pref : changed_prefs) {
pref != changed_prefs.end(); FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(pref));
++pref) {
FOR_EACH_OBSERVER(Observer, observers_, OnPrefValueChanged(*pref));
} }
} }
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_STORE_H_ #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_STORE_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_STORE_H_ #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_PREF_STORE_H_
#include <string>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/prefs/pref_store.h" #include "base/prefs/pref_store.h"
......
...@@ -215,11 +215,10 @@ SupervisedUserRegistrationUtilityTest::GetRegistrationUtility() { ...@@ -215,11 +215,10 @@ SupervisedUserRegistrationUtilityTest::GetRegistrationUtility() {
void SupervisedUserRegistrationUtilityTest::Acknowledge() { void SupervisedUserRegistrationUtilityTest::Acknowledge() {
SyncChangeList new_changes; SyncChangeList new_changes;
const SyncChangeList& changes = change_processor()->changes(); for (const SyncChange& sync_change : change_processor()->changes()) {
for (SyncChangeList::const_iterator it = changes.begin(); it != changes.end(); EXPECT_EQ(SyncChange::ACTION_ADD, sync_change.change_type());
++it) { ::sync_pb::EntitySpecifics specifics =
EXPECT_EQ(SyncChange::ACTION_ADD, it->change_type()); sync_change.sync_data().GetSpecifics();
::sync_pb::EntitySpecifics specifics = it->sync_data().GetSpecifics();
EXPECT_FALSE(specifics.managed_user().acknowledged()); EXPECT_FALSE(specifics.managed_user().acknowledged());
specifics.mutable_managed_user()->set_acknowledged(true); specifics.mutable_managed_user()->set_acknowledged(true);
new_changes.push_back( new_changes.push_back(
......
...@@ -100,12 +100,11 @@ void SupervisedUserService::URLFilterContext::LoadWhitelists( ...@@ -100,12 +100,11 @@ void SupervisedUserService::URLFilterContext::LoadWhitelists(
ScopedVector<SupervisedUserSiteList> site_lists) { ScopedVector<SupervisedUserSiteList> site_lists) {
// SupervisedUserURLFilter::LoadWhitelists takes ownership of |site_lists|, // SupervisedUserURLFilter::LoadWhitelists takes ownership of |site_lists|,
// so we make an additional copy of it. // so we make an additional copy of it.
/// TODO(bauerb): This is kinda ugly. // TODO(bauerb): This is kinda ugly.
ScopedVector<SupervisedUserSiteList> site_lists_copy; ScopedVector<SupervisedUserSiteList> site_lists_copy;
for (ScopedVector<SupervisedUserSiteList>::iterator it = site_lists.begin(); for (const SupervisedUserSiteList* site_list : site_lists)
it != site_lists.end(); ++it) { site_lists_copy.push_back(site_list->Clone());
site_lists_copy.push_back((*it)->Clone());
}
ui_url_filter_->LoadWhitelists(site_lists.Pass()); ui_url_filter_->LoadWhitelists(site_lists.Pass());
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, BrowserThread::IO,
...@@ -314,11 +313,8 @@ void SupervisedUserService::AddNavigationBlockedCallback( ...@@ -314,11 +313,8 @@ void SupervisedUserService::AddNavigationBlockedCallback(
void SupervisedUserService::DidBlockNavigation( void SupervisedUserService::DidBlockNavigation(
content::WebContents* web_contents) { content::WebContents* web_contents) {
for (std::vector<NavigationBlockedCallback>::iterator it = for (const auto& callback : navigation_blocked_callbacks_)
navigation_blocked_callbacks_.begin(); callback.Run(web_contents);
it != navigation_blocked_callbacks_.end(); ++it) {
it->Run(web_contents);
}
} }
void SupervisedUserService::AddObserver( void SupervisedUserService::AddObserver(
...@@ -508,15 +504,13 @@ SupervisedUserService::GetActiveSiteLists() { ...@@ -508,15 +504,13 @@ SupervisedUserService::GetActiveSiteLists() {
if (!extension_service) if (!extension_service)
return site_lists.Pass(); return site_lists.Pass();
const extensions::ExtensionSet* extensions = extension_service->extensions(); for (const scoped_refptr<const extensions::Extension>& extension :
for (extensions::ExtensionSet::const_iterator it = extensions->begin(); *extension_service->extensions()) {
it != extensions->end(); ++it) {
const extensions::Extension* extension = it->get();
if (!extension_service->IsExtensionEnabled(extension->id())) if (!extension_service->IsExtensionEnabled(extension->id()))
continue; continue;
extensions::ExtensionResource site_list = extensions::ExtensionResource site_list =
extensions::SupervisedUserInfo::GetContentPackSiteList(extension); extensions::SupervisedUserInfo::GetContentPackSiteList(extension.get());
if (!site_list.empty()) { if (!site_list.empty()) {
site_lists.push_back(new SupervisedUserSiteList(extension->id(), site_lists.push_back(new SupervisedUserSiteList(extension->id(),
site_list.GetFilePath())); site_list.GetFilePath()));
......
...@@ -135,10 +135,8 @@ TEST_F(SupervisedUserServiceTest, GetManualExceptionsForHost) { ...@@ -135,10 +135,8 @@ TEST_F(SupervisedUserServiceTest, GetManualExceptionsForHost) {
DictionaryPrefUpdate update(profile_->GetPrefs(), DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kSupervisedUserManualURLs); prefs::kSupervisedUserManualURLs);
base::DictionaryValue* dict = update.Get(); base::DictionaryValue* dict = update.Get();
for (std::vector<GURL>::iterator it = exceptions.begin(); for (const GURL& url : exceptions)
it != exceptions.end(); ++it) { dict->RemoveWithoutPathExpansion(url.spec(), NULL);
dict->RemoveWithoutPathExpansion(it->spec(), NULL);
}
} }
EXPECT_EQ(SupervisedUserService::MANUAL_NONE, EXPECT_EQ(SupervisedUserService::MANUAL_NONE,
...@@ -396,14 +394,12 @@ TEST_F(SupervisedUserServiceExtensionTest, InstallContentPacks) { ...@@ -396,14 +394,12 @@ TEST_F(SupervisedUserServiceExtensionTest, InstallContentPacks) {
ASSERT_EQ(4u, sites.size()); ASSERT_EQ(4u, sites.size());
// The site lists might be returned in any order, so we put them into a set. // The site lists might be returned in any order, so we put them into a set.
std::set<std::string> site_names; std::set<std::string> site_names;
for (std::vector<SupervisedUserSiteList::Site>::const_iterator it = for (const SupervisedUserSiteList::Site& site : sites)
sites.begin(); it != sites.end(); ++it) { site_names.insert(base::UTF16ToUTF8(site.name));
site_names.insert(base::UTF16ToUTF8(it->name)); EXPECT_EQ(1u, site_names.count("YouTube"));
} EXPECT_EQ(1u, site_names.count("Homestar Runner"));
EXPECT_TRUE(site_names.count("YouTube") == 1u); EXPECT_EQ(1u, site_names.count(std::string()));
EXPECT_TRUE(site_names.count("Homestar Runner") == 1u); EXPECT_EQ(1u, site_names.count("Moose"));
EXPECT_TRUE(site_names.count(std::string()) == 1u);
EXPECT_TRUE(site_names.count("Moose") == 1u);
EXPECT_EQ(SupervisedUserURLFilter::ALLOW, EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
url_filter->GetFilteringBehaviorForURL(example_url)); url_filter->GetFilteringBehaviorForURL(example_url));
......
...@@ -173,11 +173,10 @@ SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing( ...@@ -173,11 +173,10 @@ SyncMergeResult SupervisedUserSettingsService::MergeDataAndStartSyncing(
// Clear all atomic and split settings, then recreate them from Sync data. // Clear all atomic and split settings, then recreate them from Sync data.
Clear(); Clear();
for (SyncDataList::const_iterator it = initial_sync_data.begin(); for (const SyncData& sync_data : initial_sync_data) {
it != initial_sync_data.end(); ++it) { DCHECK_EQ(SUPERVISED_USER_SETTINGS, sync_data.GetDataType());
DCHECK_EQ(SUPERVISED_USER_SETTINGS, it->GetDataType());
const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting =
it->GetSpecifics().managed_user_setting(); sync_data.GetSpecifics().managed_user_setting();
scoped_ptr<base::Value> value( scoped_ptr<base::Value> value(
JSONReader::Read(supervised_user_setting.value())); JSONReader::Read(supervised_user_setting.value()));
std::string name_suffix = supervised_user_setting.name(); std::string name_suffix = supervised_user_setting.name();
...@@ -248,24 +247,24 @@ SyncDataList SupervisedUserSettingsService::GetAllSyncData( ...@@ -248,24 +247,24 @@ SyncDataList SupervisedUserSettingsService::GetAllSyncData(
SyncError SupervisedUserSettingsService::ProcessSyncChanges( SyncError SupervisedUserSettingsService::ProcessSyncChanges(
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
const SyncChangeList& change_list) { const SyncChangeList& change_list) {
for (SyncChangeList::const_iterator it = change_list.begin(); for (const SyncChange& sync_change : change_list) {
it != change_list.end(); ++it) { SyncData data = sync_change.sync_data();
SyncData data = it->sync_data();
DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType()); DCHECK_EQ(SUPERVISED_USER_SETTINGS, data.GetDataType());
const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting = const ::sync_pb::ManagedUserSettingSpecifics& supervised_user_setting =
data.GetSpecifics().managed_user_setting(); data.GetSpecifics().managed_user_setting();
std::string key = supervised_user_setting.name(); std::string key = supervised_user_setting.name();
base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key); base::DictionaryValue* dict = GetDictionaryAndSplitKey(&key);
switch (it->change_type()) { SyncChange::SyncChangeType change_type = sync_change.change_type();
switch (change_type) {
case SyncChange::ACTION_ADD: case SyncChange::ACTION_ADD:
case SyncChange::ACTION_UPDATE: { case SyncChange::ACTION_UPDATE: {
scoped_ptr<base::Value> value( scoped_ptr<base::Value> value(
JSONReader::Read(supervised_user_setting.value())); JSONReader::Read(supervised_user_setting.value()));
if (dict->HasKey(key)) { if (dict->HasKey(key)) {
DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_ADD) DLOG_IF(WARNING, change_type == SyncChange::ACTION_ADD)
<< "Value for key " << key << " already exists"; << "Value for key " << key << " already exists";
} else { } else {
DLOG_IF(WARNING, it->change_type() == SyncChange::ACTION_UPDATE) DLOG_IF(WARNING, change_type == SyncChange::ACTION_UPDATE)
<< "Value for key " << key << " doesn't exist yet"; << "Value for key " << key << " doesn't exist yet";
} }
dict->SetWithoutPathExpansion(key, value.release()); dict->SetWithoutPathExpansion(key, value.release());
...@@ -379,8 +378,6 @@ void SupervisedUserSettingsService::InformSubscribers() { ...@@ -379,8 +378,6 @@ void SupervisedUserSettingsService::InformSubscribers() {
return; return;
scoped_ptr<base::DictionaryValue> settings = GetSettings(); scoped_ptr<base::DictionaryValue> settings = GetSettings();
for (std::vector<SettingsCallback>::iterator it = subscribers_.begin(); for (const auto& callback : subscribers_)
it != subscribers_.end(); ++it) { callback.Run(settings.get());
it->Run(settings.get());
}
} }
...@@ -221,23 +221,18 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) { ...@@ -221,23 +221,18 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) {
// Uploading should produce changes when we start syncing. // Uploading should produce changes when we start syncing.
StartSyncing(syncer::SyncDataList()); StartSyncing(syncer::SyncDataList());
ASSERT_EQ(3u, sync_processor_->changes().size()); ASSERT_EQ(3u, sync_processor_->changes().size());
for (syncer::SyncChangeList::const_iterator it = for (const syncer::SyncChange& sync_change : sync_processor_->changes()) {
sync_processor_->changes().begin(); ASSERT_TRUE(sync_change.IsValid());
it != sync_processor_->changes().end(); EXPECT_EQ(syncer::SyncChange::ACTION_ADD, sync_change.change_type());
++it) { VerifySyncDataItem(sync_change.sync_data());
ASSERT_TRUE(it->IsValid());
EXPECT_EQ(syncer::SyncChange::ACTION_ADD, it->change_type());
VerifySyncDataItem(it->sync_data());
} }
// It should also show up in local Sync data. // It should also show up in local Sync data.
syncer::SyncDataList sync_data = syncer::SyncDataList sync_data =
settings_service_.GetAllSyncData(syncer::SUPERVISED_USER_SETTINGS); settings_service_.GetAllSyncData(syncer::SUPERVISED_USER_SETTINGS);
EXPECT_EQ(3u, sync_data.size()); EXPECT_EQ(3u, sync_data.size());
for (syncer::SyncDataList::const_iterator it = sync_data.begin(); for (const syncer::SyncData& sync_data_item : sync_data)
it != sync_data.end(); ++it) { VerifySyncDataItem(sync_data_item);
VerifySyncDataItem(*it);
}
// Uploading after we have started syncing should work too. // Uploading after we have started syncing should work too.
sync_processor_->changes().clear(); sync_processor_->changes().clear();
...@@ -251,10 +246,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) { ...@@ -251,10 +246,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) {
sync_data = settings_service_.GetAllSyncData( sync_data = settings_service_.GetAllSyncData(
syncer::SUPERVISED_USER_SETTINGS); syncer::SUPERVISED_USER_SETTINGS);
EXPECT_EQ(4u, sync_data.size()); EXPECT_EQ(4u, sync_data.size());
for (syncer::SyncDataList::const_iterator it = sync_data.begin(); for (const syncer::SyncData& sync_data_item : sync_data)
it != sync_data.end(); ++it) { VerifySyncDataItem(sync_data_item);
VerifySyncDataItem(*it);
}
// Uploading an item with a previously seen key should create an UPDATE // Uploading an item with a previously seen key should create an UPDATE
// action. // action.
...@@ -269,10 +262,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) { ...@@ -269,10 +262,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) {
sync_data = settings_service_.GetAllSyncData( sync_data = settings_service_.GetAllSyncData(
syncer::SUPERVISED_USER_SETTINGS); syncer::SUPERVISED_USER_SETTINGS);
EXPECT_EQ(4u, sync_data.size()); EXPECT_EQ(4u, sync_data.size());
for (syncer::SyncDataList::const_iterator it = sync_data.begin(); for (const syncer::SyncData& sync_data_item : sync_data)
it != sync_data.end(); ++it) { VerifySyncDataItem(sync_data_item);
VerifySyncDataItem(*it);
}
sync_processor_->changes().clear(); sync_processor_->changes().clear();
UploadAtomicItem("fjord"); UploadAtomicItem("fjord");
...@@ -285,10 +276,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) { ...@@ -285,10 +276,8 @@ TEST_F(SupervisedUserSettingsServiceTest, UploadItem) {
sync_data = settings_service_.GetAllSyncData( sync_data = settings_service_.GetAllSyncData(
syncer::SUPERVISED_USER_SETTINGS); syncer::SUPERVISED_USER_SETTINGS);
EXPECT_EQ(4u, sync_data.size()); EXPECT_EQ(4u, sync_data.size());
for (syncer::SyncDataList::const_iterator it = sync_data.begin(); for (const syncer::SyncData& sync_data_item : sync_data)
it != sync_data.end(); ++it) { VerifySyncDataItem(sync_data_item);
VerifySyncDataItem(*it);
}
// The uploaded items should not show up as settings. // The uploaded items should not show up as settings.
const base::Value* value = NULL; const base::Value* value = NULL;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h" #include "chrome/browser/supervised_user/supervised_user_shared_settings_service.h"
#include <map>
#include <set>
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -202,13 +205,11 @@ SupervisedUserSharedSettingsService::MergeDataAndStartSyncing( ...@@ -202,13 +205,11 @@ SupervisedUserSharedSettingsService::MergeDataAndStartSyncing(
// Iterate over all initial sync data, and update it locally. This means that // Iterate over all initial sync data, and update it locally. This means that
// the value from the server always wins over a local value. // the value from the server always wins over a local value.
for (SyncDataList::const_iterator it = initial_sync_data.begin(); for (const SyncData& sync_data : initial_sync_data) {
it != initial_sync_data.end(); DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, sync_data.GetDataType());
++it) {
DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, it->GetDataType());
const ::sync_pb::ManagedUserSharedSettingSpecifics& const ::sync_pb::ManagedUserSharedSettingSpecifics&
supervised_user_shared_setting = supervised_user_shared_setting =
it->GetSpecifics().managed_user_shared_setting(); sync_data.GetSpecifics().managed_user_shared_setting();
scoped_ptr<Value> value( scoped_ptr<Value> value(
base::JSONReader::Read(supervised_user_shared_setting.value())); base::JSONReader::Read(supervised_user_shared_setting.value()));
const std::string& su_id = supervised_user_shared_setting.mu_id(); const std::string& su_id = supervised_user_shared_setting.mu_id();
...@@ -290,10 +291,8 @@ syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData( ...@@ -290,10 +291,8 @@ syncer::SyncDataList SupervisedUserSharedSettingsService::GetAllSyncData(
syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges(
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
const syncer::SyncChangeList& change_list) { const syncer::SyncChangeList& change_list) {
for (SyncChangeList::const_iterator it = change_list.begin(); for (const SyncChange& sync_change : change_list) {
it != change_list.end(); SyncData data = sync_change.sync_data();
++it) {
SyncData data = it->sync_data();
DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); DCHECK_EQ(SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType());
const ::sync_pb::ManagedUserSharedSettingSpecifics& const ::sync_pb::ManagedUserSharedSettingSpecifics&
supervised_user_shared_setting = supervised_user_shared_setting =
...@@ -304,7 +303,7 @@ syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( ...@@ -304,7 +303,7 @@ syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges(
DictionaryValue* update_dict = update.Get(); DictionaryValue* update_dict = update.Get();
DictionaryValue* dict = NULL; DictionaryValue* dict = NULL;
bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict); bool has_key = update_dict->GetDictionaryWithoutPathExpansion(key, &dict);
switch (it->change_type()) { switch (sync_change.change_type()) {
case SyncChange::ACTION_ADD: case SyncChange::ACTION_ADD:
case SyncChange::ACTION_UPDATE: { case SyncChange::ACTION_UPDATE: {
// Every setting we get from the server should have the acknowledged // Every setting we get from the server should have the acknowledged
...@@ -314,10 +313,10 @@ syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges( ...@@ -314,10 +313,10 @@ syncer::SyncError SupervisedUserSharedSettingsService::ProcessSyncChanges(
if (has_key) { if (has_key) {
// If the supervised user already exists, it should be an update // If the supervised user already exists, it should be an update
// action. // action.
DCHECK_EQ(SyncChange::ACTION_UPDATE, it->change_type()); DCHECK_EQ(SyncChange::ACTION_UPDATE, sync_change.change_type());
} else { } else {
// Otherwise, it should be an add action. // Otherwise, it should be an add action.
DCHECK_EQ(SyncChange::ACTION_ADD, it->change_type()); DCHECK_EQ(SyncChange::ACTION_ADD, sync_change.change_type());
dict = new DictionaryValue; dict = new DictionaryValue;
update_dict->SetWithoutPathExpansion(key, dict); update_dict->SetWithoutPathExpansion(key, dict);
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H_ #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H_ #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SHARED_SETTINGS_SERVICE_H_
#include <string>
#include "base/callback.h" #include "base/callback.h"
#include "base/callback_list.h" #include "base/callback_list.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
...@@ -101,11 +103,9 @@ class SupervisedUserSharedSettingsServiceTest : public ::testing::Test { ...@@ -101,11 +103,9 @@ class SupervisedUserSharedSettingsServiceTest : public ::testing::Test {
void VerifySyncChangesAndClear() { void VerifySyncChangesAndClear() {
SyncChangeList& changes = sync_processor_->changes(); SyncChangeList& changes = sync_processor_->changes();
for (SyncChangeList::const_iterator it = changes.begin(); for (const SyncChange& sync_change : changes) {
it != changes.end();
++it) {
const sync_pb::ManagedUserSharedSettingSpecifics& setting = const sync_pb::ManagedUserSharedSettingSpecifics& setting =
it->sync_data().GetSpecifics().managed_user_shared_setting(); sync_change.sync_data().GetSpecifics().managed_user_shared_setting();
EXPECT_EQ( EXPECT_EQ(
setting.value(), setting.value(),
ToJson(settings_service_.GetValue(setting.mu_id(), setting.key()))); ToJson(settings_service_.GetValue(setting.mu_id(), setting.key())));
......
...@@ -10,10 +10,6 @@ ...@@ -10,10 +10,6 @@
#include "base/values.h" #include "base/values.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
using base::DictionaryValue;
using base::ListValue;
using base::Value;
const int kSitelistFormatVersion = 1; const int kSitelistFormatVersion = 1;
const char kCategoriesKey[] = "categories"; const char kCategoriesKey[] = "categories";
...@@ -76,10 +72,9 @@ void AddWhitelistEntries(const base::DictionaryValue* site_dict, ...@@ -76,10 +72,9 @@ void AddWhitelistEntries(const base::DictionaryValue* site_dict,
const base::ListValue* whitelist = NULL; const base::ListValue* whitelist = NULL;
if (site_dict->GetList(kWhitelistKey, &whitelist)) { if (site_dict->GetList(kWhitelistKey, &whitelist)) {
found = true; found = true;
for (base::ListValue::const_iterator whitelist_it = whitelist->begin(); for (const base::Value* entry : *whitelist) {
whitelist_it != whitelist->end(); ++whitelist_it) {
std::string pattern; std::string pattern;
if (!(*whitelist_it)->GetAsString(&pattern)) { if (!entry->GetAsString(&pattern)) {
LOG(ERROR) << "Invalid whitelist entry"; LOG(ERROR) << "Invalid whitelist entry";
continue; continue;
} }
...@@ -92,10 +87,9 @@ void AddWhitelistEntries(const base::DictionaryValue* site_dict, ...@@ -92,10 +87,9 @@ void AddWhitelistEntries(const base::DictionaryValue* site_dict,
const base::ListValue* hash_list = NULL; const base::ListValue* hash_list = NULL;
if (site_dict->GetList(kHostnameHashesKey, &hash_list)) { if (site_dict->GetList(kHostnameHashesKey, &hash_list)) {
found = true; found = true;
for (base::ListValue::const_iterator hash_list_it = hash_list->begin(); for (const base::Value* entry : *hash_list) {
hash_list_it != hash_list->end(); ++hash_list_it) {
std::string hash; std::string hash;
if (!(*hash_list_it)->GetAsString(&hash)) { if (!entry->GetAsString(&hash)) {
LOG(ERROR) << "Invalid whitelist entry"; LOG(ERROR) << "Invalid whitelist entry";
continue; continue;
} }
...@@ -142,7 +136,7 @@ SupervisedUserSiteList::SupervisedUserSiteList( ...@@ -142,7 +136,7 @@ SupervisedUserSiteList::SupervisedUserSiteList(
SupervisedUserSiteList::~SupervisedUserSiteList() { SupervisedUserSiteList::~SupervisedUserSiteList() {
} }
SupervisedUserSiteList* SupervisedUserSiteList::Clone() { SupervisedUserSiteList* SupervisedUserSiteList::Clone() const {
return new SupervisedUserSiteList(extension_id_, path_); return new SupervisedUserSiteList(extension_id_, path_);
} }
...@@ -159,10 +153,9 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) { ...@@ -159,10 +153,9 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) {
if (!LazyLoad()) if (!LazyLoad())
return; return;
for (base::ListValue::iterator entry_it = sites_->begin(); for (const base::Value* site : *sites_) {
entry_it != sites_->end(); ++entry_it) { const base::DictionaryValue* entry = NULL;
base::DictionaryValue* entry = NULL; if (!site->GetAsDictionary(&entry)) {
if (!(*entry_it)->GetAsDictionary(&entry)) {
LOG(ERROR) << "Entry is invalid"; LOG(ERROR) << "Entry is invalid";
continue; continue;
} }
...@@ -175,10 +168,9 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) { ...@@ -175,10 +168,9 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) {
int category_id = 0; int category_id = 0;
const base::ListValue* categories = NULL; const base::ListValue* categories = NULL;
if (entry->GetList(kCategoriesKey, &categories)) { if (entry->GetList(kCategoriesKey, &categories)) {
for (base::ListValue::const_iterator it = categories->begin(); for (const base::Value* category_entry : *categories) {
it != categories->end(); ++it) {
std::string category; std::string category;
if (!(*it)->GetAsString(&category)) { if (!category_entry->GetAsString(&category)) {
LOG(ERROR) << "Invalid category"; LOG(ERROR) << "Invalid category";
continue; continue;
} }
...@@ -192,7 +184,7 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) { ...@@ -192,7 +184,7 @@ void SupervisedUserSiteList::GetSites(std::vector<Site>* sites) {
} }
bool SupervisedUserSiteList::LazyLoad() { bool SupervisedUserSiteList::LazyLoad() {
if (sites_.get()) if (sites_)
return true; return true;
JSONFileValueSerializer serializer(path_); JSONFileValueSerializer serializer(path_);
......
...@@ -58,7 +58,7 @@ class SupervisedUserSiteList { ...@@ -58,7 +58,7 @@ class SupervisedUserSiteList {
// Creates a copy of the site list. // Creates a copy of the site list.
// Caller takes ownership of the returned value. // Caller takes ownership of the returned value.
SupervisedUserSiteList* Clone(); SupervisedUserSiteList* Clone() const;
// Returns a list of all categories. // Returns a list of all categories.
// TODO(bauerb): The list is hardcoded for now, but if we allow custom // TODO(bauerb): The list is hardcoded for now, but if we allow custom
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chrome/browser/supervised_user/supervised_user_sync_service.h" #include "chrome/browser/supervised_user/supervised_user_sync_service.h"
#include <set>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/prefs/scoped_user_pref_update.h" #include "base/prefs/scoped_user_pref_update.h"
...@@ -417,11 +419,10 @@ SyncMergeResult SupervisedUserSyncService::MergeDataAndStartSyncing( ...@@ -417,11 +419,10 @@ SyncMergeResult SupervisedUserSyncService::MergeDataAndStartSyncing(
std::set<std::string> seen_ids; std::set<std::string> seen_ids;
int num_items_added = 0; int num_items_added = 0;
int num_items_modified = 0; int num_items_modified = 0;
for (SyncDataList::const_iterator it = initial_sync_data.begin(); for (const SyncData& sync_data : initial_sync_data) {
it != initial_sync_data.end(); ++it) { DCHECK_EQ(SUPERVISED_USERS, sync_data.GetDataType());
DCHECK_EQ(SUPERVISED_USERS, it->GetDataType());
const ManagedUserSpecifics& supervised_user = const ManagedUserSpecifics& supervised_user =
it->GetSpecifics().managed_user(); sync_data.GetSpecifics().managed_user();
base::DictionaryValue* value = new base::DictionaryValue(); base::DictionaryValue* value = new base::DictionaryValue();
value->SetString(kName, supervised_user.name()); value->SetString(kName, supervised_user.name());
value->SetBoolean(kAcknowledged, supervised_user.acknowledged()); value->SetBoolean(kAcknowledged, supervised_user.acknowledged());
...@@ -486,13 +487,12 @@ SyncError SupervisedUserSyncService::ProcessSyncChanges( ...@@ -486,13 +487,12 @@ SyncError SupervisedUserSyncService::ProcessSyncChanges(
SyncError error; SyncError error;
DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers); DictionaryPrefUpdate update(prefs_, prefs::kSupervisedUsers);
base::DictionaryValue* dict = update.Get(); base::DictionaryValue* dict = update.Get();
for (SyncChangeList::const_iterator it = change_list.begin(); for (const SyncChange& sync_change : change_list) {
it != change_list.end(); ++it) { SyncData data = sync_change.sync_data();
SyncData data = it->sync_data();
DCHECK_EQ(SUPERVISED_USERS, data.GetDataType()); DCHECK_EQ(SUPERVISED_USERS, data.GetDataType());
const ManagedUserSpecifics& supervised_user = const ManagedUserSpecifics& supervised_user =
data.GetSpecifics().managed_user(); data.GetSpecifics().managed_user();
switch (it->change_type()) { switch (sync_change.change_type()) {
case SyncChange::ACTION_ADD: case SyncChange::ACTION_ADD:
case SyncChange::ACTION_UPDATE: { case SyncChange::ACTION_UPDATE: {
// Every item we get from the server should be acknowledged. // Every item we get from the server should be acknowledged.
...@@ -505,7 +505,7 @@ SyncError SupervisedUserSyncService::ProcessSyncChanges( ...@@ -505,7 +505,7 @@ SyncError SupervisedUserSyncService::ProcessSyncChanges(
// an add action, it should not. // an add action, it should not.
DCHECK_EQ( DCHECK_EQ(
old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD, old_value ? SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD,
it->change_type()); sync_change.change_type());
// If the supervised user switched from unacknowledged to acknowledged, // If the supervised user switched from unacknowledged to acknowledged,
// we might need to continue with a registration. // we might need to continue with a registration.
...@@ -569,9 +569,7 @@ void SupervisedUserSyncService::NotifySupervisedUsersChanged() { ...@@ -569,9 +569,7 @@ void SupervisedUserSyncService::NotifySupervisedUsersChanged() {
void SupervisedUserSyncService::DispatchCallbacks() { void SupervisedUserSyncService::DispatchCallbacks() {
const base::DictionaryValue* supervised_users = const base::DictionaryValue* supervised_users =
prefs_->GetDictionary(prefs::kSupervisedUsers); prefs_->GetDictionary(prefs::kSupervisedUsers);
for (std::vector<SupervisedUsersCallback>::iterator it = callbacks_.begin(); for (const auto& callback : callbacks_)
it != callbacks_.end(); ++it) { callback.Run(supervised_users);
it->Run(supervised_users);
}
callbacks_.clear(); callbacks_.clear();
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SYNC_SERVICE_H_ #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SYNC_SERVICE_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SYNC_SERVICE_H_ #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SYNC_SERVICE_H_
#include <string>
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
......
...@@ -68,10 +68,9 @@ SyncError MockChangeProcessor::ProcessSyncChanges( ...@@ -68,10 +68,9 @@ SyncError MockChangeProcessor::ProcessSyncChanges(
} }
SyncChange MockChangeProcessor::GetChange(const std::string& id) const { SyncChange MockChangeProcessor::GetChange(const std::string& id) const {
for (SyncChangeList::const_iterator it = change_list_.begin(); for (const SyncChange& sync_change : change_list_) {
it != change_list_.end(); ++it) { if (sync_change.sync_data().GetSpecifics().managed_user().id() == id)
if (it->sync_data().GetSpecifics().managed_user().id() == id) return sync_change;
return *it;
} }
return SyncChange(); return SyncChange();
} }
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/supervised_user/supervised_user_url_filter.h" #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
#include <set>
#include <utility>
#include "base/containers/hash_tables.h" #include "base/containers/hash_tables.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
...@@ -119,22 +122,14 @@ void FilterBuilder::AddSiteList(SupervisedUserSiteList* site_list) { ...@@ -119,22 +122,14 @@ void FilterBuilder::AddSiteList(SupervisedUserSiteList* site_list) {
std::vector<SupervisedUserSiteList::Site> sites; std::vector<SupervisedUserSiteList::Site> sites;
site_list->GetSites(&sites); site_list->GetSites(&sites);
int site_id = contents_->sites.size(); int site_id = contents_->sites.size();
for (std::vector<SupervisedUserSiteList::Site>::const_iterator it = for (const SupervisedUserSiteList::Site& site : sites) {
sites.begin(); it != sites.end(); ++it) {
const SupervisedUserSiteList::Site& site = *it;
contents_->sites.push_back(site); contents_->sites.push_back(site);
for (std::vector<std::string>::const_iterator pattern_it = for (const std::string& pattern : site.patterns)
site.patterns.begin(); AddPattern(pattern, site_id);
pattern_it != site.patterns.end(); ++pattern_it) {
AddPattern(*pattern_it, site_id);
}
for (std::vector<std::string>::const_iterator hash_it = for (const std::string& hash : site.hostname_hashes)
site.hostname_hashes.begin(); AddHostnameHash(hash, site_id);
hash_it != site.hostname_hashes.end(); ++hash_it) {
AddHostnameHash(*hash_it, site_id);
}
site_id++; site_id++;
} }
...@@ -151,10 +146,9 @@ scoped_ptr<SupervisedUserURLFilter::Contents> CreateWhitelistFromPatterns( ...@@ -151,10 +146,9 @@ scoped_ptr<SupervisedUserURLFilter::Contents> CreateWhitelistFromPatterns(
DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
FilterBuilder builder; FilterBuilder builder;
for (std::vector<std::string>::const_iterator it = patterns.begin(); for (const std::string& pattern : patterns) {
it != patterns.end(); ++it) {
// TODO(bauerb): We should create a fake site for the whitelist. // TODO(bauerb): We should create a fake site for the whitelist.
builder.AddPattern(*it, -1); builder.AddPattern(pattern, -1);
} }
return builder.Build(); return builder.Build();
...@@ -166,10 +160,8 @@ LoadWhitelistsOnBlockingPoolThread( ...@@ -166,10 +160,8 @@ LoadWhitelistsOnBlockingPoolThread(
DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
FilterBuilder builder; FilterBuilder builder;
for (ScopedVector<SupervisedUserSiteList>::iterator it = site_lists.begin(); for (SupervisedUserSiteList* site_list : site_lists)
it != site_lists.end(); ++it) { builder.AddSiteList(site_list);
builder.AddSiteList(*it);
}
return builder.Build(); return builder.Build();
} }
...@@ -282,11 +274,10 @@ SupervisedUserURLFilter::GetFilteringBehaviorForURL(const GURL& url) const { ...@@ -282,11 +274,10 @@ SupervisedUserURLFilter::GetFilteringBehaviorForURL(const GURL& url) const {
// Look for patterns matching the hostname, with a value that is different // Look for patterns matching the hostname, with a value that is different
// from the default (a value of true in the map meaning allowed). // from the default (a value of true in the map meaning allowed).
for (std::map<std::string, bool>::const_iterator host_it = for (const std::pair<std::string, bool>& host_entry : host_map_) {
host_map_.begin(); host_it != host_map_.end(); ++host_it) { if ((host_entry.second == (default_behavior_ == BLOCK)) &&
if ((host_it->second == (default_behavior_ == BLOCK)) && HostMatchesPattern(host, host_entry.first)) {
HostMatchesPattern(host, host_it->first)) { return host_entry.second ? ALLOW : BLOCK;
return host_it->second ? ALLOW : BLOCK;
} }
} }
...@@ -318,10 +309,9 @@ void SupervisedUserURLFilter::GetSites( ...@@ -318,10 +309,9 @@ void SupervisedUserURLFilter::GetSites(
std::vector<SupervisedUserSiteList::Site*>* sites) const { std::vector<SupervisedUserSiteList::Site*>* sites) const {
std::set<URLMatcherConditionSet::ID> matching_ids = std::set<URLMatcherConditionSet::ID> matching_ids =
contents_->url_matcher.MatchURL(url); contents_->url_matcher.MatchURL(url);
for (std::set<URLMatcherConditionSet::ID>::const_iterator it = for (const URLMatcherConditionSet::ID& id : matching_ids) {
matching_ids.begin(); it != matching_ids.end(); ++it) {
std::map<URLMatcherConditionSet::ID, int>::const_iterator entry = std::map<URLMatcherConditionSet::ID, int>::const_iterator entry =
contents_->matcher_site_map.find(*it); contents_->matcher_site_map.find(id);
if (entry == contents_->matcher_site_map.end()) { if (entry == contents_->matcher_site_map.end()) {
NOTREACHED(); NOTREACHED();
continue; continue;
......
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_URL_FILTER_H_ #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_URL_FILTER_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_URL_FILTER_H_ #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_URL_FILTER_H_
#include <map>
#include <string>
#include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment