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 // Sets whether the site list should be loaded in-process or out-of-process.
64 // In-process loading should only be used in tests (to avoid having to set up
65 // child process handling).
66 static void SetLoadInProcessForTesting(bool in_process
);
68 // Returns a list of all sites in this site list.
69 const std::vector
<Site
>& sites() const { return sites_
; }
72 friend class base::RefCountedThreadSafe
<SupervisedUserSiteList
>;
74 explicit SupervisedUserSiteList(const base::ListValue
& sites
);
75 ~SupervisedUserSiteList();
77 // Static private so they can access the private constructor.
78 static void ParseJson(const base::FilePath
& path
,
79 const SupervisedUserSiteList::LoadedCallback
& callback
,
80 const std::string
& json
);
81 static void OnJsonParseSucceeded(
82 const base::FilePath
& path
,
83 base::TimeTicks start_time
,
84 const SupervisedUserSiteList::LoadedCallback
& callback
,
85 scoped_ptr
<base::Value
> value
);
87 std::vector
<Site
> sites_
;
89 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList
);
92 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_