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/api/record/record_api.h" | 5 #include "chrome/browser/extensions/api/record/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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) | 160 CaptureURLsFunction::CaptureURLsFunction(ProcessStrategy* strategy) |
161 : RunPageCyclerFunction(strategy) {} | 161 : RunPageCyclerFunction(strategy) {} |
162 | 162 |
163 // Fetch data for possible optional switch for an extension to load. | 163 // Fetch data for possible optional switch for an extension to load. |
164 bool CaptureURLsFunction::ParseJSParameters() { | 164 bool CaptureURLsFunction::ParseJSParameters() { |
165 scoped_ptr<record::CaptureURLs::Params> params( | 165 scoped_ptr<record::CaptureURLs::Params> params( |
166 record::CaptureURLs::Params::Create(*args_)); | 166 record::CaptureURLs::Params::Create(*args_)); |
167 EXTENSION_FUNCTION_VALIDATE(params.get()); | 167 EXTENSION_FUNCTION_VALIDATE(params.get()); |
168 | 168 |
169 url_contents_ = JoinString(params->urls, '\n'); | 169 url_contents_ = JoinString(params->urls, '\n'); |
170 user_data_dir_ = FilePath::FromUTF8Unsafe(params->cache_directory_path); | 170 // TODO(cstaley): Can't just use captureName -- gotta stick it in a temp dir. |
171 // TODO(cstaley): Ensure that capture name is suitable as directory name. | |
172 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | |
171 | 173 |
172 return true; | 174 return true; |
173 } | 175 } |
174 | 176 |
175 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns | 177 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns |
176 // just the (possibly empty) error list. | 178 // just the (possibly empty) error list. |
177 void CaptureURLsFunction::AddSwitches(CommandLine* line) { | 179 void CaptureURLsFunction::AddSwitches(CommandLine* line) { |
178 if (!line->HasSwitch(switches::kRecordMode)) | 180 if (!line->HasSwitch(switches::kRecordMode)) |
179 line->AppendSwitch(switches::kRecordMode); | 181 line->AppendSwitch(switches::kRecordMode); |
180 } | 182 } |
181 | 183 |
182 void CaptureURLsFunction::Finish() { | 184 void CaptureURLsFunction::Finish() { |
183 results_ = record::CaptureURLs::Results::Create(errors_); | 185 results_ = record::CaptureURLs::Results::Create(errors_); |
184 SendResponse(true); | 186 SendResponse(true); |
185 } | 187 } |
186 | 188 |
187 | |
188 // ReplayURLsFunction ------------------------------------------------ | 189 // ReplayURLsFunction ------------------------------------------------ |
189 | 190 |
190 ReplayURLsFunction::ReplayURLsFunction() | 191 ReplayURLsFunction::ReplayURLsFunction() |
191 : RunPageCyclerFunction(new ProductionProcessStrategy()), | 192 : RunPageCyclerFunction(new ProductionProcessStrategy()), |
192 run_time_ms_(0) { | 193 run_time_ms_(0) { |
193 } | 194 } |
194 | 195 |
195 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) | 196 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) |
196 : RunPageCyclerFunction(strategy), run_time_ms_(0) { | 197 : RunPageCyclerFunction(strategy), run_time_ms_(0) { |
197 } | 198 } |
198 | 199 |
199 ReplayURLsFunction::~ReplayURLsFunction() {} | 200 ReplayURLsFunction::~ReplayURLsFunction() {} |
200 | 201 |
201 // Fetch data for possible optional switches for a repeat count and an | 202 // Fetch data for possible optional switches for a repeat count and an |
202 // extension to load. | 203 // extension to load. |
203 bool ReplayURLsFunction::ParseJSParameters() { | 204 bool ReplayURLsFunction::ParseJSParameters() { |
204 scoped_ptr<record::ReplayURLs::Params> params( | 205 scoped_ptr<record::ReplayURLs::Params> params( |
205 record::ReplayURLs::Params::Create(*args_)); | 206 record::ReplayURLs::Params::Create(*args_)); |
206 EXTENSION_FUNCTION_VALIDATE(params.get()); | 207 EXTENSION_FUNCTION_VALIDATE(params.get()); |
207 | 208 |
208 url_contents_ = JoinString(params->urls, '\n'); | 209 |
209 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_directory_path); | 210 // TODO(cstaley): Must build full temp dir from capture_name |
211 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | |
212 | |
213 // TODO(cstaley): Get this from user data dir ultimately | |
214 url_contents_ = "http://www.google.com\nhttp://www.amazon.com\n"; | |
215 | |
210 repeat_count_ = params->repeat_count; | 216 repeat_count_ = params->repeat_count; |
211 | 217 |
212 if (params->details.get()) { | 218 if (params->details.get()) { |
213 if (params->details->extension_path.get()) | 219 if (params->details->extension_path.get()) |
214 extension_path_ = | 220 extension_path_ = |
215 FilePath::FromUTF8Unsafe(*params->details->extension_path); | 221 FilePath::FromUTF8Unsafe(*params->details->extension_path); |
216 } | 222 } |
217 | 223 |
218 return true; | 224 return true; |
219 } | 225 } |
(...skipping 10 matching lines...) Expand all Loading... | |
230 line->AppendSwitch(switches::kPlaybackMode); | 236 line->AppendSwitch(switches::kPlaybackMode); |
231 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); | 237 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); |
232 | 238 |
233 timer_ = base::Time::NowFromSystemTime(); | 239 timer_ = base::Time::NowFromSystemTime(); |
234 } | 240 } |
235 | 241 |
236 // Read stats file, and get run time. | 242 // Read stats file, and get run time. |
237 void ReplayURLsFunction::ReadReplyFiles() { | 243 void ReplayURLsFunction::ReadReplyFiles() { |
238 file_util::ReadFileToString(stats_file_path_, &stats_); | 244 file_util::ReadFileToString(stats_file_path_, &stats_); |
239 | 245 |
240 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMilliseconds(); | 246 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMilliseconds(); |
Jeffrey Yasskin
2012/08/17 19:32:14
Switch this to InMillisecondsF and change run_time
clintstaley
2012/08/20 23:17:06
Done.
| |
241 } | 247 } |
242 | 248 |
243 void ReplayURLsFunction::Finish() { | 249 void ReplayURLsFunction::Finish() { |
244 record::ReplayURLsResult result; | 250 results_ = record::ReplayURLs::Results::Create((double)run_time_ms_, stats_, |
Jeffrey Yasskin
2012/08/17 19:32:14
In C++, ints implicitly convert to doubles, so you
clintstaley
2012/08/20 23:17:06
Done.
| |
245 | 251 errors_); |
246 result.run_time = run_time_ms_; | |
247 result.stats = stats_; | |
248 result.errors = errors_; | |
249 | |
250 results_ = record::ReplayURLs::Results::Create(result); | |
251 SendResponse(true); | 252 SendResponse(true); |
252 } | 253 } |
253 | 254 |
254 } // namespace extensions | 255 } // namespace extensions |
OLD | NEW |