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/extensions/extension_record_api.h" | 5 #include "chrome/browser/extensions/extension_record_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 ProcessStrategy::~ProcessStrategy() {} | 25 ProcessStrategy::~ProcessStrategy() {} |
26 | 26 |
27 void ProductionProcessStrategy::RunProcess(const CommandLine& line) { | 27 void ProductionProcessStrategy::RunProcess(const CommandLine& line) { |
28 base::LaunchOptions options; | 28 base::LaunchOptions options; |
29 | 29 |
30 options.wait = true; | 30 options.wait = true; |
31 base::LaunchProcess(line, options, NULL); | 31 base::LaunchProcess(line, options, NULL); |
32 } | 32 } |
33 | 33 |
34 RunPageCyclerFunction::RunPageCyclerFunction(ProcessStrategy* strategy) | 34 RunPageCyclerFunction::RunPageCyclerFunction(ProcessStrategy* strategy) |
35 : base_command_line_(*CommandLine::ForCurrentProcess()), | 35 : repeat_count_(1), base_command_line_(*CommandLine::ForCurrentProcess()), |
36 process_strategy_(strategy) {} | 36 process_strategy_(strategy) {} |
37 | 37 |
38 RunPageCyclerFunction::~RunPageCyclerFunction() {} | 38 RunPageCyclerFunction::~RunPageCyclerFunction() {} |
39 | 39 |
40 bool RunPageCyclerFunction::RunImpl() { | 40 bool RunPageCyclerFunction::RunImpl() { |
41 if (!ParseJSParameters()) | 41 if (!ParseJSParameters()) |
42 return false; | 42 return false; |
43 | 43 |
44 // If we've had any errors reportable to the JS caller so far (in | 44 // If we've had any errors reportable to the JS caller so far (in |
45 // parameter parsing) then return a list of such errors, else perform | 45 // parameter parsing) then return a list of such errors, else perform |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 remove_switches.push_back(switches::kVisitURLsCount); | 89 remove_switches.push_back(switches::kVisitURLsCount); |
90 remove_switches.push_back(switches::kPlaybackMode); | 90 remove_switches.push_back(switches::kPlaybackMode); |
91 remove_switches.push_back(switches::kRecordStats); | 91 remove_switches.push_back(switches::kRecordStats); |
92 remove_switches.push_back(switches::kLoadExtension); | 92 remove_switches.push_back(switches::kLoadExtension); |
93 | 93 |
94 CommandLine line = RemoveSwitches(base_command_line_, remove_switches); | 94 CommandLine line = RemoveSwitches(base_command_line_, remove_switches); |
95 | 95 |
96 // Add the user-data-dir switch, since this is common to both call types. | 96 // Add the user-data-dir switch, since this is common to both call types. |
97 line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_); | 97 line.AppendSwitchPath(switches::kUserDataDir, user_data_dir_); |
98 | 98 |
99 // Do the same for visit-urls, creating a temp file to communicate the | 99 // Test browsers must run as if they are not in first-run mode |
100 // URL list to the test browser. | 100 line.AppendSwitch(switches::kNoFirstRun); |
| 101 |
| 102 // Create and fill a temp file to communicate the URL list to the test |
| 103 // browser. |
101 FilePath url_path; | 104 FilePath url_path; |
102 file_util::CreateTemporaryFile(&url_path); | 105 file_util::CreateTemporaryFile(&url_path); |
103 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size()); | 106 file_util::WriteFile(url_path, url_contents_.c_str(), url_contents_.size()); |
104 line.AppendSwitchPath(switches::kVisitURLs, url_path); | 107 line.AppendSwitchPath(switches::kVisitURLs, url_path); |
105 | 108 |
106 // Set up Capture- or Replay-specific commandline switches. | 109 // Set up Capture- or Replay-specific commandline switches. |
107 AddSwitches(&line); | 110 AddSwitches(&line); |
108 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString(); | 111 LOG(ERROR) << "Test browser commandline: " << line.GetCommandLineString(); |
109 | 112 |
110 // Run the test browser (or a mockup, depending on |process_strategy_|. | 113 // Run the test browser (or a mockup, depending on |process_strategy_|. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 151 |
149 // Fetch data for possible optional switches for a repeat count and an | 152 // Fetch data for possible optional switches for a repeat count and an |
150 // extension to load. | 153 // extension to load. |
151 bool CaptureURLsFunction::ParseJSParameters() { | 154 bool CaptureURLsFunction::ParseJSParameters() { |
152 scoped_ptr<record::CaptureURLs::Params> params( | 155 scoped_ptr<record::CaptureURLs::Params> params( |
153 record::CaptureURLs::Params::Create(*args_)); | 156 record::CaptureURLs::Params::Create(*args_)); |
154 EXTENSION_FUNCTION_VALIDATE(params.get()); | 157 EXTENSION_FUNCTION_VALIDATE(params.get()); |
155 | 158 |
156 url_contents_ = JoinString(params->urls, '\n'); | 159 url_contents_ = JoinString(params->urls, '\n'); |
157 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); | 160 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); |
| 161 repeat_count_ = params->repeat_count; |
158 | 162 |
159 return true; | 163 return true; |
160 } | 164 } |
161 | 165 |
162 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns | 166 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns |
163 // just the (possibly empty) error list. | 167 // just the (possibly empty) error list. |
164 void CaptureURLsFunction::AddSwitches(CommandLine* line) { | 168 void CaptureURLsFunction::AddSwitches(CommandLine* line) { |
| 169 line->AppendSwitchASCII(switches::kVisitURLsCount, |
| 170 base::Int64ToString(repeat_count_)); |
| 171 |
165 if (!line->HasSwitch(switches::kRecordMode)) | 172 if (!line->HasSwitch(switches::kRecordMode)) |
166 line->AppendSwitch(switches::kRecordMode); | 173 line->AppendSwitch(switches::kRecordMode); |
167 } | 174 } |
168 | 175 |
169 void CaptureURLsFunction::Finish() { | 176 void CaptureURLsFunction::Finish() { |
170 result_.reset(record::CaptureURLs::Result::Create(errors_)); | 177 result_.reset(record::CaptureURLs::Result::Create(errors_)); |
171 SendResponse(true); | 178 SendResponse(true); |
172 } | 179 } |
173 | 180 |
174 | 181 |
175 // ReplayURLsFunction ------------------------------------------------ | 182 // ReplayURLsFunction ------------------------------------------------ |
176 | 183 |
177 ReplayURLsFunction::ReplayURLsFunction() | 184 ReplayURLsFunction::ReplayURLsFunction() |
178 : RunPageCyclerFunction(new ProductionProcessStrategy()), | 185 : RunPageCyclerFunction(new ProductionProcessStrategy()), |
179 repeat_count_(1), run_time_ms_(0) { | 186 run_time_ms_(0) { |
180 } | 187 } |
181 | 188 |
182 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) | 189 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) |
183 : RunPageCyclerFunction(strategy), | 190 : RunPageCyclerFunction(strategy), run_time_ms_(0) { |
184 repeat_count_(1), run_time_ms_(0) { | |
185 } | 191 } |
186 | 192 |
187 ReplayURLsFunction::~ReplayURLsFunction() {} | 193 ReplayURLsFunction::~ReplayURLsFunction() {} |
188 | 194 |
189 // Fetch data for possible optional switches for a repeat count and an | 195 // Fetch data for possible optional switches for a repeat count and an |
190 // extension to load. | 196 // extension to load. |
191 bool ReplayURLsFunction::ParseJSParameters() { | 197 bool ReplayURLsFunction::ParseJSParameters() { |
192 scoped_ptr<record::ReplayURLs::Params> params( | 198 scoped_ptr<record::ReplayURLs::Params> params( |
193 record::ReplayURLs::Params::Create(*args_)); | 199 record::ReplayURLs::Params::Create(*args_)); |
194 EXTENSION_FUNCTION_VALIDATE(params.get()); | 200 EXTENSION_FUNCTION_VALIDATE(params.get()); |
195 | 201 |
196 url_contents_ = JoinString(params->urls, '\n'); | 202 url_contents_ = JoinString(params->urls, '\n'); |
197 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); | 203 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); |
| 204 repeat_count_ = params->repeat_count; |
198 | 205 |
199 if (params->details.get()) { | 206 if (params->details.get()) { |
200 if (params->details->repeat_count.get()) | |
201 repeat_count_ = *params->details->repeat_count; | |
202 if (params->details->extension_path.get()) | 207 if (params->details->extension_path.get()) |
203 extension_path_ = | 208 extension_path_ = |
204 FilePath::FromUTF8Unsafe(*params->details->extension_path); | 209 FilePath::FromUTF8Unsafe(*params->details->extension_path); |
205 } | 210 } |
206 | 211 |
207 return true; | 212 return true; |
208 } | 213 } |
209 | 214 |
210 // Add special switches, if indicated, for repeat count and extension to load, | 215 // Add special switches, if indicated, for repeat count and extension to load, |
211 // plus temp file into which to place stats. (Can't do this in | 216 // plus temp file into which to place stats. (Can't do this in |
(...skipping 23 matching lines...) Expand all Loading... |
235 record::ReplayURLsResult result; | 240 record::ReplayURLsResult result; |
236 | 241 |
237 result.run_time = run_time_ms_; | 242 result.run_time = run_time_ms_; |
238 result.stats = stats_; | 243 result.stats = stats_; |
239 result.errors = errors_; | 244 result.errors = errors_; |
240 | 245 |
241 result_.reset(record::ReplayURLs::Result::Create(result)); | 246 result_.reset(record::ReplayURLs::Result::Create(result)); |
242 SendResponse(true); | 247 SendResponse(true); |
243 } | 248 } |
244 | 249 |
OLD | NEW |