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

Unified Diff: chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc

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/syslogs/debugd_log_fetcher.cc
diff --git a/chrome/browser/chromeos/system/sysinfo_provider.cc b/chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc
similarity index 54%
rename from chrome/browser/chromeos/system/sysinfo_provider.cc
rename to chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc
index 4869a104161b0cedbee86c8539e154295d58cfa3..4848ab616c77a56315a8f3788e2197c96aa3f8be 100644
--- a/chrome/browser/chromeos/system/sysinfo_provider.cc
+++ b/chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc
@@ -2,29 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/system/sysinfo_provider.h"
+#include "chrome/browser/chromeos/syslogs/debugd_log_fetcher.h"
+#include "vector"
rkc 2012/08/06 18:30:18 This should be #include <vector> and separated by
tudalex(Chromium) 2012/08/06 19:14:22 Acutally it doesn't even need to be there, it's al
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/command_line.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/string_util.h"
-#include "base/synchronization/waitable_event.h"
-#include "base/threading/thread.h"
-#include "chrome/browser/memory_details.h"
+#include "chrome/browser/chromeos/syslogs/syslogs_fetcher.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/debug_daemon_client.h"
-#include "content/public/browser/browser_thread.h"
-
-using content::BrowserThread;
namespace chromeos {
-namespace system {
// Fetches logs from the debug daemon over DBus. When all the logs have been
// fetched, forwards the results to the supplied Request. Used like:
@@ -32,45 +24,19 @@ namespace system {
// fetcher->Fetch();
// Note that you do not need to delete the fetcher; it will delete itself after
// Fetch() has forwarded the result to the request handler.
-class DebugDaemonLogFetcher {
- public:
- typedef
- scoped_refptr<CancelableRequest<SysInfoProvider::FetchCompleteCallback> >
- Request;
-
- explicit DebugDaemonLogFetcher(Request request);
- ~DebugDaemonLogFetcher();
-
- // Fetches logs from the daemon over dbus. After the fetch is complete, the
- // results will be forwarded to the request supplied to the constructor and
- // this instance will free itself.
- void Fetch();
- private:
- // Callbacks
- void GotRoutes(bool succeeded, const std::vector<std::string>& routes);
- void GotNetworkStatus(bool succeeded, const std::string& status);
- void GotModemStatus(bool succeeded, const std::string& status);
- void GotLogs(bool succeeded, const std::map<std::string, std::string>& logs);
- void RequestCompleted();
-
- SysInfoResponse* response_;
- Request request_;
- int pending_requests_;
- base::WeakPtrFactory<DebugDaemonLogFetcher> weak_ptr_factory_;
-};
-
-DebugDaemonLogFetcher::DebugDaemonLogFetcher(Request request)
- : response_(new SysInfoResponse()), request_(request),
- weak_ptr_factory_(this) { }
-
-DebugDaemonLogFetcher::~DebugDaemonLogFetcher() { }
-
-void DebugDaemonLogFetcher::Fetch() {
+
+
+DebugDaemonLogFetcher::DebugDaemonLogFetcher()
+ : response_(new SysLogsResponse()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
+
+DebugDaemonLogFetcher::~DebugDaemonLogFetcher() {}
+
+void DebugDaemonLogFetcher::Fetch(SysLogsFetcherCallback request) {
+ request_ = request;
DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient();
pending_requests_ = 4;
- // Note that this use of base::Unretained(this) is safe, since |this| is
- // deleted in RequestCompleted if and only if all outstanding callbacks are
- // done.
+
client->GetRoutes(true, false,
base::Bind(&DebugDaemonLogFetcher::GotRoutes,
weak_ptr_factory_.GetWeakPtr()));
@@ -129,33 +95,8 @@ void DebugDaemonLogFetcher::GotLogs(bool /* succeeded */,
void DebugDaemonLogFetcher::RequestCompleted() {
if (--pending_requests_)
return;
- request_->ForwardResult(response_);
- BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
-}
-
-class SysInfoProviderImpl : public SysInfoProvider {
- public:
- virtual Handle Fetch(CancelableRequestConsumerBase* consumer,
- const FetchCompleteCallback& callback);
-};
-
-CancelableRequestProvider::Handle SysInfoProviderImpl::Fetch(
- CancelableRequestConsumerBase* consumer,
- const FetchCompleteCallback& callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- scoped_refptr<CancelableRequest<FetchCompleteCallback> >
- request(new CancelableRequest<FetchCompleteCallback>(callback));
- AddRequest(request, consumer);
- // Deleted by DebugDaemonLogFetcher::RequestCompleted()
- DebugDaemonLogFetcher* fetcher = new DebugDaemonLogFetcher(request);
- fetcher->Fetch();
-
- return request->handle();
-}
+ request_.Run(response_);
-SysInfoProvider* SysInfoProvider::Create() {
- return new SysInfoProviderImpl();
}
-} // namespace system
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698