Home | History | Annotate | Download | only in feedback
      1 // Copyright (c) 2012 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_FEEDBACK_FEEDBACK_DATA_H_
      6 #define CHROME_BROWSER_FEEDBACK_FEEDBACK_DATA_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/memory/ref_counted.h"
     12 #include "chrome/browser/ui/webui/screenshot_source.h"
     13 #include "url/gurl.h"
     14 
     15 #if defined(OS_CHROMEOS)
     16 #include "chrome/browser/chromeos/system_logs/scrubbed_system_logs_fetcher.h"
     17 #endif
     18 
     19 class Profile;
     20 #if defined(OS_CHROMEOS)
     21 namespace base {
     22 class RefCountedString;
     23 }
     24 #endif
     25 
     26 class FeedbackData : public base::RefCountedThreadSafe<FeedbackData> {
     27  public:
     28   FeedbackData();
     29 
     30   // Called once we've update all the data from the feedback page.
     31   void FeedbackPageDataComplete();
     32 
     33 #if defined(OS_CHROMEOS)
     34   // Called once we have read our system logs.
     35   void CompressSyslogs(scoped_ptr<chromeos::SystemLogsResponse> sys_info);
     36 
     37   // Called once we have read and compressed our system logs.
     38   void SyslogsComplete(scoped_ptr<chromeos::SystemLogsResponse> sys_info,
     39                        scoped_ptr<std::string> compressed_logs);
     40 
     41   // Called once we have read our attached file.
     42   void ReadFileComplete();
     43 
     44   // Starts the collection of our system logs. SyslogsComplete is called once
     45   // the collection is done.
     46   void StartSyslogsCollection();
     47 #endif
     48 
     49   // Returns true if we've complete collection of data from all our
     50   // data sources. At this time this involves the system logs, the attached
     51   // file (if needed to be read of the disk) and the rest of the data from
     52   // the feedback page.
     53   bool DataCollectionComplete();
     54 
     55   // Sends the feedback report if we have all our data complete.
     56   void SendReport();
     57 
     58   // Starts reading the file to attach to this report into the string
     59   // file_data. ReadFileComplete is called once this is done.
     60   void StartReadFile(const std::string filename, const std::string* file_data);
     61 
     62   // Getters
     63   Profile* profile() const { return profile_; }
     64   const std::string& category_tag() const { return category_tag_; }
     65   const std::string& page_url() const { return page_url_; }
     66   const std::string& description() const { return description_; }
     67   const std::string& user_email() const { return user_email_; }
     68   ScreenshotDataPtr image() const { return image_; }
     69   const std::string attached_filename() const { return attached_filename_; }
     70   const GURL attached_file_url() const { return attached_file_url_; }
     71   std::string* attached_filedata() const { return attached_filedata_.get(); }
     72   const GURL screenshot_url() const { return screenshot_url_; }
     73 #if defined(OS_CHROMEOS)
     74   chromeos::SystemLogsResponse* sys_info() const {
     75     return send_sys_info_ ? sys_info_.get() : NULL;
     76   }
     77   const int trace_id() const { return trace_id_; }
     78   const std::string timestamp() const { return timestamp_; }
     79   std::string* compressed_logs() const { return compressed_logs_.get(); }
     80 #endif
     81 
     82   // Setters
     83   void set_profile(Profile* profile) { profile_ = profile; }
     84   void set_category_tag(const std::string& category_tag) {
     85     category_tag_ = category_tag;
     86   }
     87   void set_page_url(const std::string& page_url) { page_url_ = page_url; }
     88   void set_description(const std::string& description) {
     89     description_ = description;
     90   }
     91   void set_user_email(const std::string& user_email) {
     92     user_email_ = user_email;
     93   }
     94   void set_image(ScreenshotDataPtr image) { image_ = image; }
     95   void set_attached_filename(const std::string& attached_filename) {
     96     attached_filename_ = attached_filename;
     97   }
     98   void set_attached_filedata(scoped_ptr<std::string> attached_filedata) {
     99     attached_filedata_ = attached_filedata.Pass();
    100   }
    101   void set_attached_file_url(const GURL& url) { attached_file_url_ = url; }
    102   void set_screenshot_url(const GURL& url) { screenshot_url_ = url; }
    103 #if defined(OS_CHROMEOS)
    104   void set_sys_info(scoped_ptr<chromeos::SystemLogsResponse> sys_info);
    105   void set_trace_id(int trace_id) { trace_id_ = trace_id; }
    106   void set_send_sys_info(bool send_sys_info) { send_sys_info_ = send_sys_info; }
    107   void set_timestamp(const std::string& timestamp) {
    108     timestamp_ = timestamp;
    109   }
    110 #endif
    111 
    112  private:
    113   friend class base::RefCountedThreadSafe<FeedbackData>;
    114 
    115   virtual ~FeedbackData();
    116 
    117 #if defined(OS_CHROMEOS)
    118   void ReadAttachedFile(const base::FilePath& from);
    119   void OnGetTraceData(scoped_refptr<base::RefCountedString> trace_data);
    120 #endif
    121 
    122   Profile* profile_;
    123 
    124   std::string category_tag_;
    125   std::string page_url_;
    126   std::string description_;
    127   std::string user_email_;
    128   ScreenshotDataPtr image_;
    129   std::string attached_filename_;
    130   scoped_ptr<std::string> attached_filedata_;
    131 
    132   GURL attached_file_url_;
    133   GURL screenshot_url_;
    134 
    135 #if defined(OS_CHROMEOS)
    136   // Chromeos specific values for SendReport. Will be deleted in
    137   // feedback_util::SendReport once consumed or in SyslogsComplete if
    138   // we don't send the logs with the report.
    139   scoped_ptr<chromeos::SystemLogsResponse> sys_info_;
    140 
    141   int trace_id_;
    142   std::string timestamp_;
    143   scoped_ptr<std::string> compressed_logs_;
    144 
    145   // Flag to indicate whether or not we should send the system information
    146   // gathered with the report or not.
    147   bool send_sys_info_;
    148 
    149   // Flags to indicate if various pieces of data needed for the report have
    150   // been collected yet or are still pending collection.
    151   bool read_attached_file_complete_;
    152   bool syslogs_collection_complete_;
    153 #endif
    154   bool feedback_page_data_complete_;
    155 
    156   DISALLOW_COPY_AND_ASSIGN(FeedbackData);
    157 };
    158 
    159 #endif  // CHROME_BROWSER_FEEDBACK_FEEDBACK_DATA_H_
    160