| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ | 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ | 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ |
| 7 | 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 8 #include <array> | 11 #include <array> |
| 9 #include <string> | 12 #include <string> |
| 10 #include <vector> | 13 #include <vector> |
| 11 | 14 |
| 12 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 13 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/sha1.h" | 20 #include "base/sha1.h" |
| 17 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 18 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 19 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 20 | 24 |
| 21 class Profile; | 25 class Profile; |
| 22 | 26 |
| 23 namespace base { | 27 namespace base { |
| 24 class DictionaryValue; | 28 class DictionaryValue; |
| 25 class ListValue; | 29 class ListValue; |
| 26 class Value; | 30 class Value; |
| 27 } | 31 } |
| 28 | 32 |
| 29 // This class represents the content of a supervised user whitelist. It is | 33 // This class represents the content of a supervised user whitelist. It is |
| 30 // loaded from a JSON file inside the extension bundle, which defines the sites | 34 // loaded from a JSON file inside the extension bundle, which defines the sites |
| 31 // on the list. | 35 // on the list. |
| 32 // All whitelists are combined in the SupervisedUserURLFilter, which can tell | 36 // All whitelists are combined in the SupervisedUserURLFilter, which can tell |
| 33 // for a given URL if it is part of any whitelist. Effectively, | 37 // for a given URL if it is part of any whitelist. Effectively, |
| 34 // SupervisedUserURLFilter then acts as a big whitelist which is the union of | 38 // SupervisedUserURLFilter then acts as a big whitelist which is the union of |
| 35 // all the whitelists. | 39 // all the whitelists. |
| 36 class SupervisedUserSiteList | 40 class SupervisedUserSiteList |
| 37 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { | 41 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { |
| 38 public: | 42 public: |
| 39 class HostnameHash { | 43 class HostnameHash { |
| 40 public: | 44 public: |
| 41 explicit HostnameHash(const std::string& hostname); | 45 explicit HostnameHash(const std::string& hostname); |
| 42 // |bytes| must have a size of at least |base::kSHA1Length|. | 46 // |bytes| must have a size of at least |base::kSHA1Length|. |
| 43 explicit HostnameHash(const std::vector<uint8>& bytes); | 47 explicit HostnameHash(const std::vector<uint8_t>& bytes); |
| 44 | 48 |
| 45 bool operator==(const HostnameHash& rhs) const; | 49 bool operator==(const HostnameHash& rhs) const; |
| 46 | 50 |
| 47 // Returns a hash code suitable for putting this into hash maps. | 51 // Returns a hash code suitable for putting this into hash maps. |
| 48 size_t hash() const; | 52 size_t hash() const; |
| 49 | 53 |
| 50 private: | 54 private: |
| 51 std::array<uint8, base::kSHA1Length> bytes_; | 55 std::array<uint8_t, base::kSHA1Length> bytes_; |
| 52 // Copy and assign are allowed. | 56 // Copy and assign are allowed. |
| 53 }; | 57 }; |
| 54 | 58 |
| 55 using LoadedCallback = | 59 using LoadedCallback = |
| 56 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; | 60 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; |
| 57 | 61 |
| 58 // Asynchronously loads the site list from |file| and calls |callback| with | 62 // Asynchronously loads the site list from |file| and calls |callback| with |
| 59 // the newly created object. | 63 // the newly created object. |
| 60 static void Load(const base::string16& title, | 64 static void Load(const base::string16& title, |
| 61 const base::FilePath& file, | 65 const base::FilePath& file, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 91 // A list of URL patterns that should be whitelisted. | 95 // A list of URL patterns that should be whitelisted. |
| 92 std::vector<std::string> patterns_; | 96 std::vector<std::string> patterns_; |
| 93 | 97 |
| 94 // A list of SHA1 hashes of hostnames that should be whitelisted. | 98 // A list of SHA1 hashes of hostnames that should be whitelisted. |
| 95 std::vector<HostnameHash> hostname_hashes_; | 99 std::vector<HostnameHash> hostname_hashes_; |
| 96 | 100 |
| 97 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); | 101 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ | 104 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ |
| OLD | NEW |