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

Side by Side Diff: chrome/browser/extensions/api/feedback_private/feedback_service_chromeos.cc

Issue 17111003: Implement the feedbackPrivate API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 #include "chrome/browser/extensions/api/feedback_private/feedback_service.h"
6
7 #include "base/callback.h"
8 #include "base/memory/weak_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h"
12
13 using extensions::api::feedback_private::SystemInformation;
14
15 namespace extensions {
16
17 class FeedbackServiceImpl
18 : public FeedbackService,
19 public base::SupportsWeakPtr<FeedbackServiceImpl> {
20 public:
21 FeedbackServiceImpl();
22 virtual ~FeedbackServiceImpl();
23
24 virtual std::string GetUserEmail() OVERRIDE;
25 virtual void GetSystemInformation(
26 const GetSystemInformationCallback& callback) OVERRIDE;
27
28 private:
29 void ProcessSystemLogs(scoped_ptr<chromeos::SystemLogsResponse> sys_info);
30
31 // Overridden from FeedbackService:
32 virtual base::WeakPtr<FeedbackService> GetWeakPtr() OVERRIDE;
33
34 DISALLOW_COPY_AND_ASSIGN(FeedbackServiceImpl);
35 };
36
37 FeedbackService* FeedbackService::CreateInstance() {
38 return new FeedbackServiceImpl;
39 }
40
41 FeedbackServiceImpl::FeedbackServiceImpl() {
42 }
43
44 FeedbackServiceImpl::~FeedbackServiceImpl() {
45 }
46
47 std::string FeedbackServiceImpl::GetUserEmail() {
48 chromeos::UserManager* manager = chromeos::UserManager::Get();
49 if (!manager)
50 return std::string();
51 else
52 return manager->GetLoggedInUser()->display_email();}
53
54 void FeedbackServiceImpl::GetSystemInformation(
55 const GetSystemInformationCallback& callback) {
56 system_information_callback_ = callback;
57
58 chromeos::SystemLogsFetcher* fetcher = new chromeos::SystemLogsFetcher();
59 fetcher->Fetch(base::Bind(&FeedbackServiceImpl::ProcessSystemLogs,
60 AsWeakPtr()));
61 }
62
63 void FeedbackServiceImpl::ProcessSystemLogs(
64 scoped_ptr<chromeos::SystemLogsResponse> sys_info_map) {
65 SystemInformationList sys_info_list;
66 if (!sys_info_map.get()) {
67 system_information_callback_.Run(sys_info_list);
68 return;
69 }
70
71 for (chromeos::SystemLogsResponse::iterator it = sys_info_map->begin();
72 it != sys_info_map->end(); ++it) {
73 base::DictionaryValue sys_info_value;
74 sys_info_value.Set("key", new base::StringValue(it->first));
75 sys_info_value.Set("value", new base::StringValue(it->second));
76
77 linked_ptr<SystemInformation> sys_info(new SystemInformation());
78 SystemInformation::Populate(sys_info_value, sys_info.get());
79
80 sys_info_list.push_back(sys_info);
81 }
82
83 system_information_callback_.Run(sys_info_list);
84 }
85
86 base::WeakPtr<FeedbackService> FeedbackServiceImpl::GetWeakPtr() {
87 return AsWeakPtr();
88 }
89
90 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698