| 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 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 5 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 const int kLegacyWhitelistFormatVersion = 2; | 19 const int kLegacyWhitelistFormatVersion = 2; |
| 20 const int kWhitelistFormatVersion = 1; | 20 const int kWhitelistFormatVersion = 1; |
| 21 | 21 |
| 22 const char kEntryPointUrlKey[] = "entry_point_url"; | 22 const char kEntryPointUrlKey[] = "entry_point_url"; |
| 23 const char kHostnameHashesKey[] = "hostname_hashes"; | 23 const char kHostnameHashesKey[] = "hostname_hashes"; |
| 24 const char kLegacyWhitelistFormatVersionKey[] = "version"; | 24 const char kLegacyWhitelistFormatVersionKey[] = "version"; |
| 25 const char kSitelistFormatVersionKey[] = "sitelist_version"; | 25 const char kSitelistFormatVersionKey[] = "sitelist_version"; |
| 26 const char kWhitelistKey[] = "whitelist"; | 26 const char kWhitelistKey[] = "whitelist"; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 scoped_ptr<base::Value> ReadFileOnBlockingThread(const base::FilePath& path) { | 30 std::unique_ptr<base::Value> ReadFileOnBlockingThread( |
| 31 const base::FilePath& path) { |
| 31 SCOPED_UMA_HISTOGRAM_TIMER("ManagedUsers.Whitelist.ReadDuration"); | 32 SCOPED_UMA_HISTOGRAM_TIMER("ManagedUsers.Whitelist.ReadDuration"); |
| 32 JSONFileValueDeserializer deserializer(path); | 33 JSONFileValueDeserializer deserializer(path); |
| 33 int error_code; | 34 int error_code; |
| 34 std::string error_msg; | 35 std::string error_msg; |
| 35 scoped_ptr<base::Value> value = | 36 std::unique_ptr<base::Value> value = |
| 36 deserializer.Deserialize(&error_code, &error_msg); | 37 deserializer.Deserialize(&error_code, &error_msg); |
| 37 if (!value) { | 38 if (!value) { |
| 38 LOG(ERROR) << "Couldn't load site list " << path.value() << ": " | 39 LOG(ERROR) << "Couldn't load site list " << path.value() << ": " |
| 39 << error_msg; | 40 << error_msg; |
| 40 } | 41 } |
| 41 return value; | 42 return value; |
| 42 } | 43 } |
| 43 | 44 |
| 44 std::vector<std::string> ConvertListValues(const base::ListValue* list_values) { | 45 std::vector<std::string> ConvertListValues(const base::ListValue* list_values) { |
| 45 std::vector<std::string> converted; | 46 std::vector<std::string> converted; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 142 } |
| 142 | 143 |
| 143 // static | 144 // static |
| 144 void SupervisedUserSiteList::OnJsonLoaded( | 145 void SupervisedUserSiteList::OnJsonLoaded( |
| 145 const std::string& id, | 146 const std::string& id, |
| 146 const base::string16& title, | 147 const base::string16& title, |
| 147 const base::FilePath& large_icon_path, | 148 const base::FilePath& large_icon_path, |
| 148 const base::FilePath& path, | 149 const base::FilePath& path, |
| 149 base::TimeTicks start_time, | 150 base::TimeTicks start_time, |
| 150 const SupervisedUserSiteList::LoadedCallback& callback, | 151 const SupervisedUserSiteList::LoadedCallback& callback, |
| 151 scoped_ptr<base::Value> value) { | 152 std::unique_ptr<base::Value> value) { |
| 152 if (!value) | 153 if (!value) |
| 153 return; | 154 return; |
| 154 | 155 |
| 155 if (!start_time.is_null()) { | 156 if (!start_time.is_null()) { |
| 156 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.JsonParseDuration", | 157 UMA_HISTOGRAM_TIMES("ManagedUsers.Whitelist.JsonParseDuration", |
| 157 base::TimeTicks::Now() - start_time); | 158 base::TimeTicks::Now() - start_time); |
| 158 } | 159 } |
| 159 | 160 |
| 160 base::DictionaryValue* dict = nullptr; | 161 base::DictionaryValue* dict = nullptr; |
| 161 if (!value->GetAsDictionary(&dict)) { | 162 if (!value->GetAsDictionary(&dict)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 189 base::ListValue* patterns = nullptr; | 190 base::ListValue* patterns = nullptr; |
| 190 dict->GetList(kWhitelistKey, &patterns); | 191 dict->GetList(kWhitelistKey, &patterns); |
| 191 | 192 |
| 192 base::ListValue* hostname_hashes = nullptr; | 193 base::ListValue* hostname_hashes = nullptr; |
| 193 dict->GetList(kHostnameHashesKey, &hostname_hashes); | 194 dict->GetList(kHostnameHashesKey, &hostname_hashes); |
| 194 | 195 |
| 195 callback.Run(make_scoped_refptr( | 196 callback.Run(make_scoped_refptr( |
| 196 new SupervisedUserSiteList(id, title, GURL(entry_point_url), | 197 new SupervisedUserSiteList(id, title, GURL(entry_point_url), |
| 197 large_icon_path, patterns, hostname_hashes))); | 198 large_icon_path, patterns, hostname_hashes))); |
| 198 } | 199 } |
| OLD | NEW |