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