Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9261)

Unified Diff: chrome/browser/chromeos/system_logs/system_logs_fetcher.h

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1549a7900d8c3ae5278edd4bd5df1154d73f3d44
--- /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;
+
+// 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() {}
+};
+
+// 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) {
+// //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 AddResponse(SystemLogsResponse* callback);
satorux1 2012/08/15 22:01:09 response. this is not callback, right?
tudalex(Chromium) 2012/08/16 01:08:57 Yes. Done.
+
+ ScopedVector<SystemLogsSource> 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_
+

Powered by Google App Engine
This is Rietveld 408576698