Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ms release build Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/history/history_api.h" 5 #include "chrome/browser/extensions/api/history/history_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 MessageLoop::current()->PostTask( 261 MessageLoop::current()->PostTask(
262 FROM_HERE, 262 FROM_HERE,
263 base::Bind(&HistoryFunctionWithCallback::SendResponseToCallback, this)); 263 base::Bind(&HistoryFunctionWithCallback::SendResponseToCallback, this));
264 } 264 }
265 265
266 void HistoryFunctionWithCallback::SendResponseToCallback() { 266 void HistoryFunctionWithCallback::SendResponseToCallback() {
267 SendResponse(true); 267 SendResponse(true);
268 Release(); // Balanced in RunImpl(). 268 Release(); // Balanced in RunImpl().
269 } 269 }
270 270
271 bool GetMostVisitedHistoryFunction::RunAsyncImpl() { 271 bool HistoryGetMostVisitedFunction::RunAsyncImpl() {
272 scoped_ptr<GetMostVisited::Params> params = 272 scoped_ptr<GetMostVisited::Params> params =
273 GetMostVisited::Params::Create(*args_); 273 GetMostVisited::Params::Create(*args_);
274 EXTENSION_FUNCTION_VALIDATE(params.get()); 274 EXTENSION_FUNCTION_VALIDATE(params.get());
275 275
276 history::VisitFilter filter; 276 history::VisitFilter filter;
277 if (params->details.filter_time.get()) 277 if (params->details.filter_time.get())
278 filter.SetFilterTime(GetTime(*params->details.filter_time)); 278 filter.SetFilterTime(GetTime(*params->details.filter_time));
279 if (params->details.filter_width.get()) { 279 if (params->details.filter_width.get()) {
280 filter.SetFilterWidth(base::TimeDelta::FromMilliseconds( 280 filter.SetFilterWidth(base::TimeDelta::FromMilliseconds(
281 static_cast<int64>(*params->details.filter_width))); 281 static_cast<int64>(*params->details.filter_width)));
282 } 282 }
283 if (params->details.day_of_the_week.get()) 283 if (params->details.day_of_the_week.get())
284 filter.SetDayOfTheWeekFilter(*params->details.day_of_the_week); 284 filter.SetDayOfTheWeekFilter(*params->details.day_of_the_week);
285 int max_results = 100; 285 int max_results = 100;
286 if (params->details.max_results.get()) 286 if (params->details.max_results.get())
287 max_results = *params->details.max_results; 287 max_results = *params->details.max_results;
288 HistoryService* hs = 288 HistoryService* hs =
289 HistoryServiceFactory::GetForProfile(profile(), Profile::EXPLICIT_ACCESS); 289 HistoryServiceFactory::GetForProfile(profile(), Profile::EXPLICIT_ACCESS);
290 hs->QueryFilteredURLs(max_results, filter, false, &cancelable_consumer_, 290 hs->QueryFilteredURLs(max_results, filter, false, &cancelable_consumer_,
291 base::Bind(&GetMostVisitedHistoryFunction::QueryComplete, 291 base::Bind(&HistoryGetMostVisitedFunction::QueryComplete,
292 base::Unretained(this))); 292 base::Unretained(this)));
293 return true; 293 return true;
294 } 294 }
295 295
296 void GetMostVisitedHistoryFunction::QueryComplete( 296 void HistoryGetMostVisitedFunction::QueryComplete(
297 CancelableRequestProvider::Handle handle, 297 CancelableRequestProvider::Handle handle,
298 const history::FilteredURLList& data) { 298 const history::FilteredURLList& data) {
299 std::vector<linked_ptr<MostVisitedItem> > results; 299 std::vector<linked_ptr<MostVisitedItem> > results;
300 results.reserve(data.size()); 300 results.reserve(data.size());
301 for (size_t i = 0; i < data.size(); i++) { 301 for (size_t i = 0; i < data.size(); i++) {
302 linked_ptr<MostVisitedItem> item(new MostVisitedItem); 302 linked_ptr<MostVisitedItem> item(new MostVisitedItem);
303 item->url = data[i].url.spec(); 303 item->url = data[i].url.spec();
304 item->title = UTF16ToUTF8(data[i].title); 304 item->title = UTF16ToUTF8(data[i].title);
305 results.push_back(item); 305 results.push_back(item);
306 } 306 }
307 results_ = GetMostVisited::Results::Create(results); 307 results_ = GetMostVisited::Results::Create(results);
308 SendAsyncResponse(); 308 SendAsyncResponse();
309 } 309 }
310 310
311 bool GetVisitsHistoryFunction::RunAsyncImpl() { 311 bool HistoryGetVisitsFunction::RunAsyncImpl() {
312 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_)); 312 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_));
313 EXTENSION_FUNCTION_VALIDATE(params.get()); 313 EXTENSION_FUNCTION_VALIDATE(params.get());
314 314
315 GURL url; 315 GURL url;
316 if (!ValidateUrl(params->details.url, &url)) 316 if (!ValidateUrl(params->details.url, &url))
317 return false; 317 return false;
318 318
319 HistoryService* hs = 319 HistoryService* hs =
320 HistoryServiceFactory::GetForProfile(profile(), 320 HistoryServiceFactory::GetForProfile(profile(),
321 Profile::EXPLICIT_ACCESS); 321 Profile::EXPLICIT_ACCESS);
322 hs->QueryURL(url, 322 hs->QueryURL(url,
323 true, // Retrieve full history of a URL. 323 true, // Retrieve full history of a URL.
324 &cancelable_consumer_, 324 &cancelable_consumer_,
325 base::Bind(&GetVisitsHistoryFunction::QueryComplete, 325 base::Bind(&HistoryGetVisitsFunction::QueryComplete,
326 base::Unretained(this))); 326 base::Unretained(this)));
327 327
328 return true; 328 return true;
329 } 329 }
330 330
331 void GetVisitsHistoryFunction::QueryComplete( 331 void HistoryGetVisitsFunction::QueryComplete(
332 HistoryService::Handle request_service, 332 HistoryService::Handle request_service,
333 bool success, 333 bool success,
334 const history::URLRow* url_row, 334 const history::URLRow* url_row,
335 history::VisitVector* visits) { 335 history::VisitVector* visits) {
336 VisitItemList visit_item_vec; 336 VisitItemList visit_item_vec;
337 if (visits && !visits->empty()) { 337 if (visits && !visits->empty()) {
338 for (history::VisitVector::iterator iterator = visits->begin(); 338 for (history::VisitVector::iterator iterator = visits->begin();
339 iterator != visits->end(); 339 iterator != visits->end();
340 ++iterator) { 340 ++iterator) {
341 visit_item_vec.push_back(make_linked_ptr( 341 visit_item_vec.push_back(make_linked_ptr(
342 GetVisitItem(*iterator).release())); 342 GetVisitItem(*iterator).release()));
343 } 343 }
344 } 344 }
345 345
346 results_ = GetVisits::Results::Create(visit_item_vec); 346 results_ = GetVisits::Results::Create(visit_item_vec);
347 SendAsyncResponse(); 347 SendAsyncResponse();
348 } 348 }
349 349
350 bool SearchHistoryFunction::RunAsyncImpl() { 350 bool HistorySearchFunction::RunAsyncImpl() {
351 scoped_ptr<Search::Params> params(Search::Params::Create(*args_)); 351 scoped_ptr<Search::Params> params(Search::Params::Create(*args_));
352 EXTENSION_FUNCTION_VALIDATE(params.get()); 352 EXTENSION_FUNCTION_VALIDATE(params.get());
353 353
354 string16 search_text = UTF8ToUTF16(params->query.text); 354 string16 search_text = UTF8ToUTF16(params->query.text);
355 355
356 history::QueryOptions options; 356 history::QueryOptions options;
357 options.SetRecentDayRange(1); 357 options.SetRecentDayRange(1);
358 options.max_count = 100; 358 options.max_count = 100;
359 359
360 if (params->query.start_time.get()) 360 if (params->query.start_time.get())
361 options.begin_time = GetTime(*params->query.start_time); 361 options.begin_time = GetTime(*params->query.start_time);
362 if (params->query.end_time.get()) 362 if (params->query.end_time.get())
363 options.end_time = GetTime(*params->query.end_time); 363 options.end_time = GetTime(*params->query.end_time);
364 if (params->query.max_results.get()) 364 if (params->query.max_results.get())
365 options.max_count = *params->query.max_results; 365 options.max_count = *params->query.max_results;
366 366
367 HistoryService* hs = 367 HistoryService* hs =
368 HistoryServiceFactory::GetForProfile(profile(), 368 HistoryServiceFactory::GetForProfile(profile(),
369 Profile::EXPLICIT_ACCESS); 369 Profile::EXPLICIT_ACCESS);
370 hs->QueryHistory(search_text, options, &cancelable_consumer_, 370 hs->QueryHistory(search_text, options, &cancelable_consumer_,
371 base::Bind(&SearchHistoryFunction::SearchComplete, 371 base::Bind(&HistorySearchFunction::SearchComplete,
372 base::Unretained(this))); 372 base::Unretained(this)));
373 373
374 return true; 374 return true;
375 } 375 }
376 376
377 void SearchHistoryFunction::SearchComplete( 377 void HistorySearchFunction::SearchComplete(
378 HistoryService::Handle request_handle, 378 HistoryService::Handle request_handle,
379 history::QueryResults* results) { 379 history::QueryResults* results) {
380 HistoryItemList history_item_vec; 380 HistoryItemList history_item_vec;
381 if (results && !results->empty()) { 381 if (results && !results->empty()) {
382 for (history::QueryResults::URLResultVector::const_iterator iterator = 382 for (history::QueryResults::URLResultVector::const_iterator iterator =
383 results->begin(); 383 results->begin();
384 iterator != results->end(); 384 iterator != results->end();
385 ++iterator) { 385 ++iterator) {
386 history_item_vec.push_back(make_linked_ptr( 386 history_item_vec.push_back(make_linked_ptr(
387 GetHistoryItem(**iterator).release())); 387 GetHistoryItem(**iterator).release()));
388 } 388 }
389 } 389 }
390 results_ = Search::Results::Create(history_item_vec); 390 results_ = Search::Results::Create(history_item_vec);
391 SendAsyncResponse(); 391 SendAsyncResponse();
392 } 392 }
393 393
394 bool AddUrlHistoryFunction::RunImpl() { 394 bool HistoryAddUrlFunction::RunImpl() {
395 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_)); 395 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_));
396 EXTENSION_FUNCTION_VALIDATE(params.get()); 396 EXTENSION_FUNCTION_VALIDATE(params.get());
397 397
398 GURL url; 398 GURL url;
399 if (!ValidateUrl(params->details.url, &url)) 399 if (!ValidateUrl(params->details.url, &url))
400 return false; 400 return false;
401 401
402 HistoryService* hs = 402 HistoryService* hs =
403 HistoryServiceFactory::GetForProfile(profile(), 403 HistoryServiceFactory::GetForProfile(profile(),
404 Profile::EXPLICIT_ACCESS); 404 Profile::EXPLICIT_ACCESS);
405 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION); 405 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION);
406 406
407 SendResponse(true); 407 SendResponse(true);
408 return true; 408 return true;
409 } 409 }
410 410
411 bool DeleteUrlHistoryFunction::RunImpl() { 411 bool HistoryDeleteUrlFunction::RunImpl() {
412 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_)); 412 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_));
413 EXTENSION_FUNCTION_VALIDATE(params.get()); 413 EXTENSION_FUNCTION_VALIDATE(params.get());
414 414
415 GURL url; 415 GURL url;
416 if (!ValidateUrl(params->details.url, &url)) 416 if (!ValidateUrl(params->details.url, &url))
417 return false; 417 return false;
418 418
419 HistoryService* hs = 419 HistoryService* hs =
420 HistoryServiceFactory::GetForProfile(profile(), 420 HistoryServiceFactory::GetForProfile(profile(),
421 Profile::EXPLICIT_ACCESS); 421 Profile::EXPLICIT_ACCESS);
422 hs->DeleteURL(url); 422 hs->DeleteURL(url);
423 423
424 SendResponse(true); 424 SendResponse(true);
425 return true; 425 return true;
426 } 426 }
427 427
428 bool DeleteRangeHistoryFunction::RunAsyncImpl() { 428 bool HistoryDeleteRangeFunction::RunAsyncImpl() {
429 scoped_ptr<DeleteRange::Params> params(DeleteRange::Params::Create(*args_)); 429 scoped_ptr<DeleteRange::Params> params(DeleteRange::Params::Create(*args_));
430 EXTENSION_FUNCTION_VALIDATE(params.get()); 430 EXTENSION_FUNCTION_VALIDATE(params.get());
431 431
432 base::Time start_time = GetTime(params->range.start_time); 432 base::Time start_time = GetTime(params->range.start_time);
433 base::Time end_time = GetTime(params->range.end_time); 433 base::Time end_time = GetTime(params->range.end_time);
434 434
435 std::set<GURL> restrict_urls; 435 std::set<GURL> restrict_urls;
436 HistoryService* hs = 436 HistoryService* hs =
437 HistoryServiceFactory::GetForProfile(profile(), 437 HistoryServiceFactory::GetForProfile(profile(),
438 Profile::EXPLICIT_ACCESS); 438 Profile::EXPLICIT_ACCESS);
439 hs->ExpireHistoryBetween( 439 hs->ExpireHistoryBetween(
440 restrict_urls, 440 restrict_urls,
441 start_time, 441 start_time,
442 end_time, 442 end_time,
443 base::Bind(&DeleteRangeHistoryFunction::DeleteComplete, 443 base::Bind(&HistoryDeleteRangeFunction::DeleteComplete,
444 base::Unretained(this)), 444 base::Unretained(this)),
445 &task_tracker_); 445 &task_tracker_);
446 446
447 return true; 447 return true;
448 } 448 }
449 449
450 void DeleteRangeHistoryFunction::DeleteComplete() { 450 void HistoryDeleteRangeFunction::DeleteComplete() {
451 SendAsyncResponse(); 451 SendAsyncResponse();
452 } 452 }
453 453
454 bool DeleteAllHistoryFunction::RunAsyncImpl() { 454 bool HistoryDeleteAllFunction::RunAsyncImpl() {
455 std::set<GURL> restrict_urls; 455 std::set<GURL> restrict_urls;
456 HistoryService* hs = 456 HistoryService* hs =
457 HistoryServiceFactory::GetForProfile(profile(), 457 HistoryServiceFactory::GetForProfile(profile(),
458 Profile::EXPLICIT_ACCESS); 458 Profile::EXPLICIT_ACCESS);
459 hs->ExpireHistoryBetween( 459 hs->ExpireHistoryBetween(
460 restrict_urls, 460 restrict_urls,
461 base::Time::UnixEpoch(), // From the beginning of the epoch. 461 base::Time::UnixEpoch(), // From the beginning of the epoch.
462 base::Time::Now(), // To the current time. 462 base::Time::Now(), // To the current time.
463 base::Bind(&DeleteAllHistoryFunction::DeleteComplete, 463 base::Bind(&HistoryDeleteAllFunction::DeleteComplete,
464 base::Unretained(this)), 464 base::Unretained(this)),
465 &task_tracker_); 465 &task_tracker_);
466 466
467 return true; 467 return true;
468 } 468 }
469 469
470 void DeleteAllHistoryFunction::DeleteComplete() { 470 void HistoryDeleteAllFunction::DeleteComplete() {
471 SendAsyncResponse(); 471 SendAsyncResponse();
472 } 472 }
473 473
474 } // namespace extensions 474 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/history/history_api.h ('k') | chrome/browser/extensions/api/i18n/i18n_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698