debug_daemon_log_source.h revision a36e5920737c6adbddd3e43b760e5de8431db6e0
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_DEBUG_DAEMON_LOG_SOURCE_H_ 6#define CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_DEBUG_DAEMON_LOG_SOURCE_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include "base/memory/weak_ptr.h" 13#include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" 14 15class Profile; 16 17namespace chromeos { 18 19// Gathers log data from Debug Daemon. 20class DebugDaemonLogSource : public SystemLogsSource { 21 public: 22 DebugDaemonLogSource(); 23 virtual ~DebugDaemonLogSource(); 24 25 // SystemLogsSource override: 26 // Fetches logs from the daemon over dbus. After the fetch is complete, the 27 // results will be forwarded to the request supplied to the constructor and 28 // this instance will free itself. 29 virtual void Fetch(const SysLogsSourceCallback& callback) OVERRIDE; 30 31 private: 32 typedef std::map<std::string, std::string> KeyValueMap; 33 34 // Callbacks for the 5 different dbus calls to debugd. 35 void OnGetRoutes(bool succeeded, const std::vector<std::string>& routes); 36 void OnGetNetworkStatus(bool succeeded, const std::string& status); 37 void OnGetModemStatus(bool succeeded, const std::string& status); 38 void OnGetWiMaxStatus(bool succeeded, const std::string& status); 39 void OnGetLogs(bool succeeded, 40 const KeyValueMap& logs); 41 void OnGetUserLogFiles(bool succeeded, 42 const KeyValueMap& logs); 43 44 // Read the contents of the specified user logs files and adds it to 45 // the response parameter. 46 static void ReadUserLogFiles( 47 const KeyValueMap& user_log_files, 48 const std::vector<Profile*>& last_used_profiles, 49 SystemLogsResponse* response); 50 51 // Merge the responses from ReadUserLogFiles into the main response dict and 52 // call RequestComplete to indicate that the user log files read is complete. 53 void MergeResponse(SystemLogsResponse* response); 54 55 // Sends the data to the callback_ when all the requests are completed 56 void RequestCompleted(); 57 58 scoped_ptr<SystemLogsResponse> response_; 59 SysLogsSourceCallback callback_; 60 int num_pending_requests_; 61 base::WeakPtrFactory<DebugDaemonLogSource> weak_ptr_factory_; 62 63 DISALLOW_COPY_AND_ASSIGN(DebugDaemonLogSource); 64}; 65 66 67} // namespace chromeos 68 69#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_LOGS_DEBUG_DAEMON_LOG_SOURCE_H_ 70