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..ce96ae7cc79ec73a8d2831961687ba76af02930b |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/system_logs/system_logs_fetcher.h |
| @@ -0,0 +1,82 @@ |
| +// 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 "base/callback.h" |
| +#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.
|
| +#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.
|
| +namespace chromeos { |
| + |
| +typedef std::map<std::string, std::string> SystemLogsResponse; |
| + |
| +// Callback that the data sources use to return data. |
| +typedef base::Callback<void(SystemLogsResponse* response)> |
| + SysLogsSourceCallback; |
| + |
| +// Callback that the SystemLogsFetcher uses to return data. |
| +typedef base::Callback<void(scoped_ptr<SystemLogsResponse> response)> |
| + 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 SysLogsSourceCallback& callback) = 0; |
| + virtual ~SystemLogsSource() {} |
| +}; |
| + |
| +// 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, only the first one will be stored. |
| +// The class runs on the UI thread. |
| +// |
| +// EXAMPLE: |
| +// class Example { |
| +// public: |
| +// void ProcessLogs(SystemLogsResponse* response) { |
| +// //do something with the logs |
| +// } |
| +// void GetLogs() { |
| +// SystemLogsFetcher* fetcher = new SystemLogsFetcher(); |
| +// fetcher->Fetch(base::Bind(&Example::ProcessLogs, this)); |
| +// } |
| +class SystemLogsFetcher { |
| + public: |
| + explicit SystemLogsFetcher(); |
|
Lei Zhang
2012/08/21 19:56:55
nit: remove the explicit
tudalex(Chromium)
2012/08/21 21:21:12
Done.
|
| + ~SystemLogsFetcher(); |
| + |
| + void Fetch(const SysLogsFetcherCallback& callback); |
| + |
| + 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 callback_. After this it |
| + // deletes this instance of the object. |
| + void AddResponse(SystemLogsResponse* response); |
| + |
| + ScopedVector<SystemLogsSource> data_sources_; |
| + SysLogsFetcherCallback callback_; |
| + |
| + scoped_ptr<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_ |
| + |