| 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..11356d7b383e4bebc6c5b9ce3ee6cbb2441d937e
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/syslogs/syslogs_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_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;
|
| +
|
| +class SysLogsInterface {
|
| + public:
|
| + virtual void Fetch(SysLogsFetcherCallback) = 0;
|
| + 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:
|
| + void AddData(SysLogsResponse*);
|
| +
|
| + SysLogsDataSources data_sources_;
|
| + SysLogsFetcherCallback request_;
|
| +
|
| + SysLogsResponse* response_; // The actual response data.
|
| + base::Lock response_lock_; // The lock for it.
|
| + 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_
|
| +
|
|
|