diff options
author | xiyuan <xiyuan@chromium.org> | 2016-02-19 13:17:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-19 21:18:01 +0000 |
commit | f9e06bc4b2845a0b67c7b86497c2ea0be24cc616 (patch) | |
tree | 9539a780a234db493a45e7fe4f57acce19106c60 | |
parent | 15383d52e976fbb1cd1ccf9488601e1b107b0534 (diff) | |
download | chromium_src-f9e06bc4b2845a0b67c7b86497c2ea0be24cc616.zip chromium_src-f9e06bc4b2845a0b67c7b86497c2ea0be24cc616.tar.gz chromium_src-f9e06bc4b2845a0b67c7b86497c2ea0be24cc616.tar.bz2 |
cros: Extract syslog feedback sending code
Extract syslog feedback sending code into a function so that it
could be shared.
BUG=585530
Review URL: https://codereview.chromium.org/1712263002
Cr-Commit-Position: refs/heads/master@{#376535}
-rw-r--r-- | chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.cc | 47 | ||||
-rw-r--r-- | chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/feedback_util.cc | 55 | ||||
-rw-r--r-- | chrome/browser/chromeos/feedback_util.h | 25 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 2 |
5 files changed, 89 insertions, 42 deletions
diff --git a/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.cc b/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.cc index 0342e2d..9151fff 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.cc +++ b/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.cc @@ -12,6 +12,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/time/time.h" +#include "chrome/browser/chromeos/feedback_util.h" #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" #include "chrome/browser/profiles/profile.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" @@ -20,8 +21,6 @@ #include "extensions/browser/extension_system_provider.h" #include "extensions/browser/extensions_browser_client.h" -using feedback::FeedbackData; - namespace chromeos { class KioskDiagnosisRunner::Factory : public BrowserContextKeyedServiceFactory { @@ -83,44 +82,12 @@ void KioskDiagnosisRunner::Start(const std::string& app_id) { } void KioskDiagnosisRunner::StartSystemLogCollection() { - extensions::FeedbackService* service = - extensions::FeedbackPrivateAPI::GetFactoryInstance() - ->Get(profile_) - ->GetService(); - DCHECK(service); - - service->GetSystemInformation( - base::Bind(&KioskDiagnosisRunner::SendSysLogFeedback, - weak_factory_.GetWeakPtr())); -} - -void KioskDiagnosisRunner::SendSysLogFeedback( - const extensions::SystemInformationList& sys_info) { - scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); - - feedback_data->set_context(profile_); - feedback_data->set_description(base::StringPrintf( - "Autogenerated feedback:\nAppId: %s\n(uniquifier:%s)", - app_id_.c_str(), - base::Int64ToString(base::Time::Now().ToInternalValue()).c_str())); - - scoped_ptr<FeedbackData::SystemLogsMap> sys_logs( - new FeedbackData::SystemLogsMap); - for (extensions::SystemInformationList::const_iterator it = sys_info.begin(); - it != sys_info.end(); ++it) { - (*sys_logs.get())[it->get()->key] = it->get()->value; - } - feedback_data->SetAndCompressSystemInfo(std::move(sys_logs)); - - extensions::FeedbackService* service = - extensions::FeedbackPrivateAPI::GetFactoryInstance() - ->Get(profile_) - ->GetService(); - DCHECK(service); - service->SendFeedback(profile_, - feedback_data, - base::Bind(&KioskDiagnosisRunner::OnFeedbackSent, - weak_factory_.GetWeakPtr())); + const std::string description = base::StringPrintf( + "Autogenerated feedback:\nAppId: %s\n(uniquifier:%s)", app_id_.c_str(), + base::Int64ToString(base::Time::Now().ToInternalValue()).c_str()); + feedback_util::SendSysLogFeedback( + profile_, description, base::Bind(&KioskDiagnosisRunner::OnFeedbackSent, + weak_factory_.GetWeakPtr())); } void KioskDiagnosisRunner::OnFeedbackSent(bool) { diff --git a/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h b/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h index 92de7aa..5df2960 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h +++ b/chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h @@ -9,7 +9,6 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/extensions/api/feedback_private/feedback_service.h" #include "components/keyed_service/core/keyed_service.h" class Profile; @@ -33,7 +32,6 @@ class KioskDiagnosisRunner : public KeyedService { void Start(const std::string& app_id); void StartSystemLogCollection(); - void SendSysLogFeedback(const extensions::SystemInformationList& sys_info); void OnFeedbackSent(bool sent); Profile* profile_; diff --git a/chrome/browser/chromeos/feedback_util.cc b/chrome/browser/chromeos/feedback_util.cc new file mode 100644 index 0000000..18e7e5d --- /dev/null +++ b/chrome/browser/chromeos/feedback_util.cc @@ -0,0 +1,55 @@ +// Copyright 2016 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. + +#include "chrome/browser/chromeos/feedback_util.h" + +#include "base/bind.h" +#include "base/callback.h" +#include "base/logging.h" +#include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h" +#include "chrome/browser/extensions/api/feedback_private/feedback_service.h" +#include "chrome/browser/profiles/profile.h" + +using feedback::FeedbackData; + +namespace feedback_util { + +namespace { + +extensions::FeedbackService* GetFeedbackService(Profile* profile) { + return extensions::FeedbackPrivateAPI::GetFactoryInstance() + ->Get(profile) + ->GetService(); +} + +void OnGetSystemInformation(Profile* profile, + const std::string& description, + const SendSysLogFeedbackCallback& callback, + const extensions::SystemInformationList& sys_info) { + scoped_refptr<FeedbackData> feedback_data(new FeedbackData()); + + feedback_data->set_context(profile); + feedback_data->set_description(description); + + scoped_ptr<FeedbackData::SystemLogsMap> sys_logs( + new FeedbackData::SystemLogsMap); + for (extensions::SystemInformationList::const_iterator it = sys_info.begin(); + it != sys_info.end(); ++it) { + (*sys_logs.get())[it->get()->key] = it->get()->value; + } + feedback_data->SetAndCompressSystemInfo(std::move(sys_logs)); + + GetFeedbackService(profile)->SendFeedback(profile, feedback_data, callback); +} + +} // namespace + +void SendSysLogFeedback(Profile* profile, + const std::string& description, + const SendSysLogFeedbackCallback& callback) { + GetFeedbackService(profile)->GetSystemInformation( + base::Bind(&OnGetSystemInformation, profile, description, callback)); +} + +} // namespace feedback_util diff --git a/chrome/browser/chromeos/feedback_util.h b/chrome/browser/chromeos/feedback_util.h new file mode 100644 index 0000000..7399061 --- /dev/null +++ b/chrome/browser/chromeos/feedback_util.h @@ -0,0 +1,25 @@ +// Copyright 2016 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_FEEDBACK_UTIL_H_ +#define CHROME_BROWSER_CHROMEOS_FEEDBACK_UTIL_H_ + +#include <string> + +#include "base/callback_forward.h" + +class Profile; + +namespace feedback_util { + +// Sends a system log feedback from the given |profile| with the +// given |description|. |callback| will be invoked when the feedback is sent. +using SendSysLogFeedbackCallback = base::Callback<void(bool)>; +void SendSysLogFeedback(Profile* profile, + const std::string& description, + const SendSysLogFeedbackCallback& callback); + +} // namespace feedback_util + +#endif // CHROME_BROWSER_CHROMEOS_FEEDBACK_UTIL_H_ diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index cf48392..2b9e273 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -188,6 +188,8 @@ 'browser/chromeos/external_metrics.h', 'browser/chromeos/external_protocol_dialog.cc', 'browser/chromeos/external_protocol_dialog.h', + 'browser/chromeos/feedback_util.cc', + 'browser/chromeos/feedback_util.h', 'browser/chromeos/file_manager/app_id.h', 'browser/chromeos/file_manager/file_browser_handlers.cc', 'browser/chromeos/file_manager/file_browser_handlers.h', |