1 // Copyright 2013 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 CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_
6 #define CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_
11 #include "base/callback.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
15 namespace system_logs
{
17 typedef std::map
<std::string
, std::string
> SystemLogsResponse
;
19 // Callback that the data sources use to return data.
20 typedef base::Callback
<void(SystemLogsResponse
* response
)>
21 SysLogsSourceCallback
;
23 // Callback that the SystemLogsFetcherBase uses to return data.
24 typedef base::Callback
<void(scoped_ptr
<SystemLogsResponse
> response
)>
25 SysLogsFetcherCallback
;
27 // The SystemLogsSource provides a interface for the data sources that
28 // the SystemLogsFetcherBase class uses to fetch logs and other
30 class SystemLogsSource
{
32 // Fetches data and passes it by to the callback
33 virtual void Fetch(const SysLogsSourceCallback
& callback
) = 0;
34 virtual ~SystemLogsSource() {}
37 // The SystemLogsFetcherBaseBase specifies an interface for LogFetcher classes.
38 // Derived LogFetcher classes aggregate the logs from a list of SystemLogSource
44 // void ProcessLogs(SystemLogsResponse* response) {
45 // //do something with the logs
48 // SystemLogsFetcherBase* fetcher = new SystemLogsFetcherBase();
49 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this));
51 class SystemLogsFetcherBase
52 : public base::SupportsWeakPtr
<SystemLogsFetcherBase
> {
54 SystemLogsFetcherBase();
55 ~SystemLogsFetcherBase();
57 void Fetch(const SysLogsFetcherCallback
& callback
);
60 // Callback passed to all the data sources. It merges the |data| it receives
61 // into response_. When all the data sources have responded, it deletes their
62 // objects and returns the response to the callback_. After this it
63 // deletes this instance of the object.
64 void AddResponse(SystemLogsResponse
* response
);
66 ScopedVector
<SystemLogsSource
> data_sources_
;
67 SysLogsFetcherCallback callback_
;
69 scoped_ptr
<SystemLogsResponse
> response_
; // The actual response data.
70 size_t num_pending_requests_
; // The number of callbacks it should get.
74 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcherBase
);
77 } // namespace system_logs
79 #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_