Chromium Code Reviews| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/sha1.h" | |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class DictionaryValue; | 23 class DictionaryValue; |
| 23 class ListValue; | 24 class ListValue; |
| 24 class Value; | 25 class Value; |
| 25 } | 26 } |
| 26 | 27 |
| 27 // This class represents the content of a supervised user whitelist. It is | 28 // This class represents the content of a supervised user whitelist. It is |
| 28 // loaded from a JSON file inside the extension bundle, which defines the sites | 29 // loaded from a JSON file inside the extension bundle, which defines the sites |
| 29 // on the list. | 30 // on the list. |
| 30 // All whitelists are combined in the SupervisedUserURLFilter, which can tell | 31 // All whitelists are combined in the SupervisedUserURLFilter, which can tell |
| 31 // for a given URL if it is part of any whitelist. Effectively, | 32 // for a given URL if it is part of any whitelist. Effectively, |
| 32 // SupervisedUserURLFilter then acts as a big whitelist which is the union of | 33 // SupervisedUserURLFilter then acts as a big whitelist which is the union of |
| 33 // all the whitelists. | 34 // all the whitelists. |
| 34 class SupervisedUserSiteList | 35 class SupervisedUserSiteList |
| 35 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { | 36 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { |
| 36 public: | 37 public: |
| 38 class HostnameHash { | |
| 39 public: | |
| 40 explicit HostnameHash(const std::string& hostname); | |
| 41 // |bytes| must have a size of at least |base::kSHA1Length|. | |
| 42 explicit HostnameHash(const std::vector<uint8>& bytes); | |
| 43 | |
| 44 bool operator==(const HostnameHash& rhs) const; | |
| 45 | |
| 46 const uint8* data() const { return bytes_; } | |
| 47 | |
| 48 private: | |
| 49 uint8 bytes_[base::kSHA1Length]; | |
|
Bernhard Bauer
2015/12/01 12:42:32
DISALLOW_COPY_AND_ASSIGN? Or add a comment that co
Marc Treib
2015/12/03 11:21:11
Yeah, I meant to allow copying here. Comment added
| |
| 50 }; | |
| 51 | |
| 37 using LoadedCallback = | 52 using LoadedCallback = |
| 38 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; | 53 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; |
| 39 | 54 |
| 40 // Asynchronously loads the site list from |file| and calls |callback| with | 55 // Asynchronously loads the site list from |file| and calls |callback| with |
| 41 // the newly created object. | 56 // the newly created object. |
| 42 static void Load(const base::string16& title, | 57 static void Load(const base::string16& title, |
| 43 const base::FilePath& file, | 58 const base::FilePath& file, |
| 44 const LoadedCallback& callback); | 59 const LoadedCallback& callback); |
| 45 | 60 |
| 46 const base::string16& title() const { return title_; } | 61 const base::string16& title() const { return title_; } |
| 47 const GURL& entry_point() const { return entry_point_; } | 62 const GURL& entry_point() const { return entry_point_; } |
| 48 const std::vector<std::string>& patterns() const { return patterns_; } | 63 const std::vector<std::string>& patterns() const { return patterns_; } |
| 49 const std::vector<std::string>& hostname_hashes() const { | 64 const std::vector<HostnameHash>& hostname_hashes() const { |
| 50 return hostname_hashes_; | 65 return hostname_hashes_; |
| 51 } | 66 } |
| 52 | 67 |
| 53 private: | 68 private: |
| 54 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>; | 69 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>; |
| 55 | 70 |
| 56 SupervisedUserSiteList(const base::string16& title, | 71 SupervisedUserSiteList(const base::string16& title, |
| 57 const GURL& entry_point, | 72 const GURL& entry_point, |
| 58 const base::ListValue* patterns, | 73 const base::ListValue* patterns, |
| 59 const base::ListValue* hostname_hashes); | 74 const base::ListValue* hostname_hashes); |
| 60 ~SupervisedUserSiteList(); | 75 ~SupervisedUserSiteList(); |
| 61 | 76 |
| 62 // Static private so it can access the private constructor. | 77 // Static private so it can access the private constructor. |
| 63 static void OnJsonLoaded( | 78 static void OnJsonLoaded( |
| 64 const base::string16& title, | 79 const base::string16& title, |
| 65 const base::FilePath& path, | 80 const base::FilePath& path, |
| 66 base::TimeTicks start_time, | 81 base::TimeTicks start_time, |
| 67 const SupervisedUserSiteList::LoadedCallback& callback, | 82 const SupervisedUserSiteList::LoadedCallback& callback, |
| 68 scoped_ptr<base::Value> value); | 83 scoped_ptr<base::Value> value); |
| 69 | 84 |
| 70 base::string16 title_; | 85 base::string16 title_; |
| 71 GURL entry_point_; | 86 GURL entry_point_; |
| 72 | 87 |
| 73 // A list of URL patterns that should be whitelisted. | 88 // A list of URL patterns that should be whitelisted. |
| 74 std::vector<std::string> patterns_; | 89 std::vector<std::string> patterns_; |
| 75 | 90 |
| 76 // A list of hex-encoded SHA1 hashes of hostnames that should be whitelisted. | 91 // A list of SHA1 hashes of hostnames that should be whitelisted. |
| 77 std::vector<std::string> hostname_hashes_; | 92 std::vector<HostnameHash> hostname_hashes_; |
| 78 | 93 |
| 79 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); | 94 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); |
| 80 }; | 95 }; |
| 81 | 96 |
| 82 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ | 97 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ |
| OLD | NEW |