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

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
11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 namespace chromeos {
15
16 typedef std::map<std::string, std::string> SystemLogsResponse;
17 // Callback that the data sources use to return data.
18 typedef base::Callback<void(SystemLogsResponse* response)>
19 SysLogsSourceCallback;
satorux1 2012/08/17 17:46:29 blank line.
tudalex(Chromium) 2012/08/17 19:43:22 Done.
20 // Callback that the SystemLogsFetcher uses to return data.
21 typedef base::Callback<void(scoped_ptr<SystemLogsResponse> response)>
22 SysLogsFetcherCallback;
23
24 // The SystemLogsSource provides a interface for the data sources that
25 // the SystemLogsFetcher class uses to fetch logs and other
26 // information.
27 class SystemLogsSource {
28 public:
29 // Fetches data and passes it by to the callback
30 virtual void Fetch(const SysLogsSourceCallback& callback) = 0;
31 virtual ~SystemLogsSource() {}
32 };
33
34 // The SystemLogsFetcher creates a list of data sources which must be
35 // classes that implement the SystemLogsSource. It's Fetch function
36 // receives as a parameter a callback that takes only one parameter
37 // SystemLogsResponse that is a map of keys and values.
38 // Each data source also returns a SystemLogsResponse. If two data sources
39 // return the same key, only the first one will be stored.
40 // The class runs on the UI thread.
41 //
42 // EXAMPLE:
43 // class Example {
44 // public:
45 // void ProcessLogs(SystemLogsResponse* response) {
46 // //do something with the logs
47 // }
48 // void GetLogs() {
49 // SystemLogsFetcher* fetcher = new SystemLogsFetcher();
50 // fetcher->Fetch(base::Bind(&Example::ProcessLogs, this));
51 // }
52 class SystemLogsFetcher {
53 public:
54 explicit SystemLogsFetcher();
55 ~SystemLogsFetcher() {}
56
57 void Fetch(const SysLogsFetcherCallback& callback);
58
59 private:
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);
65
66 ScopedVector<SystemLogsSource> data_sources_;
67 SysLogsFetcherCallback callback_;
68
69 scoped_ptr<SystemLogsResponse> response_; // The actual response data.
70 size_t num_pending_requests_; // The number of callbacks it should get.
71
72 base::WeakPtrFactory<SystemLogsFetcher> weak_ptr_factory_;
73
74 DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcher);
75 };
76
77 } // namespace chromeos
78
79 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_
80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698