Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: chrome/browser/chromeos/system_logs/system_logs_fetcher.h

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14
15 namespace chromeos {
16
17 typedef std::map<std::string, std::string> SystemLogsResponse;
18 typedef base::Callback<void(SystemLogsResponse*)> SysLogsFetcherCallback;
19
20 // The SystemLogsSource provides a interface for the data sources that
21 // the SystemLogsFetcher class uses to fetch logs and other
22 // information.
23 class SystemLogsSource {
24 public:
25 // Fetches data and passes it by to the callback
26 virtual void Fetch(const SysLogsFetcherCallback& request) = 0;
27 virtual ~SystemLogsSource() {}
28 };
29
30 typedef std::vector<SystemLogsSource*> SysLogsDataSources;
31
32 // The SystemLogsFetcher creates a list of data sources which must be
33 // classes that implement the SystemLogsSource. It's Fetch function
34 // receives as a parameter a callback that takes only one parameter
35 // SystemLogsResponse that is a map of keys and values.
36 // Each data source also returns a SystemLogsResponse. If two data sources
37 // return the same key, the last one will replace the previous one.
38 // Each data source gets deleted after all of them are called, the
39 // SystemLogsFetcher deletes itself after calling the callback it
40 // received. The class runs on the UI thread.
41 //
42 // EXAMPLE:
43 // class Example {
44 // public:
45 // ProcessLogs(chrome::SystemLogsResponse) {
46 // //do something with the logs
47 // }
48 // GetLogs() {
49 // chrome::SystemLogsFetcher* fetcher =
50 // chrome::SystemLogsFetcher::GetInstance()->CreateFetcher();
51 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this));
52 // }
53 class SystemLogsFetcher {
54 public:
55 explicit SystemLogsFetcher();
56 ~SystemLogsFetcher() {}
57
58 void Fetch(const SysLogsFetcherCallback& request);
59
60 private:
61 // Callback passed to all the data sources. It merges the |data| it recieves
62 // into response_. When all the data sources have responded, it deletes their
63 // objects and returns the response to the request_ callback. After this it
64 // deletes itself.
65 void AddData(SystemLogsResponse* response);
satorux1 2012/08/13 19:33:36 AddResponse?
tudalex(Chromium) 2012/08/14 03:24:00 Done.
66
67 SysLogsDataSources data_sources_;
68 SysLogsFetcherCallback request_;
69
70 SystemLogsResponse* response_; // The actual response data.
71 size_t num_pending_requests_; // The number of callbacks it should get.
72
73 base::WeakPtrFactory<SystemLogsFetcher> weak_ptr_factory_;
74
75 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcher);
76 };
77
78 } // namespace chromeos
79
80 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_
81
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698