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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_
11 #include "base/callback_forward.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/time/time.h"
21 class DictionaryValue
;
26 // This class represents a "site list" that is part of a content pack. It is
27 // loaded from a JSON file inside the extension bundle, which defines the sites
29 // Every site has -- among other attributes -- a whitelist of URLs that are
30 // required to use it. All sites from all installed content packs together with
31 // their respective whitelists are combined in the SupervisedUserURLFilter,
32 // which can tell for a given URL if it is part of the whitelist for any site.
33 // Effectively, SupervisedUserURLFilter then acts as a big whitelist which is
34 // the union of the whitelists in all sites in all content packs. See
35 // http://goo.gl/cBCB8 for a diagram.
36 class SupervisedUserSiteList
37 : public base::RefCountedThreadSafe
<SupervisedUserSiteList
> {
39 typedef base::Callback
<void(const scoped_refptr
<SupervisedUserSiteList
>&)>
43 explicit Site(const base::string16
& name
);
46 // The human-readable name for the site.
49 // A list of URL patterns that should be whitelisted for the site.
50 std::vector
<std::string
> patterns
;
52 // A list of hex-encoded SHA1 hashes of hostnames that should be whitelisted
54 std::vector
<std::string
> hostname_hashes
;
56 // Copying and assignment is allowed.
59 // Asynchronously loads the site list from |file| and calls |callback| with
60 // the newly created object.
61 static void Load(const base::FilePath
& file
, const LoadedCallback
& callback
);
63 // Returns a list of all sites in this site list.
64 const std::vector
<Site
>& sites() const { return sites_
; }
67 friend class base::RefCountedThreadSafe
<SupervisedUserSiteList
>;
69 explicit SupervisedUserSiteList(const base::ListValue
& sites
);
70 ~SupervisedUserSiteList();
72 // Static private so they can access the private constructor.
73 static void ParseJson(const base::FilePath
& path
,
74 const SupervisedUserSiteList::LoadedCallback
& callback
,
75 const std::string
& json
);
76 static void OnJsonParseSucceeded(
77 const base::FilePath
& path
,
78 base::TimeTicks start_time
,
79 const SupervisedUserSiteList::LoadedCallback
& callback
,
80 scoped_ptr
<base::Value
> value
);
82 std::vector
<Site
> sites_
;
84 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList
);
87 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_