Chromium Code Reviews| Index: chrome/browser/chromeos/syslogs/syslogs_fetcher.h |
| diff --git a/chrome/browser/chromeos/syslogs/syslogs_fetcher.h b/chrome/browser/chromeos/syslogs/syslogs_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be8db6b9b16118816108bc05a0c293153094a23c |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/syslogs/syslogs_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_SYSLOGS_SYSLOGS_FETCHER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_ |
| + |
| +#include <string> |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/synchronization/lock.h" |
| + |
| +namespace chromeos { |
| + |
| +typedef std::map<std::string, std::string> SysLogsResponse; |
| +typedef base::Callback<void(SysLogsResponse*)> SysLogsFetcherCallback; |
| + |
| +// The SysLogsInterface provides a interface for the data sources that the |
| +// SysLogsFetcher class uses to fetch logs and other information. |
| +class SysLogsInterface { |
| + public: |
| + // Fetches data and passes it by to the callback |
| + virtual void Fetch(const SysLogsFetcherCallback&) = 0; |
|
satorux1
2012/08/07 01:15:07
parameter name is missing. Please fix everywhere.
tudalex(Chromium)
2012/08/07 23:46:54
Done.
|
| + virtual ~SysLogsInterface() {} |
| +}; |
| + |
| +typedef std::vector<SysLogsInterface*> SysLogsDataSources; |
| + |
| +// The SysLogsFetcher receives a list of data sources which must be classes that |
| +// implement the SysLogsInterface. It's Fetch function receives as a parameter |
| +// a callback that takes only one parameter SysLogsResponse that is a map of |
| +// keys and values. |
| +// Each data source also returns a SysLogsResponse. 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 |
| +// SysLogsFetcher deletes itself after calling the callback it received. |
| +// |
| +// EXAMPLE: |
| +// class Example { |
| +// public: |
| +// ProcessLogs(chrome::SysLogsResponse) { |
| +// //do something with the logs |
| +// } |
| +// GetLogs() { |
| +// chrome::SysLogsFetcher* fetcher = |
| +// chrome::SysLogsFetcherFactory::GetInstance()->CreateFetcher(); |
| +// fetcher->Fetch(base::Bind(&Example::ProcessLogs,this)); |
| +// } |
| +class SysLogsFetcher { |
| + public: |
| + explicit SysLogsFetcher(SysLogsDataSources); |
| + ~SysLogsFetcher() {} |
| + |
| + void Fetch(SysLogsFetcherCallback); |
| + |
| + 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(SysLogsResponse*); |
| + |
| + SysLogsDataSources data_sources_; |
| + SysLogsFetcherCallback request_; |
| + |
| + SysLogsResponse* response_; // The actual response data. |
| + base::Lock response_lock_; // The lock for it. |
|
satorux1
2012/08/07 01:15:07
why is Lock needed? we usually don't need it.
tudalex(Chromium)
2012/08/07 23:46:54
Done.
|
| + size_t responses_; // The number of callbacks it should get. |
| + |
| + base::WeakPtrFactory<SysLogsFetcher> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SysLogsFetcher); |
| +}; |
| + |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_SYSLOGS_SYSLOGS_FETCHER_H_ |
| + |