feedback_service_nonchromeos.cc revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
1// Copyright 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 "chrome/browser/profiles/profile.h"
10#include "chrome/browser/profiles/profile_manager.h"
11#include "chrome/browser/signin/signin_manager.h"
12#include "chrome/browser/signin/signin_manager_factory.h"
13
14using extensions::api::feedback_private::SystemInformation;
15
16namespace extensions {
17
18class FeedbackServiceImpl
19    : public FeedbackService,
20      public base::SupportsWeakPtr<FeedbackServiceImpl> {
21 public:
22  FeedbackServiceImpl();
23  virtual ~FeedbackServiceImpl();
24
25  virtual std::string GetUserEmail() OVERRIDE;
26  virtual void GetSystemInformation(
27      const GetSystemInformationCallback& callback) OVERRIDE;
28
29 private:
30  // Overridden from FeedbackService:
31  virtual base::WeakPtr<FeedbackService> GetWeakPtr() OVERRIDE;
32
33  DISALLOW_COPY_AND_ASSIGN(FeedbackServiceImpl);
34};
35
36FeedbackService* FeedbackService::CreateInstance() {
37  return new FeedbackServiceImpl;
38}
39
40FeedbackServiceImpl::FeedbackServiceImpl() {
41}
42
43FeedbackServiceImpl::~FeedbackServiceImpl() {
44}
45
46std::string FeedbackServiceImpl::GetUserEmail() {
47  Profile* profile = ProfileManager::GetLastUsedProfile();
48  if (!profile)
49    return std::string();
50
51  SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
52  if (!signin)
53    return std::string();
54
55  return signin->GetAuthenticatedUsername();
56}
57
58void FeedbackServiceImpl::GetSystemInformation(
59    const GetSystemInformationCallback& callback) {
60  system_information_callback_ = callback;
61
62  SystemInformationList sys_info_list;
63  system_information_callback_.Run(sys_info_list);
64}
65
66base::WeakPtr<FeedbackService> FeedbackServiceImpl::GetWeakPtr() {
67  return AsWeakPtr();
68}
69
70}  // namespace extensions
71