OLD | NEW |
(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 |
OLD | NEW |