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/strings/string16.h" | |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "url/gurl.h" | |
16 | 18 |
17 class Profile; | 19 class Profile; |
18 | 20 |
19 namespace base { | 21 namespace base { |
20 class DictionaryValue; | 22 class DictionaryValue; |
21 class ListValue; | 23 class ListValue; |
22 class Value; | 24 class Value; |
23 } | 25 } |
24 | 26 |
25 // This class represents a "site list" that is part of a content pack. It is | 27 // This class represents the content of a supervised user whitelist. It is |
26 // loaded from a JSON file inside the extension bundle, which defines the sites | 28 // loaded from a JSON file inside the extension bundle, which defines the sites |
27 // on the list. | 29 // on the list. |
28 // Every site has -- among other attributes -- a whitelist of URLs that are | 30 // All whitelists are combined in the SupervisedUserURLFilter, which can tell |
29 // required to use it. All sites from all installed content packs together with | 31 // for a given URL if it is part of any whitelist. Effectively, |
30 // their respective whitelists are combined in the SupervisedUserURLFilter, | 32 // SupervisedUserURLFilter then acts as a big whitelist which is the union of |
31 // which can tell for a given URL if it is part of the whitelist for any site. | 33 // all the whitelists. |
32 // Effectively, SupervisedUserURLFilter then acts as a big whitelist which is | |
33 // the union of the whitelists in all sites in all content packs. See | |
34 // http://goo.gl/cBCB8 for a diagram. | |
35 class SupervisedUserSiteList | 34 class SupervisedUserSiteList |
36 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { | 35 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { |
37 public: | 36 public: |
38 typedef base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)> | 37 using LoadedCallback = |
39 LoadedCallback; | 38 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; |
40 | |
41 struct Site { | |
42 explicit Site(const base::string16& name); | |
43 ~Site(); | |
44 | |
45 // The human-readable name for the site. | |
46 base::string16 name; | |
47 | |
48 // A list of URL patterns that should be whitelisted for the site. | |
49 std::vector<std::string> patterns; | |
50 | |
51 // A list of hex-encoded SHA1 hashes of hostnames that should be whitelisted | |
52 // for the site. | |
53 std::vector<std::string> hostname_hashes; | |
54 | |
55 // Copying and assignment is allowed. | |
56 }; | |
57 | 39 |
58 // Asynchronously loads the site list from |file| and calls |callback| with | 40 // Asynchronously loads the site list from |file| and calls |callback| with |
59 // the newly created object. | 41 // the newly created object. |
60 static void Load(const base::FilePath& file, const LoadedCallback& callback); | 42 static void Load(const base::string16& title, |
43 const base::FilePath& file, | |
44 const LoadedCallback& callback); | |
61 | 45 |
62 // Returns a list of all sites in this site list. | 46 const base::string16& title() const { return title_; } |
63 const std::vector<Site>& sites() const { return sites_; } | 47 const GURL& entry_point() const { return entry_point_; } |
48 const std::vector<std::string>& patterns() const { return patterns_; } | |
49 const std::vector<std::string>& hostname_hashes() const { | |
50 return hostname_hashes_; | |
51 } | |
64 | 52 |
65 private: | 53 private: |
66 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>; | 54 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>; |
67 | 55 |
68 explicit SupervisedUserSiteList(const base::ListValue& sites); | 56 explicit SupervisedUserSiteList(const base::string16& title, |
57 GURL entry_point, | |
Sorin Jianu
2015/11/18 16:18:53
Pass GURL parameter by reference to const?
Also, e
Marc Treib
2015/11/18 16:33:37
Done.
| |
58 const base::ListValue* patterns, | |
59 const base::ListValue* hostname_hashes); | |
69 ~SupervisedUserSiteList(); | 60 ~SupervisedUserSiteList(); |
70 | 61 |
71 // Static private so it can access the private constructor. | 62 // Static private so it can access the private constructor. |
72 static void OnJsonLoaded( | 63 static void OnJsonLoaded( |
64 const base::string16& title, | |
73 const base::FilePath& path, | 65 const base::FilePath& path, |
74 base::TimeTicks start_time, | 66 base::TimeTicks start_time, |
75 const SupervisedUserSiteList::LoadedCallback& callback, | 67 const SupervisedUserSiteList::LoadedCallback& callback, |
76 scoped_ptr<base::Value> value); | 68 scoped_ptr<base::Value> value); |
77 | 69 |
78 std::vector<Site> sites_; | 70 base::string16 title_; |
71 GURL entry_point_; | |
72 | |
73 // A list of URL patterns that should be whitelisted. | |
74 std::vector<std::string> patterns_; | |
75 | |
76 // A list of hex-encoded SHA1 hashes of hostnames that should be whitelisted. | |
77 std::vector<std::string> hostname_hashes_; | |
79 | 78 |
80 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); | 79 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); |
81 }; | 80 }; |
82 | 81 |
83 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ | 82 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ |
OLD | NEW |