Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / feedback / feedback_data.h
1 // Copyright 2014 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 COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_
6 #define COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/feedback/feedback_common.h"
13 #include "url/gurl.h"
14
15 namespace base {
16 class FilePath;
17 class RefCountedString;
18 }
19 namespace content {
20 class BrowserContext;
21 }
22
23 namespace feedback {
24
25 class FeedbackData : public FeedbackCommon {
26  public:
27   FeedbackData();
28
29   // Called once we've updated all the data from the feedback page.
30   void OnFeedbackPageDataComplete();
31
32   // Sets the system information for this instance and kicks off its
33   // compression.
34   void SetAndCompressSystemInfo(scoped_ptr<SystemLogsMap> sys_info);
35
36   // Sets the histograms for this instance and kicks off its
37   // compression.
38   void SetAndCompressHistograms(scoped_ptr<std::string> histograms);
39
40   // Sets the attached file data and kicks off its compression.
41   void AttachAndCompressFileData(scoped_ptr<std::string> attached_filedata);
42
43   // Called once we have compressed our system logs.
44   void OnCompressLogsComplete(scoped_ptr<std::string> compressed_logs);
45
46   // Called once we have compressed our attached file.
47   void OnCompressFileComplete(scoped_ptr<std::string> compressed_file);
48
49   // Returns true if we've completed all the tasks needed before we can send
50   // feedback - at this time this is includes getting the feedback page data
51   // and compressing the system logs.
52   bool IsDataComplete();
53
54   // Sends the feedback report if we have all our data complete.
55   void SendReport();
56
57   // Getters
58   content::BrowserContext* context() const { return context_; }
59   const std::string& attached_file_uuid() const { return attached_file_uuid_; }
60   const std::string& screenshot_uuid() const { return screenshot_uuid_; }
61
62   // Setters
63   void set_context(content::BrowserContext* context) { context_ = context; }
64   void set_attached_filename(const std::string& attached_filename) {
65     attached_filename_ = attached_filename;
66   }
67   void set_attached_file_uuid(const std::string& uuid) {
68     attached_file_uuid_ = uuid;
69   }
70   void set_screenshot_uuid(const std::string& uuid) {
71     screenshot_uuid_ = uuid;
72   }
73   void set_trace_id(int trace_id) { trace_id_ = trace_id; }
74   void set_send_report_callback(
75       const base::Callback<void(scoped_refptr<FeedbackData>)>& send_report) {
76     send_report_ = send_report;
77   }
78
79  private:
80   virtual ~FeedbackData();
81
82   // Called once a compression operation is complete.
83   void OnCompressComplete();
84
85   void OnGetTraceData(int trace_id,
86                       scoped_refptr<base::RefCountedString> trace_data);
87
88   base::Callback<void(scoped_refptr<FeedbackData>)> send_report_;
89
90   content::BrowserContext* context_;
91
92   std::string attached_filename_;
93   std::string attached_file_uuid_;
94   std::string screenshot_uuid_;
95
96   int trace_id_;
97
98   int pending_op_count_;
99   bool report_sent_;
100
101   DISALLOW_COPY_AND_ASSIGN(FeedbackData);
102 };
103
104 }  // namespace feedback
105
106 #endif  // COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_