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