| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_history_api.h" | 5 #include "chrome/browser/extensions/extension_history_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 &HistoryFunctionWithCallback::SendResponseToCallback)); | 194 &HistoryFunctionWithCallback::SendResponseToCallback)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void HistoryFunctionWithCallback::SendResponseToCallback() { | 197 void HistoryFunctionWithCallback::SendResponseToCallback() { |
| 198 SendResponse(true); | 198 SendResponse(true); |
| 199 Release(); // Balanced in RunImpl(). | 199 Release(); // Balanced in RunImpl(). |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool GetVisitsHistoryFunction::RunAsyncImpl() { | 202 bool GetVisitsHistoryFunction::RunAsyncImpl() { |
| 203 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 203 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 204 DictionaryValue* json = static_cast<DictionaryValue*>(args_); | 204 const DictionaryValue* json = args_as_dictionary(); |
| 205 | 205 |
| 206 Value* value; | 206 Value* value; |
| 207 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); | 207 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); |
| 208 | 208 |
| 209 GURL url; | 209 GURL url; |
| 210 if (!GetUrlFromValue(value, &url)) | 210 if (!GetUrlFromValue(value, &url)) |
| 211 return false; | 211 return false; |
| 212 | 212 |
| 213 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 213 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 214 hs->QueryURL(url, | 214 hs->QueryURL(url, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 ++iterator) { | 231 ++iterator) { |
| 232 AddVisitNode(*iterator, list); | 232 AddVisitNode(*iterator, list); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 result_.reset(list); | 235 result_.reset(list); |
| 236 SendAsyncResponse(); | 236 SendAsyncResponse(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool SearchHistoryFunction::RunAsyncImpl() { | 239 bool SearchHistoryFunction::RunAsyncImpl() { |
| 240 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 240 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 241 DictionaryValue* json = static_cast<DictionaryValue*>(args_); | 241 const DictionaryValue* json = args_as_dictionary(); |
| 242 | 242 |
| 243 // Initialize the HistoryQuery | 243 // Initialize the HistoryQuery |
| 244 std::wstring search_text; | 244 std::wstring search_text; |
| 245 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kSearchKey, &search_text)); | 245 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kSearchKey, &search_text)); |
| 246 | 246 |
| 247 history::QueryOptions options; | 247 history::QueryOptions options; |
| 248 options.SetRecentDayRange(1); | 248 options.SetRecentDayRange(1); |
| 249 options.max_count = 100; | 249 options.max_count = 100; |
| 250 | 250 |
| 251 if (json->HasKey(keys::kStartTimeKey)) { // Optional. | 251 if (json->HasKey(keys::kStartTimeKey)) { // Optional. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 281 ++iterator) { | 281 ++iterator) { |
| 282 AddHistoryNode(**iterator, list); | 282 AddHistoryNode(**iterator, list); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 result_.reset(list); | 285 result_.reset(list); |
| 286 SendAsyncResponse(); | 286 SendAsyncResponse(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 bool AddUrlHistoryFunction::RunImpl() { | 289 bool AddUrlHistoryFunction::RunImpl() { |
| 290 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 290 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 291 DictionaryValue* json = static_cast<DictionaryValue*>(args_); | 291 const DictionaryValue* json = args_as_dictionary(); |
| 292 | 292 |
| 293 Value* value; | 293 Value* value; |
| 294 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); | 294 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); |
| 295 | 295 |
| 296 GURL url; | 296 GURL url; |
| 297 if (!GetUrlFromValue(value, &url)) | 297 if (!GetUrlFromValue(value, &url)) |
| 298 return false; | 298 return false; |
| 299 | 299 |
| 300 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 300 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 301 hs->AddPage(url); | 301 hs->AddPage(url); |
| 302 | 302 |
| 303 SendResponse(true); | 303 SendResponse(true); |
| 304 return true; | 304 return true; |
| 305 } | 305 } |
| 306 | 306 |
| 307 bool DeleteUrlHistoryFunction::RunImpl() { | 307 bool DeleteUrlHistoryFunction::RunImpl() { |
| 308 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 308 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 309 DictionaryValue* json = static_cast<DictionaryValue*>(args_); | 309 const DictionaryValue* json = args_as_dictionary(); |
| 310 | 310 |
| 311 Value* value; | 311 Value* value; |
| 312 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); | 312 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value)); |
| 313 | 313 |
| 314 GURL url; | 314 GURL url; |
| 315 if (!GetUrlFromValue(value, &url)) | 315 if (!GetUrlFromValue(value, &url)) |
| 316 return false; | 316 return false; |
| 317 | 317 |
| 318 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 318 HistoryService* hs = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 319 hs->DeleteURL(url); | 319 hs->DeleteURL(url); |
| 320 | 320 |
| 321 SendResponse(true); | 321 SendResponse(true); |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 | 324 |
| 325 bool DeleteRangeHistoryFunction::RunAsyncImpl() { | 325 bool DeleteRangeHistoryFunction::RunAsyncImpl() { |
| 326 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); | 326 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); |
| 327 DictionaryValue* json = static_cast<DictionaryValue*>(args_); | 327 const DictionaryValue* json = args_as_dictionary(); |
| 328 | 328 |
| 329 Value* value = NULL; | 329 Value* value = NULL; |
| 330 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kStartTimeKey, &value)); | 330 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kStartTimeKey, &value)); |
| 331 base::Time begin_time; | 331 base::Time begin_time; |
| 332 EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &begin_time)); | 332 EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &begin_time)); |
| 333 | 333 |
| 334 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kEndTimeKey, &value)); | 334 EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kEndTimeKey, &value)); |
| 335 base::Time end_time; | 335 base::Time end_time; |
| 336 EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &end_time)); | 336 EXTENSION_FUNCTION_VALIDATE(GetTimeFromValue(value, &end_time)); |
| 337 | 337 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 356 base::Time::Now(), // To the current time. | 356 base::Time::Now(), // To the current time. |
| 357 &cancelable_consumer_, | 357 &cancelable_consumer_, |
| 358 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); | 358 NewCallback(this, &DeleteAllHistoryFunction::DeleteComplete)); |
| 359 | 359 |
| 360 return true; | 360 return true; |
| 361 } | 361 } |
| 362 | 362 |
| 363 void DeleteAllHistoryFunction::DeleteComplete() { | 363 void DeleteAllHistoryFunction::DeleteComplete() { |
| 364 SendAsyncResponse(); | 364 SendAsyncResponse(); |
| 365 } | 365 } |
| OLD | NEW |