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