Upstream version 11.40.277.0
[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/blob_reader.h"
14 #include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h"
15 #include "chrome/common/extensions/api/feedback_private.h"
16 #include "components/feedback/feedback_data.h"
17
18 class Profile;
19
20 using extensions::api::feedback_private::SystemInformation;
21
22 namespace extensions {
23
24 typedef std::vector<linked_ptr<SystemInformation> > SystemInformationList;
25
26 class FeedbackService {
27  public:
28   typedef base::Callback<void(bool)> SendFeedbackCallback;
29   typedef base::Callback<void(const SystemInformationList& sys_info)>
30       GetSystemInformationCallback;
31
32   // Creates a platform-specific FeedbackService instance.
33   static FeedbackService* CreateInstance();
34
35   virtual ~FeedbackService();
36
37   // Sends a feedback report.
38   void SendFeedback(Profile* profile,
39                     scoped_refptr<feedback::FeedbackData> feedback_data,
40                     const SendFeedbackCallback& callback);
41
42   // Start to gather system information.
43   // The |callback| will be invoked once the query is completed.
44   void GetSystemInformation(const GetSystemInformationCallback& callback);
45
46   // Platform specific methods:
47   // Gets the email address of the logged in user.
48   virtual std::string GetUserEmail() = 0;
49
50   // Gets the histograms in JSON.
51   virtual void GetHistograms(std::string* histograms) = 0;
52
53  protected:
54   FeedbackService();
55
56   // Used to get a weak ptr for a derived class instance.
57   virtual base::WeakPtr<FeedbackService> GetWeakPtr() = 0;
58
59   // Callbacks to receive blob data.
60   void AttachedFileCallback(scoped_ptr<std::string> data,
61                             int64 total_blob_length);
62   void ScreenshotCallback(scoped_ptr<std::string> data,
63                           int64 total_blob_length);
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  private:
70   void OnSystemLogsFetchComplete(
71       scoped_ptr<system_logs::SystemLogsResponse> sys_info);
72
73   GetSystemInformationCallback system_information_callback_;
74   SendFeedbackCallback send_feedback_callback_;
75
76   scoped_refptr<feedback::FeedbackData> feedback_data_;
77
78   DISALLOW_COPY_AND_ASSIGN(FeedbackService);
79 };
80
81 }  // namespace extensions
82
83 #endif  // CHROME_BROWSER_EXTENSIONS_API_FEEDBACK_PRIVATE_FEEDBACK_SERVICE_H_