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

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 #include "base/synchronization/lock.h"
15
16 namespace chromeos {
17
18 typedef std::map<std::string, std::string> SysLogsResponse;
19 typedef base::Callback<void(SysLogsResponse*)> SysLogsFetcherCallback;
20
21 // The SysLogsInterface provides a interface for the data sources that the
22 // SysLogsFetcher class uses to fetch logs and other information.
23 class SysLogsInterface {
24 public:
25 // Fetches data and passes it by to the callback
26 virtual void Fetch(const SysLogsFetcherCallback&) = 0;
satorux1 2012/08/07 01:15:07 parameter name is missing. Please fix everywhere.
tudalex(Chromium) 2012/08/07 23:46:54 Done.
27 virtual ~SysLogsInterface() {}
28 };
29
30 typedef std::vector<SysLogsInterface*> SysLogsDataSources;
31
32 // The SysLogsFetcher receives a list of data sources which must be classes that
33 // implement the SysLogsInterface. It's Fetch function receives as a parameter
34 // a callback that takes only one parameter SysLogsResponse that is a map of
35 // keys and values.
36 // Each data source also returns a SysLogsResponse. If two data sources return
37 // 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 // SysLogsFetcher deletes itself after calling the callback it received.
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));
51 // }
52 class SysLogsFetcher {
53 public:
54 explicit SysLogsFetcher(SysLogsDataSources);
55 ~SysLogsFetcher() {}
56
57 void Fetch(SysLogsFetcherCallback);
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*);
65
66 SysLogsDataSources data_sources_;
67 SysLogsFetcherCallback request_;
68
69 SysLogsResponse* response_; // The actual response data.
70 base::Lock response_lock_; // The lock for it.
satorux1 2012/08/07 01:15:07 why is Lock needed? we usually don't need it.
tudalex(Chromium) 2012/08/07 23:46:54 Done.
71 size_t responses_; // The number of callbacks it should get.
72
73 base::WeakPtrFactory<SysLogsFetcher> weak_ptr_factory_;
74
75 DISALLOW_COPY_AND_ASSIGN(SysLogsFetcher);
76 };
77
78
79 } // namespace chromeos
80
81 #endif // CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_
82
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698