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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/extensions/extension_function.h" | 9 #include "chrome/browser/extensions/extension_function.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 public: | 44 public: |
45 virtual void RunProcess(const CommandLine& line) OVERRIDE; | 45 virtual void RunProcess(const CommandLine& line) OVERRIDE; |
46 }; | 46 }; |
47 | 47 |
48 // Both page cycler calls (capture and replay) have a great deal in common, | 48 // Both page cycler calls (capture and replay) have a great deal in common, |
49 // including the need to build and write a url list file, set the user | 49 // including the need to build and write a url list file, set the user |
50 // data dir, start a sub-instance of Chrome, and parse a resultant error | 50 // data dir, start a sub-instance of Chrome, and parse a resultant error |
51 // file. This base class encapslates those common elements. | 51 // file. This base class encapslates those common elements. |
52 class RunPageCyclerFunction : public AsyncExtensionFunction { | 52 class RunPageCyclerFunction : public AsyncExtensionFunction { |
53 public: | 53 public: |
54 | |
55 explicit RunPageCyclerFunction(ProcessStrategy* strategy); | 54 explicit RunPageCyclerFunction(ProcessStrategy* strategy); |
56 virtual ~RunPageCyclerFunction(); | |
57 | |
58 // Gather common page cycler parameters and store them, then do blocking | |
59 // thread invocation of RunTestBrowser. | |
60 virtual bool RunImpl() OVERRIDE; | |
61 | 55 |
62 // Make a CommandLine copy of |original|, removing all switches in | 56 // Make a CommandLine copy of |original|, removing all switches in |
63 // |to_remove|. | 57 // |to_remove|. |
64 static CommandLine RemoveSwitches(const CommandLine& original, | 58 static CommandLine RemoveSwitches(const CommandLine& original, |
65 const std::vector<std::string>& to_remove); | 59 const std::vector<std::string>& to_remove); |
66 | 60 |
67 // Return ProcessStrategy, to allow for test versions. | 61 // Return ProcessStrategy, to allow for test versions. |
68 virtual const ProcessStrategy &GetProcessStrategy(); | 62 virtual const ProcessStrategy &GetProcessStrategy(); |
69 | 63 |
70 protected: | 64 protected: |
| 65 virtual ~RunPageCyclerFunction(); |
| 66 |
| 67 // Gather common page cycler parameters and store them, then do blocking |
| 68 // thread invocation of RunTestBrowser. |
| 69 virtual bool RunImpl() OVERRIDE; |
| 70 |
71 // Parse the JS parameters, and store them as member data. | 71 // Parse the JS parameters, and store them as member data. |
72 virtual bool ParseJSParameters() = 0; | 72 virtual bool ParseJSParameters() = 0; |
73 | 73 |
74 // Do a vanilla test browser run, bracketing it immediately before and | 74 // Do a vanilla test browser run, bracketing it immediately before and |
75 // after with a call of AddSwitches to add special commandline options | 75 // after with a call of AddSwitches to add special commandline options |
76 // for Capture or Replay, and ReadReplyFiles to do any special post-run | 76 // for Capture or Replay, and ReadReplyFiles to do any special post-run |
77 // data collection. Gather any error results into |errors_| and then do a | 77 // data collection. Gather any error results into |errors_| and then do a |
78 // BrowserThread call of Finish to return JS values. | 78 // BrowserThread call of Finish to return JS values. |
79 virtual void RunTestBrowser(); | 79 virtual void RunTestBrowser(); |
80 virtual void AddSwitches(CommandLine* command_line) {} | 80 virtual void AddSwitches(CommandLine* command_line) {} |
(...skipping 13 matching lines...) Expand all Loading... |
94 | 94 |
95 // Base CommandLine on which to build the test browser CommandLine | 95 // Base CommandLine on which to build the test browser CommandLine |
96 CommandLine base_command_line_; | 96 CommandLine base_command_line_; |
97 | 97 |
98 // ProcessStrategy to use for this run. | 98 // ProcessStrategy to use for this run. |
99 scoped_ptr<ProcessStrategy> process_strategy_; | 99 scoped_ptr<ProcessStrategy> process_strategy_; |
100 }; | 100 }; |
101 | 101 |
102 class CaptureURLsFunction : public RunPageCyclerFunction { | 102 class CaptureURLsFunction : public RunPageCyclerFunction { |
103 public: | 103 public: |
| 104 DECLARE_EXTENSION_FUNCTION_NAME("experimental.record.captureURLs"); |
| 105 |
104 CaptureURLsFunction(); | 106 CaptureURLsFunction(); |
105 explicit CaptureURLsFunction(ProcessStrategy* strategy); | 107 explicit CaptureURLsFunction(ProcessStrategy* strategy); |
106 | 108 |
107 private: | 109 private: |
108 virtual ~CaptureURLsFunction() {} | 110 virtual ~CaptureURLsFunction() {} |
109 | 111 |
110 // Read the ReplayDetails parameter if it exists. | 112 // Read the ReplayDetails parameter if it exists. |
111 virtual bool ParseJSParameters() OVERRIDE; | 113 virtual bool ParseJSParameters() OVERRIDE; |
112 | 114 |
113 // Add record-mode. | 115 // Add record-mode. |
114 virtual void AddSwitches(CommandLine* command_line) OVERRIDE; | 116 virtual void AddSwitches(CommandLine* command_line) OVERRIDE; |
115 | 117 |
116 // Return error list. | 118 // Return error list. |
117 virtual void Finish() OVERRIDE; | 119 virtual void Finish() OVERRIDE; |
118 | |
119 DECLARE_EXTENSION_FUNCTION_NAME("experimental.record.captureURLs"); | |
120 }; | 120 }; |
121 | 121 |
122 class ReplayURLsFunction : public RunPageCyclerFunction { | 122 class ReplayURLsFunction : public RunPageCyclerFunction { |
123 public: | 123 public: |
| 124 DECLARE_EXTENSION_FUNCTION_NAME("experimental.record.replayURLs"); |
| 125 |
124 ReplayURLsFunction(); | 126 ReplayURLsFunction(); |
125 explicit ReplayURLsFunction(ProcessStrategy* strategy); | 127 explicit ReplayURLsFunction(ProcessStrategy* strategy); |
126 | 128 |
127 private: | 129 private: |
128 virtual ~ReplayURLsFunction(); | 130 virtual ~ReplayURLsFunction(); |
129 | 131 |
130 // Read the ReplayDetails parameter if it exists. | 132 // Read the ReplayDetails parameter if it exists. |
131 virtual bool ParseJSParameters() OVERRIDE; | 133 virtual bool ParseJSParameters() OVERRIDE; |
132 | 134 |
133 // Add visit-urls-count and load-extension. | 135 // Add visit-urls-count and load-extension. |
134 virtual void AddSwitches(CommandLine* command_line) OVERRIDE; | 136 virtual void AddSwitches(CommandLine* command_line) OVERRIDE; |
135 | 137 |
136 // Read stats file. | 138 // Read stats file. |
137 virtual void ReadReplyFiles() OVERRIDE; | 139 virtual void ReadReplyFiles() OVERRIDE; |
138 | 140 |
139 // Return error list, statistical results, and runtime. | 141 // Return error list, statistical results, and runtime. |
140 virtual void Finish() OVERRIDE; | 142 virtual void Finish() OVERRIDE; |
141 | 143 |
142 DECLARE_EXTENSION_FUNCTION_NAME("experimental.record.replayURLs"); | |
143 | |
144 // These three data are additional information added to the sub-browser | 144 // These three data are additional information added to the sub-browser |
145 // commandline. | 145 // commandline. |
146 int repeat_count_; | 146 int repeat_count_; |
147 FilePath extension_path_; | 147 FilePath extension_path_; |
148 FilePath stats_file_path_; | 148 FilePath stats_file_path_; |
149 | 149 |
150 // This time datum marks the start and end of the sub-browser run. | 150 // This time datum marks the start and end of the sub-browser run. |
151 base::Time timer_; | 151 base::Time timer_; |
152 | 152 |
153 // These two data are additional information returned to caller. | 153 // These two data are additional information returned to caller. |
154 int run_time_ms_; | 154 int run_time_ms_; |
155 std::string stats_; | 155 std::string stats_; |
156 }; | 156 }; |
157 | 157 |
158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ | 158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_RECORD_API_H_ |
OLD | NEW |