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

Unified Diff: chrome/browser/managed_mode_url_filter.cc

Issue 10824257: Add ManagedModeURLFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fix Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/managed_mode_url_filter.h ('k') | chrome/browser/managed_mode_url_filter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/managed_mode_url_filter.cc
diff --git a/chrome/browser/managed_mode_url_filter.cc b/chrome/browser/managed_mode_url_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ea819901d128f65b6a8d3596251ba31ed0379545
--- /dev/null
+++ b/chrome/browser/managed_mode_url_filter.cc
@@ -0,0 +1,104 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/managed_mode_url_filter.h"
+
+#include "base/file_path.h"
+#include "base/json/json_file_value_serializer.h"
+#include "base/task_runner_util.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/policy/url_blacklist_manager.h"
+#include "chrome/common/extensions/matcher/url_matcher.h"
+#include "content/public/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+
+using content::BrowserThread;
+using extensions::URLMatcher;
+using extensions::URLMatcherConditionSet;
+
+namespace {
+
+scoped_ptr<URLMatcher> CreateWhitelistOnBlockingPoolThread(
+ const std::vector<std::string>& patterns) {
+ DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
+
+ scoped_ptr<URLMatcher> url_matcher(new URLMatcher());
+ URLMatcherConditionSet::Vector all_conditions;
+ URLMatcherConditionSet::ID id = 0;
+ for (std::vector<std::string>::const_iterator it = patterns.begin();
+ it != patterns.end(); ++it) {
+ std::string scheme;
+ std::string host;
+ uint16 port;
+ std::string path;
+ bool match_subdomains = true;
+ if (!policy::URLBlacklist::FilterToComponents(
+ *it, &scheme, &host, &match_subdomains, &port, &path)) {
+ LOG(ERROR) << "Invalid pattern " << *it;
+ continue;
+ }
+
+ scoped_refptr<extensions::URLMatcherConditionSet> condition_set =
+ policy::URLBlacklist::CreateConditionSet(
+ url_matcher.get(), ++id,
+ scheme, host, match_subdomains, port, path);
+ all_conditions.push_back(condition_set);
+ }
+ url_matcher->AddConditionSets(all_conditions);
+ return url_matcher.Pass();
+}
+
+} // namespace
+
+ManagedModeURLFilter::ManagedModeURLFilter()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
+ active_(false),
+ url_matcher_(new URLMatcher()) {
+ // Detach from the current thread so we can be constructed on a different
+ // thread than the one where we're used.
+ DetachFromThread();
+}
+
+ManagedModeURLFilter::~ManagedModeURLFilter() {
+ DCHECK(CalledOnValidThread());
+}
+
+bool ManagedModeURLFilter::IsURLWhitelisted(const GURL& url) const {
+ DCHECK(CalledOnValidThread());
+
+ if (!active_)
+ return true;
+
+ if (!policy::URLBlacklist::HasStandardScheme(url))
+ return true;
+
+ std::set<URLMatcherConditionSet::ID> matching_ids =
+ url_matcher_->MatchURL(url);
+ return !matching_ids.empty();
+}
+
+void ManagedModeURLFilter::SetActive(bool active) {
+ DCHECK(CalledOnValidThread());
+ active_ = active;
+}
+
+void ManagedModeURLFilter::SetWhitelist(
+ const std::vector<std::string>& patterns,
+ const base::Closure& continuation) {
+ DCHECK(CalledOnValidThread());
+
+ base::PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&CreateWhitelistOnBlockingPoolThread, patterns),
+ base::Bind(&ManagedModeURLFilter::SetURLMatcher,
+ weak_ptr_factory_.GetWeakPtr(), continuation));
+}
+
+void ManagedModeURLFilter::SetURLMatcher(const base::Closure& continuation,
+ scoped_ptr<URLMatcher> url_matcher) {
+ DCHECK(CalledOnValidThread());
+ url_matcher_ = url_matcher.Pass();
+ continuation.Run();
+}
« no previous file with comments | « chrome/browser/managed_mode_url_filter.h ('k') | chrome/browser/managed_mode_url_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698