- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / feedback_private / feedback_service.h
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_SERVICE_H_
7
8 #include <vector>
9 #include "base/basictypes.h"
10 #include "base/callback.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "chrome/browser/extensions/api/feedback_private/blob_reader.h"
14 #include "chrome/browser/feedback/feedback_data.h"
15 #include "chrome/common/extensions/api/feedback_private.h"
16
17 class Profile;
18
19 using extensions::api::feedback_private::SystemInformation;
20
21 namespace extensions {
22
23 typedef std::vector<linked_ptr<SystemInformation> > SystemInformationList;
24
25 class FeedbackService {
26  public:
27   typedef base::Callback<void(bool)> SendFeedbackCallback;
28   typedef base::Callback<void(const SystemInformationList& sys_info)>
29       GetSystemInformationCallback;
30
31   // Creates a platform-specific FeedbackService instance.
32   static FeedbackService* CreateInstance();
33   // Convenience method for populating a SystemInformationList structure
34   // with a key/value pair.
35   static void PopulateSystemInfo(SystemInformationList* sys_info_list,
36                                  const std::string& key,
37                                  const std::string& value);
38
39   virtual ~FeedbackService();
40
41   // Sends a feedback report.
42   virtual void SendFeedback(Profile* profile,
43                             scoped_refptr<FeedbackData> feedback_data,
44                             const SendFeedbackCallback& callback);
45
46   // Platform specific methods:
47   // Get's the email address of the logged in user.
48   virtual std::string GetUserEmail() = 0;
49
50   // Start to gather system information.
51   // The |callback| will be invoked once the query is completed.
52   virtual void GetSystemInformation(
53       const GetSystemInformationCallback& callback) = 0;
54
55  protected:
56   FeedbackService();
57
58   // Used to get a weak ptr for a derived class instance.
59   virtual base::WeakPtr<FeedbackService> GetWeakPtr() = 0;
60
61   // Callbacks to receive blob data.
62   void AttachedFileCallback(scoped_ptr<std::string> data);
63   void ScreenshotCallback(scoped_ptr<std::string> data);
64
65   // Checks if we have read all the blobs we need to; signals the feedback
66   // data object once all the requisite data has been populated.
67   void CompleteSendFeedback();
68
69   GetSystemInformationCallback system_information_callback_;
70   SendFeedbackCallback send_feedback_callback_;
71
72   scoped_refptr<FeedbackData> feedback_data_;
73
74   DISALLOW_COPY_AND_ASSIGN(FeedbackService);
75 };
76
77 }  // namespace extensions
78
79 #endif  // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_SERVICE_H_