Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / supervised_user / supervised_user_site_list.h
blobd98dda61445f66929138312d737e67b72f145f57
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_
8 #include <string>
9 #include <vector>
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"
18 class Profile;
20 namespace base {
21 class DictionaryValue;
22 class ListValue;
23 class Value;
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
28 // on the list.
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> {
38 public:
39 typedef base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>
40 LoadedCallback;
42 struct Site {
43 explicit Site(const base::string16& name);
44 ~Site();
46 // The human-readable name for the site.
47 base::string16 name;
49 // A list of URL patterns that should be whitelisted for the site.
50 std::vector<std::string> patterns;
52 // A list of SHA1 hashes of hostnames that should be whitelisted
53 // for the site.
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_; }
71 private:
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_