Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / feedback / feedback_uploader.cc
index 36d5620..75b3a6a 100644 (file)
@@ -9,6 +9,7 @@
 #include "base/files/file_path.h"
 #include "base/task_runner_util.h"
 #include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/feedback/feedback_report.h"
 #include "chrome/common/chrome_switches.h"
 #include "content/public/browser/browser_context.h"
 #include "content/public/browser/browser_thread.h"
@@ -29,28 +30,9 @@ const int64 kRetryDelayMinutes = 60;
 
 }  // namespace
 
-struct FeedbackReport {
-  FeedbackReport(const base::Time& upload_at, scoped_ptr<std::string> data)
-      : upload_at(upload_at), data(data.Pass()) {}
-
-  FeedbackReport(const FeedbackReport& report) {
-    upload_at = report.upload_at;
-    data = report.data.Pass();
-  }
-
-  FeedbackReport& operator=(const FeedbackReport& report) {
-    upload_at = report.upload_at;
-    data = report.data.Pass();
-    return *this;
-  }
-
-  base::Time upload_at;  // Upload this report at or after this time.
-  mutable scoped_ptr<std::string> data;
-};
-
 bool FeedbackUploader::ReportsUploadTimeComparator::operator()(
-    const FeedbackReport& a, const FeedbackReport& b) const {
-  return a.upload_at > b.upload_at;
+    FeedbackReport* a, FeedbackReport* b) const {
+  return a->upload_at() > b->upload_at();
 }
 
 FeedbackUploader::FeedbackUploader(content::BrowserContext* context)
@@ -61,15 +43,15 @@ FeedbackUploader::FeedbackUploader(content::BrowserContext* context)
                                   AsWeakPtr());
 }
 
-FeedbackUploader::~FeedbackUploader() {
-}
+FeedbackUploader::~FeedbackUploader() {}
 
-void FeedbackUploader::QueueReport(scoped_ptr<std::string> data) {
-  reports_queue_.push(FeedbackReport(base::Time::Now(), data.Pass()));
+void FeedbackUploader::QueueReport(const std::string& data) {
+  reports_queue_.push(
+      new FeedbackReport(context_, base::Time::Now(), data));
   UpdateUploadTimer();
 }
 
-void FeedbackUploader::DispatchReport(scoped_ptr<std::string> data) {
+void FeedbackUploader::DispatchReport(const std::string& data) {
   GURL post_url;
   if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFeedbackServer))
     post_url = GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
@@ -77,17 +59,14 @@ void FeedbackUploader::DispatchReport(scoped_ptr<std::string> data) {
   else
     post_url = GURL(kFeedbackPostUrl);
 
-  // Save the report data pointer since the report.Pass() in the next statement
-  // will invalidate the scoper.
-  std::string* data_ptr = data.get();
   net::URLFetcher* fetcher = net::URLFetcher::Create(
       post_url, net::URLFetcher::POST,
       new FeedbackUploaderDelegate(
-          data.Pass(),
+          data,
           base::Bind(&FeedbackUploader::UpdateUploadTimer, AsWeakPtr()),
           base::Bind(&FeedbackUploader::RetryReport, AsWeakPtr())));
 
-  fetcher->SetUploadData(std::string(kProtBufMimeType), *data_ptr);
+  fetcher->SetUploadData(std::string(kProtBufMimeType), data);
   fetcher->SetRequestContext(context_->GetRequestContext());
   fetcher->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
                         net::LOAD_DO_NOT_SEND_COOKIES);
@@ -98,25 +77,26 @@ void FeedbackUploader::UpdateUploadTimer() {
   if (reports_queue_.empty())
     return;
 
-  const FeedbackReport& report = reports_queue_.top();
+  scoped_refptr<FeedbackReport> report = reports_queue_.top();
   base::Time now = base::Time::Now();
-  if (report.upload_at <= now) {
-    scoped_ptr<std::string> data = report.data.Pass();
+  if (report->upload_at() <= now) {
     reports_queue_.pop();
-    dispatch_callback_.Run(data.Pass());
+    dispatch_callback_.Run(report->data());
+    report->DeleteReportOnDisk();
   } else {
     // Stop the old timer and start an updated one.
     if (upload_timer_.IsRunning())
       upload_timer_.Stop();
     upload_timer_.Start(
-        FROM_HERE, report.upload_at - now, this,
+        FROM_HERE, report->upload_at() - now, this,
         &FeedbackUploader::UpdateUploadTimer);
   }
 }
 
-void FeedbackUploader::RetryReport(scoped_ptr<std::string> data) {
-  reports_queue_.push(
-      FeedbackReport(base::Time::Now() + retry_delay_, data.Pass()));
+void FeedbackUploader::RetryReport(const std::string& data) {
+  reports_queue_.push(new FeedbackReport(context_,
+                                         base::Time::Now() + retry_delay_,
+                                         data));
   UpdateUploadTimer();
 }