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

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

Issue 1140053003: Refactoring: Moving the SafeJsonParser to its own component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Catching up with WebstoreInstallHelper changes Created 5 years, 6 months 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
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 #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 "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "base/task_runner_util.h" 11 #include "base/task_runner_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/safe_json_parser.h" 13 #include "components/safe_json_parser/safe_json_parser.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 const int kSitelistFormatVersion = 1; 17 const int kSitelistFormatVersion = 1;
18 18
19 const char kHostnameHashesKey[] = "hostname_hashes"; 19 const char kHostnameHashesKey[] = "hostname_hashes";
20 const char kNameKey[] = "name"; 20 const char kNameKey[] = "name";
21 const char kSitesKey[] = "sites"; 21 const char kSitesKey[] = "sites";
22 const char kSitelistFormatVersionKey[] = "version"; 22 const char kSitelistFormatVersionKey[] = "version";
23 const char kUrlKey[] = "url"; 23 const char kUrlKey[] = "url";
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (!value) { 149 if (!value) {
150 HandleError(path, error); 150 HandleError(path, error);
151 return; 151 return;
152 } 152 }
153 153
154 OnJsonParseSucceeded(path, base::TimeTicks(), callback, value.Pass()); 154 OnJsonParseSucceeded(path, base::TimeTicks(), callback, value.Pass());
155 return; 155 return;
156 } 156 }
157 157
158 // TODO(bauerb): Use batch mode to load multiple whitelists? 158 // TODO(bauerb): Use batch mode to load multiple whitelists?
159 scoped_refptr<SafeJsonParser> parser(new SafeJsonParser( 159 scoped_refptr<safe_json_parser::SafeJsonParser> parser(
160 json, 160 new safe_json_parser::SafeJsonParser(
161 base::Bind(&SupervisedUserSiteList::OnJsonParseSucceeded, path, 161 json, base::Bind(&SupervisedUserSiteList::OnJsonParseSucceeded, path,
162 base::TimeTicks::Now(), callback), 162 base::TimeTicks::Now(), callback),
163 base::Bind(&HandleError, path))); 163 base::Bind(&HandleError, path)));
164 parser->Start(); 164 parser->Start();
165 } 165 }
166 166
167 // static 167 // static
168 void SupervisedUserSiteList::OnJsonParseSucceeded( 168 void SupervisedUserSiteList::OnJsonParseSucceeded(
169 const base::FilePath& path, 169 const base::FilePath& path,
170 base::TimeTicks start_time, 170 base::TimeTicks start_time,
171 const SupervisedUserSiteList::LoadedCallback& callback, 171 const SupervisedUserSiteList::LoadedCallback& callback,
172 scoped_ptr<base::Value> value) { 172 scoped_ptr<base::Value> value) {
173 if (!start_time.is_null()) { 173 if (!start_time.is_null()) {
(...skipping 19 matching lines...) Expand all
193 } 193 }
194 194
195 base::ListValue* sites = nullptr; 195 base::ListValue* sites = nullptr;
196 if (!dict->GetList(kSitesKey, &sites)) { 196 if (!dict->GetList(kSitesKey, &sites)) {
197 LOG(ERROR) << "Site list " << path.value() << " does not contain any sites"; 197 LOG(ERROR) << "Site list " << path.value() << " does not contain any sites";
198 return; 198 return;
199 } 199 }
200 200
201 callback.Run(make_scoped_refptr(new SupervisedUserSiteList(*sites))); 201 callback.Run(make_scoped_refptr(new SupervisedUserSiteList(*sites)));
202 } 202 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_json_parser_browsertest.cc ('k') | chrome/browser/ui/app_list/search/common/json_response_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698