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

Side by Side Diff: chrome/browser/chromeos/syslogs/syslogs_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_SYSLOGS_SYSLOGS_FETCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_
7
8 #include <string>
9 #include <map>
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> SysLogsResponse;
18 typedef base::Callback<void(SysLogsResponse*)> SysLogsFetcherCallback;
19
20 // The SysLogsInterface provides a interface for the data sources that the
21 // SysLogsFetcher class uses to fetch logs and other information.
22 class SysLogsInterface {
satorux1 2012/08/09 21:15:07 I should have noticed earlier but the class name i
tudalex(Chromium) 2012/08/10 00:30:31 It was named after SysInfoProvider which was named
23 public:
24 // Fetches data and passes it by to the callback
25 virtual void Fetch(const SysLogsFetcherCallback& request) = 0;
26 virtual ~SysLogsInterface() {}
27 };
28
29 typedef std::vector<SysLogsInterface*> SysLogsDataSources;
30
31 // The SysLogsFetcher receives a list of data sources which must be classes that
32 // implement the SysLogsInterface. It's Fetch function receives as a parameter
33 // a callback that takes only one parameter SysLogsResponse that is a map of
34 // keys and values.
35 // Each data source also returns a SysLogsResponse. If two data sources return
36 // the same key, the last one will replace the previous one.
37 // Each data source gets deleted after all of them are called, the
38 // SysLogsFetcher deletes itself after calling the callback it received.
39 // The class runs on the UI thread.
40 //
41 // EXAMPLE:
42 // class Example {
43 // public:
44 // ProcessLogs(chrome::SysLogsResponse) {
45 // //do something with the logs
46 // }
47 // GetLogs() {
48 // chrome::SysLogsFetcher* fetcher =
49 // chrome::SysLogsFetcherFactory::GetInstance()->CreateFetcher();
50 // fetcher->Fetch(base::Bind(&Example::ProcessLogs,this));
rkc 2012/08/09 21:31:55 Nit: &Example::ProcessLogs, this
tudalex(Chromium) 2012/08/10 00:30:31 Done.
51 // }
52 class SysLogsFetcher {
satorux1 2012/08/09 21:15:07 This aggregates the data from multiple sources, ri
rkc 2012/08/09 23:50:50 Satoru, AggregatedSystemLogFetcher is not quite an
tudalex(Chromium) 2012/08/10 00:30:31 I wrote it as AggregatedSystemLogFetcher for now.
satorux1 2012/08/10 22:58:34 Source sounds good.
tudalex(Chromium) 2012/08/11 00:27:06 Done. Also renamed the folder from syslogs to syst
53 public:
54 explicit SysLogsFetcher();
55 ~SysLogsFetcher() {}
56
57 void Fetch(const SysLogsFetcherCallback& request);
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 request_ callback. After this it
63 // deletes itself.
64 void AddData(SysLogsResponse* data);
satorux1 2012/08/09 21:15:07 AddResponse((SysLogsResponse* response) ? "data"
tudalex(Chromium) 2012/08/10 00:30:31 Done.
65
66 SysLogsDataSources data_sources_;
67 SysLogsFetcherCallback request_;
68
69 SysLogsResponse* response_; // The actual response data.
70 size_t responses_; // The number of callbacks it should get.
satorux1 2012/08/09 21:15:07 Please add num_ prefix to make it clear it's a num
tudalex(Chromium) 2012/08/10 00:30:31 Done.
71
72 base::WeakPtrFactory<SysLogsFetcher> weak_ptr_factory_;
73
74 DISALLOW_COPY_AND_ASSIGN(SysLogsFetcher);
75 };
76
rkc 2012/08/09 21:31:55 Extra line.
tudalex(Chromium) 2012/08/10 00:30:31 Done.
77
78 } // namespace chromeos
79
80 #endif // CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_
81
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698