OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef MOJO_SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_ | |
6 #define MOJO_SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_ | |
7 | |
8 #include "base/memory/weak_ptr.h" | |
9 #include "mojo/public/cpp/system/macros.h" | |
10 #include "mojo/services/test_service/test_request_tracker.mojom.h" | |
11 | |
12 namespace mojo { | |
13 class ApplicationConnection; | |
14 namespace test { | |
15 | |
16 typedef std::map<uint64_t, std::vector<ServiceStats> > AllRecordsMap; | |
17 | |
18 // Shared state between all instances of TestRequestTrackerImpl | |
19 // and the master TrackedRequestService. | |
20 struct TrackingContext { | |
21 TrackingContext(); | |
22 ~TrackingContext(); | |
23 AllRecordsMap records; | |
24 std::map<uint64_t, std::string> ids_to_names; | |
25 uint64_t next_id; | |
26 }; | |
27 | |
28 class TestRequestTrackerImpl : public InterfaceImpl<TestRequestTracker> { | |
29 public: | |
30 explicit TestRequestTrackerImpl(TrackingContext* context); | |
31 ~TestRequestTrackerImpl() override; | |
32 | |
33 // TestRequestTracker. | |
34 void RecordStats(uint64_t client_id, ServiceStatsPtr stats) override; | |
35 | |
36 // InterfaceImpl override. | |
37 void OnConnectionEstablished() override; | |
38 | |
39 private: | |
40 void UploaderNameCallback(uint64_t id, const mojo::String& name); | |
41 TrackingContext* context_; | |
42 base::WeakPtrFactory<TestRequestTrackerImpl> weak_factory_; | |
43 MOJO_DISALLOW_COPY_AND_ASSIGN(TestRequestTrackerImpl); | |
44 }; | |
45 | |
46 class TestTrackedRequestServiceImpl | |
47 : public InterfaceImpl<TestTrackedRequestService> { | |
48 public: | |
49 explicit TestTrackedRequestServiceImpl(TrackingContext* context); | |
50 ~TestTrackedRequestServiceImpl() override; | |
51 | |
52 // |TestTrackedRequestService| implementation. | |
53 void GetReport(const mojo::Callback<void(mojo::Array<ServiceReportPtr>)>& | |
54 callback) override; | |
55 | |
56 private: | |
57 TrackingContext* context_; | |
58 MOJO_DISALLOW_COPY_AND_ASSIGN(TestTrackedRequestServiceImpl); | |
59 }; | |
60 | |
61 } // namespace test | |
62 } // namespace mojo | |
63 | |
64 #endif // MOJO_SERVICES_TEST_SERVICE_TEST_REQUEST_TRACKER_IMPL_H_ | |
OLD | NEW |