Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4581)

Unified Diff: chrome/browser/page_cycler/page_cycler.h

Issue 9667009: CommandLine Page Cycler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: PageCycler CommandLine Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/page_cycler/page_cycler.h
diff --git a/chrome/browser/page_cycler/page_cycler.h b/chrome/browser/page_cycler/page_cycler.h
new file mode 100644
index 0000000000000000000000000000000000000000..349c0557363b8bc64692ae962610fcaf756464f7
--- /dev/null
+++ b/chrome/browser/page_cycler/page_cycler.h
@@ -0,0 +1,144 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
+#define CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
+#pragma once
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/web_contents_observer.h"
+
+namespace base {
+class TimeTicks;
+} // namespace base
+
+// Performance test to track the resources used and speed with which chromium
+// fully loads a given set of URLs. This class is created on the UI thread and
+// does most of its work there. However, some work happens on background threads
+// too; those are named with 'OnBackgroundThread'.
+class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
+ public BrowserList::Observer,
+ public content::WebContentsObserver {
+ public:
+ // Called when statistics are not being recorded; typically this means that
+ // the user did not use the record-stats switch in the commandline.
+ PageCycler(Browser* browser, FilePath urls_file, FilePath errors_file);
+
+ // Called when statistics gathering is important, and will be written to file.
+ PageCycler(Browser* browser,
+ FilePath urls_file,
+ FilePath errors_file,
Aaron Boodman 2012/03/20 19:28:16 Consider just making these setters that the caller
+ FilePath stats_file);
+
+ // Begin running the page cycler; post the ReadURLsFromFile task on the IO
Aaron Boodman 2012/03/20 19:28:16 Avoid duplicating implementation (such as post the
+ // thread.
+ void Run(unsigned int iterations);
+
+ // content::WebContentsObserver
+ virtual void DidFinishLoad(int64 frame_id,
+ const GURL& validated_url,
+ bool is_main_frame) OVERRIDE;
+ virtual void DidFailProvisionalLoad(
+ int64 frame_id,
+ bool is_main_frame,
+ const GURL& validated_url,
+ int error_code,
+ const string16& error_description) OVERRIDE;
+
+ // This method should never be necessary while running PageCycler; this is
+ // for testing purposes only.
+ const std::vector<GURL>* urls() { return &urls_; }
chebert 2012/04/09 23:52:01 I've seen functions that call testing functions wi
+
+ private:
+ friend class base::RefCountedThreadSafe<PageCycler>;
+ ~PageCycler();
+
+ // Initialize the PageCyclerNavigationObserver; add a reference.
+ void Init();
+
+ // Read in the urls from |urls_file_| and store them in |urls_|. Upon finish,
+ // switch thread back to the UI thread and call BeginCycle.
+ void ReadURLsOnBackgroundThread();
+
+ // Perform any initial setup neccessary, and begin visiting the pages.
+ void BeginCycle();
+
+ // If |url_index_| points to a valid position in |urls_|, load the url,
+ // capturing any statistics information. Otherwise, call WriteResults.
+ void LoadNextURL();
+
+ // Complete statistics gathering for the finished visit, and try to load the
+ // next url.
+ void LoadSucceeded();
+
+ // Inidicate that the load failed with an error; try to load the next url.
+ void LoadFailed(const GURL& url, const string16& error_description);
+
+ // Finalize the ouput strings, and post a task on the IO thread for
+ // WriteResultsToFile().
+ void PrepareResults();
+
+ // Write the data stored within output to the file indicated by |stats_file_|,
+ // if |stats_file_| is not empty. Write any errors to |errors_file_|. Switch
+ // thread back to the UI thread, and Finish().
+ void WriteResultsOnBackgroundThread(std::string output);
+
+ // Perform any necessary cleanup, release the reference, and exit |browser_|.
+ void Finish();
+
+ // Called when the Browser to which |browser_| points is closed; exits
+ // PageCycler.
+ void Abort();
+
+ // BrowserList::Observer
+ virtual void OnBrowserAdded(const Browser* browser) OVERRIDE;
+ virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE;
+
+ // The Browser context in which the page cycler is running.
+ Browser* browser_;
+
+ // The path to the file containing the list of urls to visit.
+ FilePath urls_file_;
+
+ // The path to the file to which we write any errors encountered.
+ FilePath errors_file_;
+
+ // The path to the file to which we write the statistics (optional, may be
+ // an empty path).
+ FilePath stats_file_;
+
+ // The list of urls to visit.
+ std::vector<GURL> urls_;
+
+ // The current index into the |urls_| vector.
+ size_t url_index_;
+
+ // The current number of iterations remaining.
+ unsigned int iterations_;
+
+ // The generated string of urls which we have visited; this is built one url
+ // at a time as we iterate through the |urls_| vector. This is primarily
+ // included for interfacing with the previous page_cycler's output style.
+ std::string urls_string_;
+
+ // The generated string of the times taken to visit each url. As with
+ // |urls_string_|, this is built as we visit each url, and is primarily to
+ // produce output similar to the previous page_cycler's.
+ std::string timings_string_;
+
+ // The time at which we begin the process of loading the next url; this is
+ // used to calculate the time taken for each url load.
+ base::TimeTicks initial_time_;
+
+ string16 error_;
+
+
+ DISALLOW_COPY_AND_ASSIGN(PageCycler);
+};
+
+#endif // CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_

Powered by Google App Engine
This is Rietveld 408576698