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
3 // found in the LICENSE file.
5 #ifndef SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_
6 #define SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_
8 #include "base/memory/weak_ptr.h"
9 #include "mojo/public/cpp/bindings/strong_binding.h"
10 #include "mojo/public/cpp/system/macros.h"
11 #include "mojo/services/test_service/test_request_tracker.mojom.h"
14 class ApplicationConnection
;
17 typedef std::map
<uint64_t, std::vector
<ServiceStats
> > AllRecordsMap
;
19 // Shared state between all instances of TestRequestTrackerImpl
20 // and the master TrackedRequestService.
21 struct TrackingContext
{
24 AllRecordsMap records
;
25 std::map
<uint64_t, std::string
> ids_to_names
;
29 class TestRequestTrackerImpl
: public TestRequestTracker
{
31 TestRequestTrackerImpl(InterfaceRequest
<TestRequestTracker
> request
,
32 TrackingContext
* context
);
33 ~TestRequestTrackerImpl() override
;
35 // TestRequestTracker.
36 void SetNameAndReturnId(const String
& service_name
,
37 const Callback
<void(uint64_t id
)>& callback
) override
;
38 void RecordStats(uint64_t client_id
, ServiceStatsPtr stats
) override
;
41 void UploaderNameCallback(uint64_t id
, const mojo::String
& name
);
42 TrackingContext
* context_
;
43 StrongBinding
<TestRequestTracker
> binding_
;
44 base::WeakPtrFactory
<TestRequestTrackerImpl
> weak_factory_
;
45 MOJO_DISALLOW_COPY_AND_ASSIGN(TestRequestTrackerImpl
);
48 class TestTrackedRequestServiceImpl
: public TestTrackedRequestService
{
50 TestTrackedRequestServiceImpl(
51 InterfaceRequest
<TestTrackedRequestService
> request
,
52 TrackingContext
* context
);
53 ~TestTrackedRequestServiceImpl() override
;
55 // |TestTrackedRequestService| implementation.
56 void GetReport(const mojo::Callback
<void(mojo::Array
<ServiceReportPtr
>)>&
60 TrackingContext
* context_
;
61 StrongBinding
<TestTrackedRequestService
> binding_
;
63 MOJO_DISALLOW_COPY_AND_ASSIGN(TestTrackedRequestServiceImpl
);
69 #endif // SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_