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

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

Issue 2770443002: Reporting: Wrap context in service. (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
« no previous file with comments | « net/reporting/reporting_service.h ('k') | net/reporting/reporting_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/reporting/reporting_service.h"
6
7 #include <memory>
8
9 #include "base/callback.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/time/tick_clock.h"
13 #include "base/time/time.h"
14 #include "base/values.h"
15 #include "net/reporting/reporting_cache.h"
16 #include "net/reporting/reporting_context.h"
17 #include "net/reporting/reporting_delegate.h"
18 #include "net/reporting/reporting_header_parser.h"
19 #include "url/gurl.h"
20
21 namespace net {
22
23 namespace {
24
25 class ReportingServiceImpl : public ReportingService {
26 public:
27 ReportingServiceImpl(std::unique_ptr<ReportingContext> context)
28 : context_(std::move(context)) {}
29
30 ~ReportingServiceImpl() override {}
31
32 void QueueReport(const GURL& url,
33 const std::string& group,
34 const std::string& type,
35 std::unique_ptr<const base::Value> body) override {
36 context_->cache()->AddReport(url, group, type, std::move(body),
37 context_->tick_clock()->NowTicks(), 0);
38 }
39
40 void ProcessHeader(const GURL& url,
41 const std::string& header_value) override {
42 ReportingHeaderParser::ParseHeader(context_.get(), url, header_value);
43 }
44
45 private:
46 std::unique_ptr<ReportingContext> context_;
47
48 DISALLOW_COPY_AND_ASSIGN(ReportingServiceImpl);
49 };
50
51 } // namespace
52
53 ReportingService::~ReportingService() {}
54
55 // static
56 std::unique_ptr<ReportingService> ReportingService::Create(
57 const ReportingPolicy& policy,
58 URLRequestContext* request_context,
59 std::unique_ptr<ReportingDelegate> delegate) {
60 return base::MakeUnique<ReportingServiceImpl>(
61 ReportingContext::Create(policy, std::move(delegate), request_context));
62 }
63
64 // static
65 std::unique_ptr<ReportingService> ReportingService::CreateForTesting(
66 std::unique_ptr<ReportingContext> reporting_context) {
67 return base::MakeUnique<ReportingServiceImpl>(std::move(reporting_context));
68 }
69
70 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_service.h ('k') | net/reporting/reporting_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698