Chromium Code Reviews| Index: chrome/browser/chromeos/system_logs/system_logs_fetcher.h |
| diff --git a/chrome/browser/chromeos/system_logs/system_logs_fetcher.h b/chrome/browser/chromeos/system_logs/system_logs_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e97535a50ed82b187d68c9c930699c8eacb48d44 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/system_logs/system_logs_fetcher.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/weak_ptr.h" |
| + |
| +namespace chromeos { |
| + |
| +typedef std::map<std::string, std::string> SystemLogsResponse; |
| +typedef base::Callback<void(SystemLogsResponse*)> SysLogsFetcherCallback; |
| + |
| +// The SystemLogsSource provides a interface for the data sources that |
| +// the SystemLogsFetcher class uses to fetch logs and other |
| +// information. |
| +class SystemLogsSource { |
| + public: |
| + // Fetches data and passes it by to the callback |
| + virtual void Fetch(const SysLogsFetcherCallback& request) = 0; |
| + virtual ~SystemLogsSource() {} |
| +}; |
| + |
| +typedef std::vector<SystemLogsSource*> SysLogsDataSources; |
| + |
| +// The SystemLogsFetcher creates a list of data sources which must be |
| +// classes that implement the SystemLogsSource. It's Fetch function |
| +// receives as a parameter a callback that takes only one parameter |
| +// SystemLogsResponse that is a map of keys and values. |
| +// Each data source also returns a SystemLogsResponse. If two data sources |
| +// return the same key, the last one will replace the previous one. |
| +// Each data source gets deleted after all of them are called, the |
| +// SystemLogsFetcher deletes itself after calling the callback it |
| +// received. The class runs on the UI thread. |
| +// |
| +// EXAMPLE: |
| +// class Example { |
| +// public: |
| +// ProcessLogs(chrome::SystemLogsResponse) { |
| +// //do something with the logs |
| +// } |
| +// GetLogs() { |
| +// chrome::SystemLogsFetcher* fetcher = |
| +// chrome::SystemLogsFetcher::GetInstance()->CreateFetcher(); |
| +// fetcher->Fetch(base::Bind(&Example::ProcessLogs, this)); |
| +// } |
| +class SystemLogsFetcher { |
| + public: |
| + explicit SystemLogsFetcher(); |
| + ~SystemLogsFetcher() {} |
| + |
| + void Fetch(const SysLogsFetcherCallback& request); |
| + |
| + private: |
| + // Callback passed to all the data sources. It merges the |data| it recieves |
| + // into response_. When all the data sources have responded, it deletes their |
| + // objects and returns the response to the request_ callback. After this it |
| + // deletes itself. |
| + void AddData(SystemLogsResponse* response); |
|
satorux1
2012/08/13 19:33:36
AddResponse?
tudalex(Chromium)
2012/08/14 03:24:00
Done.
|
| + |
| + SysLogsDataSources data_sources_; |
| + SysLogsFetcherCallback request_; |
| + |
| + SystemLogsResponse* response_; // The actual response data. |
| + size_t num_pending_requests_; // The number of callbacks it should get. |
| + |
| + base::WeakPtrFactory<SystemLogsFetcher> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemLogsFetcher); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_SYSTEM_LOGS_FETCHER_H_ |
| + |