summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/feedback_util.cc
blob: 18e7e5de9c59304b6a0880fd5d8ea3f4da0552f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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