Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / webrtc_log_uploader.h
index 2a33417..dd9c916 100644 (file)
@@ -7,11 +7,10 @@
 
 #include <map>
 #include <string>
+#include <vector>
 
 #include "base/basictypes.h"
 #include "base/gtest_prod_util.h"
-#include "base/memory/ref_counted.h"
-#include "base/platform_file.h"
 #include "base/threading/thread_checker.h"
 #include "chrome/browser/media/webrtc_logging_handler_host.h"
 #include "net/url_request/url_fetcher_delegate.h"
@@ -24,19 +23,23 @@ class SharedMemory;
 
 namespace net {
 class URLFetcher;
-class URLRequestContextGetter;
 }
 
 typedef struct z_stream_s z_stream;
 
-// Used when uploading is done to perform post-upload actions.
-typedef struct {
-  base::FilePath upload_list_path;
+// Used when uploading is done to perform post-upload actions. |log_path| is
+// also used pre-upload.
+struct WebRtcLogUploadDoneData {
+  WebRtcLogUploadDoneData();
+  ~WebRtcLogUploadDoneData();
+
+  base::FilePath log_path;
+  base::FilePath incoming_rtp_dump;
+  base::FilePath outgoing_rtp_dump;
   WebRtcLoggingHandlerHost::UploadDoneCallback callback;
   scoped_refptr<WebRtcLoggingHandlerHost> host;
-} WebRtcLogUploadDoneData;
-
-class WebRtcLogURLRequestContextGetter;
+  std::string local_log_id;
+};
 
 // WebRtcLogUploader uploads WebRTC logs, keeps count of how many logs have
 // been started and denies further logs if a limit is reached. It also adds
@@ -45,12 +48,13 @@ class WebRtcLogURLRequestContextGetter;
 class WebRtcLogUploader : public net::URLFetcherDelegate {
  public:
   WebRtcLogUploader();
-  virtual ~WebRtcLogUploader();
+  ~WebRtcLogUploader() override;
 
   // net::URLFetcherDelegate implementation.
-  virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
-  virtual void OnURLFetchUploadProgress(const net::URLFetcher* source,
-                                        int64 current, int64 total) OVERRIDE;
+  void OnURLFetchComplete(const net::URLFetcher* source) override;
+  void OnURLFetchUploadProgress(const net::URLFetcher* source,
+                                int64 current,
+                                int64 total) override;
 
   // Returns true is number of logs limit is not reached yet. Increases log
   // count if true is returned. Must be called before UploadLog().
@@ -68,51 +72,79 @@ class WebRtcLogUploader : public net::URLFetcherDelegate {
   // granted by calling ApplyForStartLogging() and getting true in return. After
   // this function has been called, a new permission must be granted. Call
   // either this function or LoggingStoppedDontUpload().
+  // |upload_done_data.local_log_id| is set and used internally and should be
+  // left empty.
   void LoggingStoppedDoUpload(
-      net::URLRequestContextGetter* request_context,
       scoped_ptr<unsigned char[]> log_buffer,
       uint32 length,
       const std::map<std::string, std::string>& meta_data,
       const WebRtcLogUploadDoneData& upload_done_data);
 
+  // Cancels URL fetcher operation by deleting all URL fetchers. This cancels
+  // any pending uploads and releases SystemURLRequestContextGetter references.
+  // Sets |shutting_down_| which prevent new fetchers to be created.
+  void StartShutdown();
+
   // For testing purposes. If called, the multipart will not be uploaded, but
   // written to |post_data_| instead.
   void OverrideUploadWithBufferForTesting(std::string* post_data) {
+    DCHECK((post_data && !post_data_) || (!post_data && post_data_));
     post_data_ = post_data;
   }
 
  private:
   FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest,
+                           AddLocallyStoredLogInfoToUploadListFile);
+  FRIEND_TEST_ALL_PREFIXES(WebRtcLogUploaderTest,
                            AddUploadedLogInfoToUploadListFile);
 
   // Sets up a multipart body to be uploaded. The body is produced according
   // to RFC 2046.
-  void SetupMultipart(std::string* post_data, uint8* log_buffer,
-                      uint32 log_buffer_length,
+  void SetupMultipart(std::string* post_data,
+                      const std::vector<uint8>& compressed_log,
+                      const base::FilePath& incoming_rtp_dump,
+                      const base::FilePath& outgoing_rtp_dump,
                       const std::map<std::string, std::string>& meta_data);
 
-  void AddLogData(std::string* post_data, uint8* log_buffer,
-                  uint32 log_buffer_length);
-  void CompressLog(std::string* post_data, uint8* input, uint32 input_size);
-  void ResizeForNextOutput(std::string* post_data, z_stream* stream);
+  void CompressLog(std::vector<uint8>* compressed_log,
+                   uint8* input,
+                   uint32 input_size);
+
+  void ResizeForNextOutput(std::vector<uint8>* compressed_log,
+                           z_stream* stream);
 
   void CreateAndStartURLFetcher(
-      scoped_refptr<net::URLRequestContextGetter> request_context,
       const WebRtcLogUploadDoneData& upload_done_data,
       scoped_ptr<std::string> post_data);
 
   void DecreaseLogCount();
 
-  // Append information (time and report ID) about this uploaded log to a log
-  // list file, limited to |kLogListLimitLines| entries. This list is used for
-  // viewing the uploaded logs under chrome://webrtc-logs, see
-  // WebRtcLogUploadList. The list has the format
-  // time,id
-  // time,id
+  // Must be called on the FILE thread.
+  void WriteCompressedLogToFile(const std::vector<uint8>& compressed_log,
+                                const base::FilePath& log_file_path);
+
+  // Append information (upload time, report ID and local ID) about a log to a
+  // log list file, limited to |kLogListLimitLines| entries. This list is used
+  // for viewing the logs under chrome://webrtc-logs, see WebRtcLogUploadList.
+  // The list has the format
+  // upload_time,report_id,local_id
+  // upload_time,report_id,local_id
   // etc.
-  // where each line represents an uploaded log and "time" is Unix time.
+  // where each line represents a log. "upload_time" is the time when the log
+  // was uploaded in Unix time. "report_id" is the ID reported back by the
+  // server. "local_id" is the ID for the locally stored log. It's the time
+  // stored in Unix time and it's also used as file name.
+  // AddLocallyStoredLogInfoToUploadListFile() will first be called,
+  // "upload_time" and "report_id" is the left empty in the entry written to the
+  // list file. If uploading is successful, AddUploadedLogInfoToUploadListFile()
+  // is called and those empty items are filled out.
+  // Must be called on the FILE thread.
+  void AddLocallyStoredLogInfoToUploadListFile(
+      const base::FilePath& upload_list_path,
+      const std::string& local_log_id);
   void AddUploadedLogInfoToUploadListFile(
       const base::FilePath& upload_list_path,
+      const std::string& local_log_id,
       const std::string& report_id);
 
   void NotifyUploadDone(int response_code,
@@ -125,6 +157,8 @@ class WebRtcLogUploader : public net::URLFetcherDelegate {
   // This is the FILE thread for Chromium. Some other thread for tests.
   base::ThreadChecker file_thread_checker_;
 
+  // Keeps track of number of currently open logs. Must be accessed on the UI
+  // thread.
   int log_count_;
 
   // For testing purposes, see OverrideUploadWithBufferForTesting. Only accessed
@@ -136,6 +170,9 @@ class WebRtcLogUploader : public net::URLFetcherDelegate {
   // Only accessed on the UI thread.
   UploadDoneDataMap upload_done_data_;
 
+  // When shutting down, don't create new URLFetchers.
+  bool shutting_down_;
+
   DISALLOW_COPY_AND_ASSIGN(WebRtcLogUploader);
 };