BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / feedback / system_logs / system_logs_fetcher_base.h
blob521e15dd5ca4f12990a88bcc9fb37a8b467db0f7
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 // |source_name| provides a descriptive identifier for debugging.
33 explicit SystemLogsSource(const std::string& source_name);
34 virtual ~SystemLogsSource();
36 // Fetches data and passes it by to the callback
37 virtual void Fetch(const SysLogsSourceCallback& callback) = 0;
39 const std::string& source_name() const { return source_name_; }
41 private:
42 std::string source_name_;
45 // The SystemLogsFetcherBaseBase specifies an interface for LogFetcher classes.
46 // Derived LogFetcher classes aggregate the logs from a list of SystemLogSource
47 // classes.
49 // EXAMPLE:
50 // class Example {
51 // public:
52 // void ProcessLogs(SystemLogsResponse* response) {
53 // //do something with the logs
54 // }
55 // void GetLogs() {
56 // SystemLogsFetcherBase* fetcher = new SystemLogsFetcherBase();
57 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this));
58 // }
59 class SystemLogsFetcherBase
60 : public base::SupportsWeakPtr<SystemLogsFetcherBase> {
61 public:
62 SystemLogsFetcherBase();
63 ~SystemLogsFetcherBase();
65 void Fetch(const SysLogsFetcherCallback& callback);
67 protected:
68 // Callback passed to all the data sources. It merges the |data| it receives
69 // into response_. When all the data sources have responded, it deletes their
70 // objects and returns the response to the callback_. After this it
71 // deletes this instance of the object.
72 void AddResponse(const std::string& source_name,
73 SystemLogsResponse* response);
75 ScopedVector<SystemLogsSource> data_sources_;
76 SysLogsFetcherCallback callback_;
78 scoped_ptr<SystemLogsResponse> response_; // The actual response data.
79 size_t num_pending_requests_; // The number of callbacks it should get.
81 private:
83 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcherBase);
86 } // namespace system_logs
88 #endif // CHROME_BROWSER_FEEDBACK_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_BASE_H_