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

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
19 typedef std::map<std::string, std::string> SysLogsResponse;
20 typedef base::Callback<void(SysLogsResponse*)> SysLogsFetcherCallback;
21
22 class SysLogsInterface {
23 public:
24 virtual void Fetch(SysLogsFetcherCallback) = 0;
25 virtual ~SysLogsInterface() {}
26 };
27
28 typedef std::vector<SysLogsInterface*> SysLogsDataSources;
29
30 // The SysLogsFetcher receives a list of data sources which must be classes that
31 // implement the SysLogsInterface. It's Fetch function receives as a parameter
32 // a callback that takes only one parameter SysLogsResponse that is a map of
33 // keys and values.
34 // Each data source also returns a SysLogsResponse. If two data sources return
35 // the same key, the last one will replace the previous one.
36 // Each data source gets deleted after all of them are called, the
37 // SysLogsFetcher deletes itself after calling the callback it received.
38 //
39 // EXAMPLE:
40 // class Example {
41 // public:
42 // ProcessLogs(chrome::SysLogsResponse) {
43 // //do something with the logs
44 // }
45 // GetLogs() {
46 // chrome::SysLogsFetcher* fetcher =
47 // chrome::SysLogsFetcherFactory::GetInstance()->CreateFetcher();
48 // fetcher->Fetch(base::Bind(&Example::ProcessLogs,this));
49 // }
50
51 class SysLogsFetcher {
52 public:
53 explicit SysLogsFetcher(SysLogsDataSources);
54 ~SysLogsFetcher() {}
55 void Fetch(SysLogsFetcherCallback);
56
57 private:
58 void AddData(SysLogsResponse*);
59
60 SysLogsDataSources data_sources_;
61 SysLogsFetcherCallback request_;
62
63 SysLogsResponse* response_; // The actual response data.
64 base::Lock response_lock_; // The lock for it.
65 size_t responses_; // The number of callbacks it should get.
66
67 base::WeakPtrFactory<SysLogsFetcher> weak_ptr_factory_;
68
69 DISALLOW_COPY_AND_ASSIGN(SysLogsFetcher);
70 };
71
72
73 } // namespace chromeos
74
75 #endif // CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_
76
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698