| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/page_cycler/page_cycler.h" | 5 #include "chrome/browser/page_cycler/page_cycler.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" | 
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" | 
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" | 
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 85         FROM_HERE, | 85         FROM_HERE, | 
| 86         base::Bind(&PageCycler::ReadURLsOnBackgroundThread, this)); | 86         base::Bind(&PageCycler::ReadURLsOnBackgroundThread, this)); | 
| 87 } | 87 } | 
| 88 | 88 | 
| 89 void PageCycler::ReadURLsOnBackgroundThread() { | 89 void PageCycler::ReadURLsOnBackgroundThread() { | 
| 90   CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 90   CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 
| 91 | 91 | 
| 92   std::string file_contents; | 92   std::string file_contents; | 
| 93   std::vector<std::string> url_strings; | 93   std::vector<std::string> url_strings; | 
| 94 | 94 | 
| 95   CHECK(file_util::PathExists(urls_file_)) << urls_file_.value(); | 95   CHECK(base::PathExists(urls_file_)) << urls_file_.value(); | 
| 96   file_util::ReadFileToString(urls_file_, &file_contents); | 96   file_util::ReadFileToString(urls_file_, &file_contents); | 
| 97   base::SplitStringAlongWhitespace(file_contents, &url_strings); | 97   base::SplitStringAlongWhitespace(file_contents, &url_strings); | 
| 98 | 98 | 
| 99   if (!url_strings.size()) { | 99   if (!url_strings.size()) { | 
| 100 #if defined(OS_POSIX) | 100 #if defined(OS_POSIX) | 
| 101     error_.append(ASCIIToUTF16("Page Cycler: No URLs in given file: " + | 101     error_.append(ASCIIToUTF16("Page Cycler: No URLs in given file: " + | 
| 102         urls_file_.value())); | 102         urls_file_.value())); | 
| 103 #elif defined(OS_WIN) | 103 #elif defined(OS_WIN) | 
| 104     error_.append(ASCIIToUTF16("Page Cycler: No URLs in given file: ")) | 104     error_.append(ASCIIToUTF16("Page Cycler: No URLs in given file: ")) | 
| 105           .append(urls_file_.value()); | 105           .append(urls_file_.value()); | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 202     output.append("*RESULT times: t_ref= [" + timings_string_ + "] ms\n"); | 202     output.append("*RESULT times: t_ref= [" + timings_string_ + "] ms\n"); | 
| 203   } | 203   } | 
| 204   WriteResultsOnBackgroundThread(output); | 204   WriteResultsOnBackgroundThread(output); | 
| 205 } | 205 } | 
| 206 | 206 | 
| 207 void PageCycler::WriteResultsOnBackgroundThread(const std::string& output) { | 207 void PageCycler::WriteResultsOnBackgroundThread(const std::string& output) { | 
| 208   CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 208   CHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 
| 209 | 209 | 
| 210   if (!output.empty()) { | 210   if (!output.empty()) { | 
| 211     CHECK(!stats_file_.empty()); | 211     CHECK(!stats_file_.empty()); | 
| 212     if (file_util::PathExists(stats_file_)) { | 212     if (base::PathExists(stats_file_)) { | 
| 213       VLOG(1) << "PageCycler: Previous stats file found; appending."; | 213       VLOG(1) << "PageCycler: Previous stats file found; appending."; | 
| 214       file_util::AppendToFile(stats_file_, output.c_str(), output.size()); | 214       file_util::AppendToFile(stats_file_, output.c_str(), output.size()); | 
| 215     } else { | 215     } else { | 
| 216       file_util::WriteFile(stats_file_, output.c_str(), output.size()); | 216       file_util::WriteFile(stats_file_, output.c_str(), output.size()); | 
| 217     } | 217     } | 
| 218   } | 218   } | 
| 219   if (!errors_file_.empty()) { | 219   if (!errors_file_.empty()) { | 
| 220     if (!error_.empty()) { | 220     if (!error_.empty()) { | 
| 221       file_util::WriteFile(errors_file_, UTF16ToUTF8(error_).c_str(), | 221       file_util::WriteFile(errors_file_, UTF16ToUTF8(error_).c_str(), | 
| 222                            error_.size()); | 222                            error_.size()); | 
| 223     } else if (file_util::PathExists(errors_file_)) { | 223     } else if (base::PathExists(errors_file_)) { | 
| 224       // If there is an old error file, delete it to avoid confusion. | 224       // If there is an old error file, delete it to avoid confusion. | 
| 225       base::Delete(errors_file_, false); | 225       base::Delete(errors_file_, false); | 
| 226     } | 226     } | 
| 227   } | 227   } | 
| 228   if (aborted_) { | 228   if (aborted_) { | 
| 229     content::BrowserThread::PostTask(content::BrowserThread::UI, | 229     content::BrowserThread::PostTask(content::BrowserThread::UI, | 
| 230                                      FROM_HERE, | 230                                      FROM_HERE, | 
| 231                                      base::Bind(&PageCycler::Abort, this)); | 231                                      base::Bind(&PageCycler::Abort, this)); | 
| 232   } else { | 232   } else { | 
| 233     content::BrowserThread::PostTask(content::BrowserThread::UI, | 233     content::BrowserThread::PostTask(content::BrowserThread::UI, | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 259     aborted_ = true; | 259     aborted_ = true; | 
| 260     error_.append(ASCIIToUTF16( | 260     error_.append(ASCIIToUTF16( | 
| 261         "Browser was closed before the run was completed.")); | 261         "Browser was closed before the run was completed.")); | 
| 262     DLOG(WARNING) << | 262     DLOG(WARNING) << | 
| 263         "Page Cycler: browser was closed before the run was completed."; | 263         "Page Cycler: browser was closed before the run was completed."; | 
| 264     content::BrowserThread::PostBlockingPoolTask( | 264     content::BrowserThread::PostBlockingPoolTask( | 
| 265         FROM_HERE, | 265         FROM_HERE, | 
| 266         base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); | 266         base::Bind(&PageCycler::PrepareResultsOnBackgroundThread, this)); | 
| 267   } | 267   } | 
| 268 } | 268 } | 
| OLD | NEW | 
|---|