Home | History | Annotate | Download | only in feedback
      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_filename() const { return attached_filename_; }
     60   const std::string attached_file_uuid() const { return attached_file_uuid_; }
     61   const std::string screenshot_uuid() const { return screenshot_uuid_; }
     62   int trace_id() const { return trace_id_; }
     63 
     64   // Setters
     65   void set_context(content::BrowserContext* context) { context_ = context; }
     66   void set_attached_filename(const std::string& attached_filename) {
     67     attached_filename_ = attached_filename;
     68   }
     69   void set_attached_file_uuid(const std::string& uuid) {
     70     attached_file_uuid_ = uuid;
     71   }
     72   void set_screenshot_uuid(const std::string& uuid) {
     73     screenshot_uuid_ = uuid;
     74   }
     75   void set_trace_id(int trace_id) { trace_id_ = trace_id; }
     76   void set_send_report_callback(
     77       const base::Callback<void(scoped_refptr<FeedbackData>)>& send_report) {
     78     send_report_ = send_report;
     79   }
     80 
     81  private:
     82   virtual ~FeedbackData();
     83 
     84   // Called once a compression operation is complete.
     85   void OnCompressComplete();
     86 
     87   void OnGetTraceData(int trace_id,
     88                       scoped_refptr<base::RefCountedString> trace_data);
     89 
     90   base::Callback<void(scoped_refptr<FeedbackData>)> send_report_;
     91 
     92   content::BrowserContext* context_;
     93 
     94   std::string attached_filename_;
     95   std::string attached_file_uuid_;
     96   std::string screenshot_uuid_;
     97 
     98   int trace_id_;
     99 
    100   int pending_op_count_;
    101   bool report_sent_;
    102 
    103   DISALLOW_COPY_AND_ASSIGN(FeedbackData);
    104 };
    105 
    106 }  // namespace feedback
    107 
    108 #endif  // COMPONENTS_FEEDBACK_FEEDBACK_DATA_H_
    109