Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_diagnosis_runner.cc
blob659c94ba2588195312c10b4c6a3f98075b8ff879
1 // Copyright 2014 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.
5 #include "chrome/browser/chromeos/app_mode/kiosk_diagnosis_runner.h"
7 #include "base/bind.h"
8 #include "base/memory/singleton.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "extensions/browser/extension_system_provider.h"
18 #include "extensions/browser/extensions_browser_client.h"
20 using feedback::FeedbackData;
22 namespace chromeos {
24 class KioskDiagnosisRunner::Factory : public BrowserContextKeyedServiceFactory {
25 public:
26 static KioskDiagnosisRunner* GetForProfile(Profile* profile) {
27 return static_cast<KioskDiagnosisRunner*>(
28 GetInstance()->GetServiceForBrowserContext(profile, true));
31 static Factory* GetInstance() {
32 return Singleton<Factory>::get();
35 private:
36 friend struct DefaultSingletonTraits<Factory>;
38 Factory()
39 : BrowserContextKeyedServiceFactory(
40 "KioskDiagnosisRunner",
41 BrowserContextDependencyManager::GetInstance()) {
42 DependsOn(extensions::ExtensionsBrowserClient::Get()
43 ->GetExtensionSystemFactory());
44 DependsOn(extensions::FeedbackPrivateAPI::GetFactoryInstance());
47 ~Factory() override {}
49 // BrowserContextKeyedServiceFactory overrides:
50 KeyedService* BuildServiceInstanceFor(
51 content::BrowserContext* context) const override {
52 Profile* profile = static_cast<Profile*>(context);
53 return new KioskDiagnosisRunner(profile);
56 private:
57 DISALLOW_COPY_AND_ASSIGN(Factory);
60 // static
61 void KioskDiagnosisRunner::Run(Profile* profile,
62 const std::string& app_id) {
63 KioskDiagnosisRunner::Factory::GetForProfile(profile)->Start(app_id);
66 KioskDiagnosisRunner::KioskDiagnosisRunner(Profile* profile)
67 : profile_(profile),
68 weak_factory_(this) {}
70 KioskDiagnosisRunner::~KioskDiagnosisRunner() {}
72 void KioskDiagnosisRunner::Start(const std::string& app_id) {
73 app_id_ = app_id;
75 // Schedules system logs to be collected after 1 minute.
76 content::BrowserThread::PostDelayedTask(
77 content::BrowserThread::UI,
78 FROM_HERE,
79 base::Bind(&KioskDiagnosisRunner::StartSystemLogCollection,
80 weak_factory_.GetWeakPtr()),
81 base::TimeDelta::FromMinutes(1));
84 void KioskDiagnosisRunner::StartSystemLogCollection() {
85 extensions::FeedbackService* service =
86 extensions::FeedbackPrivateAPI::GetFactoryInstance()
87 ->Get(profile_)
88 ->GetService();
89 DCHECK(service);
91 service->GetSystemInformation(
92 base::Bind(&KioskDiagnosisRunner::SendSysLogFeedback,
93 weak_factory_.GetWeakPtr()));
96 void KioskDiagnosisRunner::SendSysLogFeedback(
97 const extensions::SystemInformationList& sys_info) {
98 scoped_refptr<FeedbackData> feedback_data(new FeedbackData());
100 feedback_data->set_context(profile_);
101 feedback_data->set_description(base::StringPrintf(
102 "Autogenerated feedback:\nAppId: %s\n(uniquifier:%s)",
103 app_id_.c_str(),
104 base::Int64ToString(base::Time::Now().ToInternalValue()).c_str()));
106 scoped_ptr<FeedbackData::SystemLogsMap> sys_logs(
107 new FeedbackData::SystemLogsMap);
108 for (extensions::SystemInformationList::const_iterator it = sys_info.begin();
109 it != sys_info.end(); ++it) {
110 (*sys_logs.get())[it->get()->key] = it->get()->value;
112 feedback_data->SetAndCompressSystemInfo(sys_logs.Pass());
114 extensions::FeedbackService* service =
115 extensions::FeedbackPrivateAPI::GetFactoryInstance()
116 ->Get(profile_)
117 ->GetService();
118 DCHECK(service);
119 service->SendFeedback(profile_,
120 feedback_data,
121 base::Bind(&KioskDiagnosisRunner::OnFeedbackSent,
122 weak_factory_.GetWeakPtr()));
125 void KioskDiagnosisRunner::OnFeedbackSent(bool) {
126 // Do nothing.
129 } // namespace chromeos