| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 // Back to UI thread to finish up the JS call. | 146 // Back to UI thread to finish up the JS call. |
| 147 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 147 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 148 base::Bind(&RunPageCyclerFunction::Finish, this)); | 148 base::Bind(&RunPageCyclerFunction::Finish, this)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 const ProcessStrategy &RunPageCyclerFunction::GetProcessStrategy() { | 151 const ProcessStrategy &RunPageCyclerFunction::GetProcessStrategy() { |
| 152 return *process_strategy_; | 152 return *process_strategy_; |
| 153 } | 153 } |
| 154 | 154 |
| 155 // RecordCaptureURLsFunction ------------------------------------------------ | 155 // CaptureURLsFunction ------------------------------------------------ |
| 156 | 156 |
| 157 RecordCaptureURLsFunction::RecordCaptureURLsFunction() | 157 CaptureURLsFunction::CaptureURLsFunction() |
| 158 : RunPageCyclerFunction(new ProductionProcessStrategy()) {} | 158 : RunPageCyclerFunction(new ProductionProcessStrategy()) {} |
| 159 | 159 |
| 160 RecordCaptureURLsFunction::RecordCaptureURLsFunction(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 RecordCaptureURLsFunction::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 // TODO(cstaley): Can't just use captureName -- gotta stick it in a temp dir. | 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. | 171 // TODO(cstaley): Ensure that capture name is suitable as directory name. |
| 172 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | 172 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); |
| 173 | 173 |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // RecordCaptureURLsFunction adds "record-mode" to sub-browser call, and returns | 177 // CaptureURLsFunction adds "record-mode" to sub-browser call, and returns |
| 178 // just the (possibly empty) error list. | 178 // just the (possibly empty) error list. |
| 179 void RecordCaptureURLsFunction::AddSwitches(CommandLine* line) { | 179 void CaptureURLsFunction::AddSwitches(CommandLine* line) { |
| 180 if (!line->HasSwitch(switches::kRecordMode)) | 180 if (!line->HasSwitch(switches::kRecordMode)) |
| 181 line->AppendSwitch(switches::kRecordMode); | 181 line->AppendSwitch(switches::kRecordMode); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void RecordCaptureURLsFunction::Finish() { | 184 void CaptureURLsFunction::Finish() { |
| 185 results_ = record::CaptureURLs::Results::Create(errors_); | 185 results_ = record::CaptureURLs::Results::Create(errors_); |
| 186 SendResponse(true); | 186 SendResponse(true); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // RecordReplayURLsFunction ------------------------------------------------ | 189 // ReplayURLsFunction ------------------------------------------------ |
| 190 | 190 |
| 191 RecordReplayURLsFunction::RecordReplayURLsFunction() | 191 ReplayURLsFunction::ReplayURLsFunction() |
| 192 : RunPageCyclerFunction(new ProductionProcessStrategy()), | 192 : RunPageCyclerFunction(new ProductionProcessStrategy()), |
| 193 run_time_ms_(0.0) { | 193 run_time_ms_(0.0) { |
| 194 } | 194 } |
| 195 | 195 |
| 196 RecordReplayURLsFunction::RecordReplayURLsFunction(ProcessStrategy* strategy) | 196 ReplayURLsFunction::ReplayURLsFunction(ProcessStrategy* strategy) |
| 197 : RunPageCyclerFunction(strategy), run_time_ms_(0.0) { | 197 : RunPageCyclerFunction(strategy), run_time_ms_(0.0) { |
| 198 } | 198 } |
| 199 | 199 |
| 200 RecordReplayURLsFunction::~RecordReplayURLsFunction() {} | 200 ReplayURLsFunction::~ReplayURLsFunction() {} |
| 201 | 201 |
| 202 // 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 |
| 203 // extension to load. | 203 // extension to load. |
| 204 bool RecordReplayURLsFunction::ParseJSParameters() { | 204 bool ReplayURLsFunction::ParseJSParameters() { |
| 205 scoped_ptr<record::ReplayURLs::Params> params( | 205 scoped_ptr<record::ReplayURLs::Params> params( |
| 206 record::ReplayURLs::Params::Create(*args_)); | 206 record::ReplayURLs::Params::Create(*args_)); |
| 207 EXTENSION_FUNCTION_VALIDATE(params.get()); | 207 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 208 | 208 |
| 209 | 209 |
| 210 // TODO(cstaley): Must build full temp dir from capture_name | 210 // TODO(cstaley): Must build full temp dir from capture_name |
| 211 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); | 211 user_data_dir_ = FilePath::FromUTF8Unsafe(params->capture_name); |
| 212 | 212 |
| 213 // TODO(cstaley): Get this from user data dir ultimately | 213 // TODO(cstaley): Get this from user data dir ultimately |
| 214 url_contents_ = "http://www.google.com\nhttp://www.amazon.com"; | 214 url_contents_ = "http://www.google.com\nhttp://www.amazon.com"; |
| 215 | 215 |
| 216 repeat_count_ = params->repeat_count; | 216 repeat_count_ = params->repeat_count; |
| 217 | 217 |
| 218 if (params->details.get()) { | 218 if (params->details.get()) { |
| 219 if (params->details->extension_path.get()) | 219 if (params->details->extension_path.get()) |
| 220 extension_path_ = | 220 extension_path_ = |
| 221 FilePath::FromUTF8Unsafe(*params->details->extension_path); | 221 FilePath::FromUTF8Unsafe(*params->details->extension_path); |
| 222 } | 222 } |
| 223 | 223 |
| 224 return true; | 224 return true; |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Add special switches, if indicated, for repeat count and extension to load, | 227 // Add special switches, if indicated, for repeat count and extension to load, |
| 228 // plus temp file into which to place stats. (Can't do this in | 228 // plus temp file into which to place stats. (Can't do this in |
| 229 // ParseJSParameters because file creation can't go on the UI thread.) | 229 // ParseJSParameters because file creation can't go on the UI thread.) |
| 230 // Plus, initialize time to create run time statistic. | 230 // Plus, initialize time to create run time statistic. |
| 231 void RecordReplayURLsFunction::AddSwitches(CommandLine* line) { | 231 void ReplayURLsFunction::AddSwitches(CommandLine* line) { |
| 232 file_util::CreateTemporaryFile(&stats_file_path_); | 232 file_util::CreateTemporaryFile(&stats_file_path_); |
| 233 | 233 |
| 234 if (!extension_path_.empty()) | 234 if (!extension_path_.empty()) |
| 235 line->AppendSwitchPath(switches::kLoadExtension, extension_path_); | 235 line->AppendSwitchPath(switches::kLoadExtension, extension_path_); |
| 236 line->AppendSwitch(switches::kPlaybackMode); | 236 line->AppendSwitch(switches::kPlaybackMode); |
| 237 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); | 237 line->AppendSwitchPath(switches::kRecordStats, stats_file_path_); |
| 238 | 238 |
| 239 timer_ = base::Time::NowFromSystemTime(); | 239 timer_ = base::Time::NowFromSystemTime(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Read stats file, and get run time. | 242 // Read stats file, and get run time. |
| 243 void RecordReplayURLsFunction::ReadReplyFiles() { | 243 void ReplayURLsFunction::ReadReplyFiles() { |
| 244 file_util::ReadFileToString(stats_file_path_, &stats_); | 244 file_util::ReadFileToString(stats_file_path_, &stats_); |
| 245 | 245 |
| 246 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMillisecondsF(); | 246 run_time_ms_ = (base::Time::NowFromSystemTime() - timer_).InMillisecondsF(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 void RecordReplayURLsFunction::Finish() { | 249 void ReplayURLsFunction::Finish() { |
| 250 record::ReplayURLsResult result; | 250 record::ReplayURLsResult result; |
| 251 | 251 |
| 252 result.run_time = run_time_ms_; | 252 result.run_time = run_time_ms_; |
| 253 result.stats = stats_; | 253 result.stats = stats_; |
| 254 result.errors = errors_; | 254 result.errors = errors_; |
| 255 | 255 |
| 256 results_ = record::ReplayURLs::Results::Create(result); | 256 results_ = record::ReplayURLs::Results::Create(result); |
| 257 SendResponse(true); | 257 SendResponse(true); |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |