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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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_PAGE_CYCLER_PAGE_CYCLER_H_
6 #define CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
7 #pragma once
8
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_list.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/web_contents_observer.h"
15
16 namespace base {
17 class TimeTicks;
18 } // namespace base
19
20 // Performance test to track the resources used and speed with which chromium
21 // fully loads a given set of URLs. This class is created on the UI thread and
22 // does most of its work there. However, some work happens on background threads
23 // too; those are named with 'OnBackgroundThread'.
24 class PageCycler : public base::RefCountedThreadSafe<PageCycler>,
25 public BrowserList::Observer,
26 public content::WebContentsObserver {
27 public:
28 // Called when statistics are not being recorded; typically this means that
29 // the user did not use the record-stats switch in the commandline.
30 PageCycler(Browser* browser, FilePath urls_file, FilePath errors_file);
31
32 // Called when statistics gathering is important, and will be written to file.
33 PageCycler(Browser* browser,
34 FilePath urls_file,
35 FilePath errors_file,
Aaron Boodman 2012/03/20 19:28:16 Consider just making these setters that the caller
36 FilePath stats_file);
37
38 // 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
39 // thread.
40 void Run(unsigned int iterations);
41
42 // content::WebContentsObserver
43 virtual void DidFinishLoad(int64 frame_id,
44 const GURL& validated_url,
45 bool is_main_frame) OVERRIDE;
46 virtual void DidFailProvisionalLoad(
47 int64 frame_id,
48 bool is_main_frame,
49 const GURL& validated_url,
50 int error_code,
51 const string16& error_description) OVERRIDE;
52
53 // This method should never be necessary while running PageCycler; this is
54 // for testing purposes only.
55 const std::vector<GURL>* urls() { return &urls_; }
chebert 2012/04/09 23:52:01 I've seen functions that call testing functions wi
56
57 private:
58 friend class base::RefCountedThreadSafe<PageCycler>;
59 ~PageCycler();
60
61 // Initialize the PageCyclerNavigationObserver; add a reference.
62 void Init();
63
64 // Read in the urls from |urls_file_| and store them in |urls_|. Upon finish,
65 // switch thread back to the UI thread and call BeginCycle.
66 void ReadURLsOnBackgroundThread();
67
68 // Perform any initial setup neccessary, and begin visiting the pages.
69 void BeginCycle();
70
71 // If |url_index_| points to a valid position in |urls_|, load the url,
72 // capturing any statistics information. Otherwise, call WriteResults.
73 void LoadNextURL();
74
75 // Complete statistics gathering for the finished visit, and try to load the
76 // next url.
77 void LoadSucceeded();
78
79 // Inidicate that the load failed with an error; try to load the next url.
80 void LoadFailed(const GURL& url, const string16& error_description);
81
82 // Finalize the ouput strings, and post a task on the IO thread for
83 // WriteResultsToFile().
84 void PrepareResults();
85
86 // Write the data stored within output to the file indicated by |stats_file_|,
87 // if |stats_file_| is not empty. Write any errors to |errors_file_|. Switch
88 // thread back to the UI thread, and Finish().
89 void WriteResultsOnBackgroundThread(std::string output);
90
91 // Perform any necessary cleanup, release the reference, and exit |browser_|.
92 void Finish();
93
94 // Called when the Browser to which |browser_| points is closed; exits
95 // PageCycler.
96 void Abort();
97
98 // BrowserList::Observer
99 virtual void OnBrowserAdded(const Browser* browser) OVERRIDE;
100 virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE;
101
102 // The Browser context in which the page cycler is running.
103 Browser* browser_;
104
105 // The path to the file containing the list of urls to visit.
106 FilePath urls_file_;
107
108 // The path to the file to which we write any errors encountered.
109 FilePath errors_file_;
110
111 // The path to the file to which we write the statistics (optional, may be
112 // an empty path).
113 FilePath stats_file_;
114
115 // The list of urls to visit.
116 std::vector<GURL> urls_;
117
118 // The current index into the |urls_| vector.
119 size_t url_index_;
120
121 // The current number of iterations remaining.
122 unsigned int iterations_;
123
124 // The generated string of urls which we have visited; this is built one url
125 // at a time as we iterate through the |urls_| vector. This is primarily
126 // included for interfacing with the previous page_cycler's output style.
127 std::string urls_string_;
128
129 // The generated string of the times taken to visit each url. As with
130 // |urls_string_|, this is built as we visit each url, and is primarily to
131 // produce output similar to the previous page_cycler's.
132 std::string timings_string_;
133
134 // The time at which we begin the process of loading the next url; this is
135 // used to calculate the time taken for each url load.
136 base::TimeTicks initial_time_;
137
138 string16 error_;
139
140
141 DISALLOW_COPY_AND_ASSIGN(PageCycler);
142 };
143
144 #endif // CHROME_BROWSER_PAGE_CYCLER_PAGE_CYCLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698