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