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..40e063425fd1a575aed36d82d3c62d0f5221f93b |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/system_logs/system_logs_fetcher.h |
| @@ -0,0 +1,76 @@ |
| +// 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" |
| +#include "base/memory/scoped_vector.h" |
| +namespace chromeos { |
| + |
| +typedef std::map<std::string, std::string> SystemLogsResponse; |
| +typedef base::Callback<void(SystemLogsResponse*)> SysLogsFetcherCallback; |
|
satorux1
2012/08/16 10:50:57
please add a parameter name when typedefin'g a cal
tudalex(Chromium)
2012/08/16 22:33:03
Done.
|
| + |
| +// 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& 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, the last one will replace the previous one. |
| +// The class runs on the UI thread. |
| +// |
| +// EXAMPLE: |
| +// class Example { |
| +// public: |
| +// ProcessLogs(chrome::SystemLogsResponse) { |
|
satorux1
2012/08/16 10:50:57
indentation is off. 3 spaces -> 2 spaces.
'void'
tudalex(Chromium)
2012/08/16 22:33:03
Done.
|
| +// //do something with the logs |
| +// } |
| +// GetLogs() { |
| +// chrome::SystemLogsFetcher* fetcher = |
|
satorux1
2012/08/16 10:50:57
remove chrome::
tudalex(Chromium)
2012/08/16 22:33:03
Done.
|
| +// chrome::SystemLogsFetcher::GetInstance()->CreateFetcher(); |
|
satorux1
2012/08/16 10:50:57
I think this is not correct. this is no longer a s
tudalex(Chromium)
2012/08/16 22:33:03
Right. Fixed.
|
| +// 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 AddResponse(SystemLogsResponse* response); |
| + |
| + ScopedVector<SystemLogsSource> data_sources_; |
| + SysLogsFetcherCallback request_; |
|
satorux1
2012/08/16 10:50:57
callback_
tudalex(Chromium)
2012/08/16 22:33:03
Done.
|
| + |
| + 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_ |
| + |