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

Side by Side Diff: net/reporting/reporting_header_parser.cc

Issue 2751103002: Reporting: Wrap existing classes in context. (Closed)
Patch Set: rebase Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "net/reporting/reporting_header_parser.h" 5 #include "net/reporting/reporting_header_parser.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/time/tick_clock.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "net/reporting/reporting_cache.h" 14 #include "net/reporting/reporting_cache.h"
14 #include "url/gurl.h" 15 #include "net/reporting/reporting_context.h"
15 #include "url/origin.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace { 19 namespace {
20 20
21 const char kUrlKey[] = "url"; 21 const char kUrlKey[] = "url";
22 const char kIncludeSubdomainsKey[] = "includeSubdomains"; 22 const char kIncludeSubdomainsKey[] = "includeSubdomains";
23 const char kGroupKey[] = "group"; 23 const char kGroupKey[] = "group";
24 const char kGroupDefaultValue[] = "default"; 24 const char kGroupDefaultValue[] = "default";
25 const char kMaxAgeKey[] = "max-age"; 25 const char kMaxAgeKey[] = "max-age";
26 26
27 } // namespace 27 } // namespace
28 28
29 // static 29 // static
30 void ReportingHeaderParser::ParseHeader(ReportingCache* cache, 30 void ReportingHeaderParser::ParseHeader(ReportingContext* context,
31 base::TimeTicks now,
32 const GURL& url, 31 const GURL& url,
33 const std::string& json_value) { 32 const std::string& json_value) {
34 DCHECK(url.SchemeIsCryptographic()); 33 DCHECK(url.SchemeIsCryptographic());
35 34
36 std::unique_ptr<base::Value> value = 35 std::unique_ptr<base::Value> value =
37 base::JSONReader::Read("[" + json_value + "]"); 36 base::JSONReader::Read("[" + json_value + "]");
38 if (!value) 37 if (!value)
39 return; 38 return;
40 39
41 const base::ListValue* list = nullptr; 40 const base::ListValue* list = nullptr;
42 bool is_list = value->GetAsList(&list); 41 bool is_list = value->GetAsList(&list);
43 DCHECK(is_list); 42 DCHECK(is_list);
44 43
44 ReportingCache* cache = context->cache();
45 base::TimeTicks now = context->tick_clock()->NowTicks();
45 for (size_t i = 0; i < list->GetSize(); i++) { 46 for (size_t i = 0; i < list->GetSize(); i++) {
46 const base::Value* endpoint = nullptr; 47 const base::Value* endpoint = nullptr;
47 bool got_endpoint = list->Get(i, &endpoint); 48 bool got_endpoint = list->Get(i, &endpoint);
48 DCHECK(got_endpoint); 49 DCHECK(got_endpoint);
49 ProcessEndpoint(cache, now, url, *endpoint); 50 ProcessEndpoint(cache, now, url, *endpoint);
50 } 51 }
51 } 52 }
52 53
53 // static 54 // static
54 void ReportingHeaderParser::ProcessEndpoint(ReportingCache* cache, 55 void ReportingHeaderParser::ProcessEndpoint(ReportingCache* cache,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 if (ttl_sec > 0) { 90 if (ttl_sec > 0) {
90 cache->SetClient(url::Origin(url), endpoint_url, subdomains, group, 91 cache->SetClient(url::Origin(url), endpoint_url, subdomains, group,
91 now + base::TimeDelta::FromSeconds(ttl_sec)); 92 now + base::TimeDelta::FromSeconds(ttl_sec));
92 } else { 93 } else {
93 cache->RemoveClientForOriginAndEndpoint(url::Origin(url), endpoint_url); 94 cache->RemoveClientForOriginAndEndpoint(url::Origin(url), endpoint_url);
94 } 95 }
95 } 96 }
96 97
97 } // namespace net 98 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_header_parser.h ('k') | net/reporting/reporting_header_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698