summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 11:28:53 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-22 11:28:53 +0000
commitf574674ae65bfd387a518138ad357afa4a411a2a (patch)
tree9b2320c0ab6e346918733bf218c29dd8f64e9ab3 /chrome
parent9c7c40e33b676b2a482f6bbb7adaa167a4fae28d (diff)
downloadchromium_src-f574674ae65bfd387a518138ad357afa4a411a2a.zip
chromium_src-f574674ae65bfd387a518138ad357afa4a411a2a.tar.gz
chromium_src-f574674ae65bfd387a518138ad357afa4a411a2a.tar.bz2
Readability review for joaodasilva
Added the URLBlacklistManager and the URLBlacklist filter matcher Review URL: http://codereview.chromium.org/7930011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/policy/url_blacklist_manager.cc48
-rw-r--r--chrome/browser/policy/url_blacklist_manager.h18
2 files changed, 36 insertions, 30 deletions
diff --git a/chrome/browser/policy/url_blacklist_manager.cc b/chrome/browser/policy/url_blacklist_manager.cc
index 2c90093..44791a5 100644
--- a/chrome/browser/policy/url_blacklist_manager.cc
+++ b/chrome/browser/policy/url_blacklist_manager.cc
@@ -29,7 +29,7 @@ typedef std::vector<std::string> StringVector;
StringVector* ListValueToStringVector(const base::ListValue* list) {
StringVector* vector = new StringVector;
- if (!list)
+ if (list == NULL)
return vector;
vector->reserve(list->GetSize());
@@ -66,14 +66,30 @@ void BuildBlacklist(URLBlacklist* blacklist,
void SetBlacklistOnIO(base::WeakPtr<URLBlacklistManager> blacklist_manager,
URLBlacklist* blacklist) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (blacklist_manager)
+ if (blacklist_manager) {
blacklist_manager->SetBlacklist(blacklist);
- else
+ } else {
delete blacklist;
+ }
}
} // namespace
+struct URLBlacklist::PathFilter {
+ explicit PathFilter(const std::string& path, uint16 port, bool match)
+ : path_prefix(path),
+ port(port),
+ blocked_schemes(0),
+ allowed_schemes(0),
+ match_subdomains(match) {}
+
+ std::string path_prefix;
+ uint16 port;
+ uint8 blocked_schemes;
+ uint8 allowed_schemes;
+ bool match_subdomains;
+};
+
URLBlacklist::URLBlacklist() {
}
@@ -106,7 +122,7 @@ bool URLBlacklist::IsURLBlocked(const GURL& url) const {
// to those.
bool is_matching_subdomains = false;
const bool host_is_ip = url.HostIsIPAddress();
- for (;;) {
+ while (1) {
HostFilterTable::const_iterator host_filter = host_filters_.find(host);
if (host_filter != host_filters_.end()) {
const PathFilterList* list = host_filter->second;
@@ -179,16 +195,17 @@ bool URLBlacklist::IsURLBlocked(const GURL& url) const {
// static
bool URLBlacklist::SchemeToFlag(const std::string& scheme, SchemeFlag* flag) {
- if (scheme.empty())
+ if (scheme.empty()) {
*flag = SCHEME_ALL;
- else if (scheme == "http")
+ } else if (scheme == "http") {
*flag = SCHEME_HTTP;
- else if (scheme == "https")
+ } else if (scheme == "https") {
*flag = SCHEME_HTTPS;
- else if (scheme == "ftp")
+ } else if (scheme == "ftp") {
*flag = SCHEME_FTP;
- else
+ } else {
return false;
+ }
return true;
}
@@ -241,19 +258,18 @@ void URLBlacklist::AddFilter(const std::string& filter, bool block) {
std::string host;
uint16 port;
std::string path;
- SchemeFlag flag;
- bool match_subdomains = true;
-
if (!FilterToComponents(filter, &scheme, &host, &port, &path)) {
LOG(WARNING) << "Invalid filter, ignoring: " << filter;
return;
}
+ SchemeFlag flag;
if (!SchemeToFlag(scheme, &flag)) {
LOG(WARNING) << "Unsupported scheme in filter, ignoring filter: " << filter;
return;
}
+ bool match_subdomains = true;
// Special syntax to disable subdomain matching.
if (!host.empty() && host[0] == '.') {
host.erase(0, 1);
@@ -273,8 +289,9 @@ void URLBlacklist::AddFilter(const std::string& filter, bool block) {
PathFilterList::iterator it;
for (it = list->begin(); it != list->end(); ++it) {
if (it->port == port && it->match_subdomains == match_subdomains &&
- it->path_prefix == path)
+ it->path_prefix == path) {
break;
+ }
}
PathFilter* path_filter;
if (it == list->end()) {
@@ -284,10 +301,11 @@ void URLBlacklist::AddFilter(const std::string& filter, bool block) {
path_filter = &(*it);
}
- if (block)
+ if (block) {
path_filter->blocked_schemes |= flag;
- else
+ } else {
path_filter->allowed_schemes |= flag;
+ }
}
URLBlacklistManager::URLBlacklistManager(PrefService* pref_service)
diff --git a/chrome/browser/policy/url_blacklist_manager.h b/chrome/browser/policy/url_blacklist_manager.h
index c085973..e3b7f25 100644
--- a/chrome/browser/policy/url_blacklist_manager.h
+++ b/chrome/browser/policy/url_blacklist_manager.h
@@ -39,7 +39,8 @@ class URLBlacklist {
URLBlacklist();
virtual ~URLBlacklist();
- // URLs matching |filter| will be blocked.
+ // URLs matching |filter| will be blocked. The filter format is documented
+ // at http://www.chromium.org/administrators/url-blacklist-filter-format
void Block(const std::string& filter);
// URLs matching |filter| will be allowed. If |filter| is both Blocked and
@@ -65,20 +66,7 @@ class URLBlacklist {
uint16* port,
std::string* path);
private:
- struct PathFilter {
- explicit PathFilter(const std::string& path, uint16 port, bool match)
- : path_prefix(path),
- port(port),
- blocked_schemes(0),
- allowed_schemes(0),
- match_subdomains(match) {}
-
- std::string path_prefix;
- uint16 port;
- uint8 blocked_schemes;
- uint8 allowed_schemes;
- bool match_subdomains;
- };
+ struct PathFilter;
typedef std::vector<PathFilter> PathFilterList;
typedef base::hash_map<std::string, PathFilterList*> HostFilterTable;