Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/browser/supervised_user/supervised_user_site_list.h

Issue 1469813002: Supervised user whitelists optimization: Store raw sha1 hashes rather than strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/supervised_user/supervised_user_site_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <array>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/sha1.h"
15 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 class Profile; 21 class Profile;
20 22
21 namespace base { 23 namespace base {
22 class DictionaryValue; 24 class DictionaryValue;
23 class ListValue; 25 class ListValue;
24 class Value; 26 class Value;
25 } 27 }
26 28
27 // This class represents the content of a supervised user whitelist. It is 29 // 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 30 // loaded from a JSON file inside the extension bundle, which defines the sites
29 // on the list. 31 // on the list.
30 // All whitelists are combined in the SupervisedUserURLFilter, which can tell 32 // All whitelists are combined in the SupervisedUserURLFilter, which can tell
31 // for a given URL if it is part of any whitelist. Effectively, 33 // 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 34 // SupervisedUserURLFilter then acts as a big whitelist which is the union of
33 // all the whitelists. 35 // all the whitelists.
34 class SupervisedUserSiteList 36 class SupervisedUserSiteList
35 : public base::RefCountedThreadSafe<SupervisedUserSiteList> { 37 : public base::RefCountedThreadSafe<SupervisedUserSiteList> {
36 public: 38 public:
39 class HostnameHash {
40 public:
41 explicit HostnameHash(const std::string& hostname);
42 // |bytes| must have a size of at least |base::kSHA1Length|.
43 explicit HostnameHash(const std::vector<uint8>& bytes);
44
45 bool operator==(const HostnameHash& rhs) const;
46
47 // Returns a hash code suitable for putting this into hash maps.
48 size_t hash() const;
49
50 private:
51 std::array<uint8, base::kSHA1Length> bytes_;
52 // Copy and assign are allowed.
53 };
54
37 using LoadedCallback = 55 using LoadedCallback =
38 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>; 56 base::Callback<void(const scoped_refptr<SupervisedUserSiteList>&)>;
39 57
40 // Asynchronously loads the site list from |file| and calls |callback| with 58 // Asynchronously loads the site list from |file| and calls |callback| with
41 // the newly created object. 59 // the newly created object.
42 static void Load(const base::string16& title, 60 static void Load(const base::string16& title,
43 const base::FilePath& file, 61 const base::FilePath& file,
44 const LoadedCallback& callback); 62 const LoadedCallback& callback);
45 63
46 const base::string16& title() const { return title_; } 64 const base::string16& title() const { return title_; }
47 const GURL& entry_point() const { return entry_point_; } 65 const GURL& entry_point() const { return entry_point_; }
48 const std::vector<std::string>& patterns() const { return patterns_; } 66 const std::vector<std::string>& patterns() const { return patterns_; }
49 const std::vector<std::string>& hostname_hashes() const { 67 const std::vector<HostnameHash>& hostname_hashes() const {
50 return hostname_hashes_; 68 return hostname_hashes_;
51 } 69 }
52 70
53 private: 71 private:
54 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>; 72 friend class base::RefCountedThreadSafe<SupervisedUserSiteList>;
55 73
56 SupervisedUserSiteList(const base::string16& title, 74 SupervisedUserSiteList(const base::string16& title,
57 const GURL& entry_point, 75 const GURL& entry_point,
58 const base::ListValue* patterns, 76 const base::ListValue* patterns,
59 const base::ListValue* hostname_hashes); 77 const base::ListValue* hostname_hashes);
60 ~SupervisedUserSiteList(); 78 ~SupervisedUserSiteList();
61 79
62 // Static private so it can access the private constructor. 80 // Static private so it can access the private constructor.
63 static void OnJsonLoaded( 81 static void OnJsonLoaded(
64 const base::string16& title, 82 const base::string16& title,
65 const base::FilePath& path, 83 const base::FilePath& path,
66 base::TimeTicks start_time, 84 base::TimeTicks start_time,
67 const SupervisedUserSiteList::LoadedCallback& callback, 85 const SupervisedUserSiteList::LoadedCallback& callback,
68 scoped_ptr<base::Value> value); 86 scoped_ptr<base::Value> value);
69 87
70 base::string16 title_; 88 base::string16 title_;
71 GURL entry_point_; 89 GURL entry_point_;
72 90
73 // A list of URL patterns that should be whitelisted. 91 // A list of URL patterns that should be whitelisted.
74 std::vector<std::string> patterns_; 92 std::vector<std::string> patterns_;
75 93
76 // A list of hex-encoded SHA1 hashes of hostnames that should be whitelisted. 94 // A list of SHA1 hashes of hostnames that should be whitelisted.
77 std::vector<std::string> hostname_hashes_; 95 std::vector<HostnameHash> hostname_hashes_;
78 96
79 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList); 97 DISALLOW_COPY_AND_ASSIGN(SupervisedUserSiteList);
80 }; 98 };
81 99
82 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_ 100 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SITE_LIST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/supervised_user/supervised_user_site_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698