OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |
| 6 #define CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "chrome/browser/prefs/pref_member.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 // Holds URLs for which we want to run the encoding detector. The instance is |
| 20 // held by ProfileIOData and lives on IO thread. |
| 21 class GarbledTextURLTracker |
| 22 : public base::SupportsWeakPtr<GarbledTextURLTracker>, |
| 23 public base::NonThreadSafe { |
| 24 public: |
| 25 typedef std::vector<GURL> GarbledURLs; |
| 26 typedef std::set<std::string> Blacklist; |
| 27 |
| 28 GarbledTextURLTracker(const BooleanPrefMember& enabled, |
| 29 const Blacklist& blacklist); |
| 30 ~GarbledTextURLTracker(); |
| 31 |
| 32 // Returns true if we should run the encoding detector for the resource. |
| 33 // If |enabled_| is false, the function returns false. |
| 34 bool NeedsEncodingDetection(const GURL& url) const; |
| 35 |
| 36 // Adds normalized |garbled_urls| to the blacklist and return the delta as |
| 37 // |blacklist_delta|. Does nothing if |enabled_| is false. |
| 38 void UpdateBlacklist(const GarbledURLs& garbled_urls, |
| 39 Blacklist* blacklist_delta); |
| 40 |
| 41 private: |
| 42 friend class GarbledTextHelperTest; |
| 43 friend class GarbledTextServiceTest; |
| 44 |
| 45 // Returns the normalized representation of the given |url|, with which we |
| 46 // actually register and compare URLs internally. |
| 47 // Currently this method naively returns the host part of the given |url| |
| 48 // (i.e. url.host()), assuming that if a page needs encoding detection other |
| 49 // pages on the same site would need it as well. |
| 50 std::string Normalize(const GURL& url) const; |
| 51 |
| 52 const BooleanPrefMember& enabled_; |
| 53 Blacklist blacklist_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(GarbledTextURLTracker); |
| 56 }; |
| 57 |
| 58 #endif // CHROME_BROWSER_GARBLED_TEXT_URL_TRACKER_H_ |
OLD | NEW |