Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / feedback / system_logs / system_logs_fetcher_base.h
blob92e98acfb182badb7729dcd216fd2230c42dcc73
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_
8 #include <map>
9 #include <string>
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
29 // information.
30 class SystemLogsSource {
31 public:
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
39 // classes.
41 // EXAMPLE:
42 // class Example {
43 // public:
44 // void ProcessLogs(SystemLogsResponse* response) {
45 // //do something with the logs
46 // }
47 // void GetLogs() {
48 // SystemLogsFetcherBase* fetcher = new SystemLogsFetcherBase();
49 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this));
50 // }
51 class SystemLogsFetcherBase
52 : public base::SupportsWeakPtr<SystemLogsFetcherBase> {
53 public:
54 SystemLogsFetcherBase();
55 ~SystemLogsFetcherBase();
57 void Fetch(const SysLogsFetcherCallback& callback);
59 protected:
60 // Callback passed to all the data sources. It merges the |data| it recieves
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.
72 private:
74 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcherBase);
77 } // namespace system_logs
79 #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_