Index: chrome/browser/garbled_text_url_tracker.h |
diff --git a/chrome/browser/garbled_text_url_tracker.h b/chrome/browser/garbled_text_url_tracker.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0fcc08b79b48c4e432c61cdd8ea34ab0c7fb9067 |
--- /dev/null |
+++ b/chrome/browser/garbled_text_url_tracker.h |
@@ -0,0 +1,58 @@ |
+// 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. |
+ |
+#ifndef CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |
+#define CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |
+#pragma once |
+ |
+#include <set> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "chrome/browser/prefs/pref_member.h" |
+ |
+class GURL; |
+ |
+// Holds URLs for which we want to run the encoding detector. The instance is |
+// held by ProfileIOData and lives on IO thread. |
+class GarbledTextURLTracker |
+ : public base::SupportsWeakPtr<GarbledTextURLTracker>, |
+ public base::NonThreadSafe { |
+ public: |
+ typedef std::vector<GURL> GarbledURLs; |
+ typedef std::set<std::string> Blacklist; |
+ |
+ GarbledTextURLTracker(const BooleanPrefMember& enabled, |
+ const Blacklist& blacklist); |
+ ~GarbledTextURLTracker(); |
+ |
+ // Returns true if we should run the encoding detector for the resource. |
+ // If |enabled_| is false, the function returns false. |
+ bool NeedsEncodingDetection(const GURL& url) const; |
+ |
+ // Adds normalized |garbled_urls| to the blacklist and return the delta as |
+ // |blacklist_delta|. Does nothing if |enabled_| is false. |
+ void UpdateBlacklist(const GarbledURLs& garbled_urls, |
+ Blacklist* blacklist_delta); |
+ |
+ private: |
+ friend class GarbledTextHelperTest; |
+ friend class GarbledTextServiceTest; |
+ |
+ // Returns the normalized representation of the given |url|, with which we |
+ // actually register and compare URLs internally. |
+ // Currently this method naively returns the host part of the given |url| |
+ // (i.e. url.host()), assuming that if a page needs encoding detection other |
+ // pages on the same site would need it as well. |
+ std::string Normalize(const GURL& url) const; |
+ |
+ const BooleanPrefMember& enabled_; |
+ Blacklist blacklist_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GarbledTextURLTracker); |
+}; |
+ |
+#endif // CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |