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

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

Issue 839193002: Move ServiceAccessType into //components/keyed_service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation on android Created 5 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
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 template <> 219 template <>
220 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() { 220 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies() {
221 DependsOn(ActivityLog::GetFactoryInstance()); 221 DependsOn(ActivityLog::GetFactoryInstance());
222 DependsOn(HistoryServiceFactory::GetInstance()); 222 DependsOn(HistoryServiceFactory::GetInstance());
223 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 223 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
224 } 224 }
225 225
226 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) { 226 void HistoryAPI::OnListenerAdded(const EventListenerInfo& details) {
227 Profile* profile = Profile::FromBrowserContext(browser_context_); 227 Profile* profile = Profile::FromBrowserContext(browser_context_);
228 history_event_router_.reset(new HistoryEventRouter( 228 history_event_router_.reset(new HistoryEventRouter(
229 profile, 229 profile, HistoryServiceFactory::GetForProfile(
230 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS))); 230 profile, ServiceAccessType::EXPLICIT_ACCESS)));
231 EventRouter::Get(browser_context_)->UnregisterObserver(this); 231 EventRouter::Get(browser_context_)->UnregisterObserver(this);
232 } 232 }
233 233
234 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) { 234 bool HistoryFunction::ValidateUrl(const std::string& url_string, GURL* url) {
235 GURL temp_url(url_string); 235 GURL temp_url(url_string);
236 if (!temp_url.is_valid()) { 236 if (!temp_url.is_valid()) {
237 error_ = kInvalidUrlError; 237 error_ = kInvalidUrlError;
238 return false; 238 return false;
239 } 239 }
240 url->Swap(&temp_url); 240 url->Swap(&temp_url);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 bool HistoryGetVisitsFunction::RunAsyncImpl() { 288 bool HistoryGetVisitsFunction::RunAsyncImpl() {
289 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_)); 289 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_));
290 EXTENSION_FUNCTION_VALIDATE(params.get()); 290 EXTENSION_FUNCTION_VALIDATE(params.get());
291 291
292 GURL url; 292 GURL url;
293 if (!ValidateUrl(params->details.url, &url)) 293 if (!ValidateUrl(params->details.url, &url))
294 return false; 294 return false;
295 295
296 HistoryService* hs = HistoryServiceFactory::GetForProfile( 296 HistoryService* hs = HistoryServiceFactory::GetForProfile(
297 GetProfile(), Profile::EXPLICIT_ACCESS); 297 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
298 hs->QueryURL(url, 298 hs->QueryURL(url,
299 true, // Retrieve full history of a URL. 299 true, // Retrieve full history of a URL.
300 base::Bind(&HistoryGetVisitsFunction::QueryComplete, 300 base::Bind(&HistoryGetVisitsFunction::QueryComplete,
301 base::Unretained(this)), 301 base::Unretained(this)),
302 &task_tracker_); 302 &task_tracker_);
303 return true; 303 return true;
304 } 304 }
305 305
306 void HistoryGetVisitsFunction::QueryComplete( 306 void HistoryGetVisitsFunction::QueryComplete(
307 bool success, 307 bool success,
(...skipping 24 matching lines...) Expand all
332 options.max_count = 100; 332 options.max_count = 100;
333 333
334 if (params->query.start_time.get()) 334 if (params->query.start_time.get())
335 options.begin_time = GetTime(*params->query.start_time); 335 options.begin_time = GetTime(*params->query.start_time);
336 if (params->query.end_time.get()) 336 if (params->query.end_time.get())
337 options.end_time = GetTime(*params->query.end_time); 337 options.end_time = GetTime(*params->query.end_time);
338 if (params->query.max_results.get()) 338 if (params->query.max_results.get())
339 options.max_count = *params->query.max_results; 339 options.max_count = *params->query.max_results;
340 340
341 HistoryService* hs = HistoryServiceFactory::GetForProfile( 341 HistoryService* hs = HistoryServiceFactory::GetForProfile(
342 GetProfile(), Profile::EXPLICIT_ACCESS); 342 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
343 hs->QueryHistory(search_text, 343 hs->QueryHistory(search_text,
344 options, 344 options,
345 base::Bind(&HistorySearchFunction::SearchComplete, 345 base::Bind(&HistorySearchFunction::SearchComplete,
346 base::Unretained(this)), 346 base::Unretained(this)),
347 &task_tracker_); 347 &task_tracker_);
348 348
349 return true; 349 return true;
350 } 350 }
351 351
352 void HistorySearchFunction::SearchComplete(history::QueryResults* results) { 352 void HistorySearchFunction::SearchComplete(history::QueryResults* results) {
(...skipping 13 matching lines...) Expand all
366 366
367 bool HistoryAddUrlFunction::RunAsync() { 367 bool HistoryAddUrlFunction::RunAsync() {
368 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_)); 368 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_));
369 EXTENSION_FUNCTION_VALIDATE(params.get()); 369 EXTENSION_FUNCTION_VALIDATE(params.get());
370 370
371 GURL url; 371 GURL url;
372 if (!ValidateUrl(params->details.url, &url)) 372 if (!ValidateUrl(params->details.url, &url))
373 return false; 373 return false;
374 374
375 HistoryService* hs = HistoryServiceFactory::GetForProfile( 375 HistoryService* hs = HistoryServiceFactory::GetForProfile(
376 GetProfile(), Profile::EXPLICIT_ACCESS); 376 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
377 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION); 377 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION);
378 378
379 SendResponse(true); 379 SendResponse(true);
380 return true; 380 return true;
381 } 381 }
382 382
383 bool HistoryDeleteUrlFunction::RunAsync() { 383 bool HistoryDeleteUrlFunction::RunAsync() {
384 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_)); 384 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_));
385 EXTENSION_FUNCTION_VALIDATE(params.get()); 385 EXTENSION_FUNCTION_VALIDATE(params.get());
386 386
387 if (!VerifyDeleteAllowed()) 387 if (!VerifyDeleteAllowed())
388 return false; 388 return false;
389 389
390 GURL url; 390 GURL url;
391 if (!ValidateUrl(params->details.url, &url)) 391 if (!ValidateUrl(params->details.url, &url))
392 return false; 392 return false;
393 393
394 HistoryService* hs = HistoryServiceFactory::GetForProfile( 394 HistoryService* hs = HistoryServiceFactory::GetForProfile(
395 GetProfile(), Profile::EXPLICIT_ACCESS); 395 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
396 hs->DeleteURL(url); 396 hs->DeleteURL(url);
397 397
398 // Also clean out from the activity log. If the activity log testing flag is 398 // Also clean out from the activity log. If the activity log testing flag is
399 // set then don't clean so testers can see what potentially malicious 399 // set then don't clean so testers can see what potentially malicious
400 // extensions have been trying to clean from their logs. 400 // extensions have been trying to clean from their logs.
401 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 401 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
402 switches::kEnableExtensionActivityLogTesting)) { 402 switches::kEnableExtensionActivityLogTesting)) {
403 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); 403 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile());
404 DCHECK(activity_log); 404 DCHECK(activity_log);
405 activity_log->RemoveURL(url); 405 activity_log->RemoveURL(url);
406 } 406 }
407 407
408 SendResponse(true); 408 SendResponse(true);
409 return true; 409 return true;
410 } 410 }
411 411
412 bool HistoryDeleteRangeFunction::RunAsyncImpl() { 412 bool HistoryDeleteRangeFunction::RunAsyncImpl() {
413 scoped_ptr<DeleteRange::Params> params(DeleteRange::Params::Create(*args_)); 413 scoped_ptr<DeleteRange::Params> params(DeleteRange::Params::Create(*args_));
414 EXTENSION_FUNCTION_VALIDATE(params.get()); 414 EXTENSION_FUNCTION_VALIDATE(params.get());
415 415
416 if (!VerifyDeleteAllowed()) 416 if (!VerifyDeleteAllowed())
417 return false; 417 return false;
418 418
419 base::Time start_time = GetTime(params->range.start_time); 419 base::Time start_time = GetTime(params->range.start_time);
420 base::Time end_time = GetTime(params->range.end_time); 420 base::Time end_time = GetTime(params->range.end_time);
421 421
422 std::set<GURL> restrict_urls; 422 std::set<GURL> restrict_urls;
423 HistoryService* hs = HistoryServiceFactory::GetForProfile( 423 HistoryService* hs = HistoryServiceFactory::GetForProfile(
424 GetProfile(), Profile::EXPLICIT_ACCESS); 424 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
425 hs->ExpireHistoryBetween( 425 hs->ExpireHistoryBetween(
426 restrict_urls, 426 restrict_urls,
427 start_time, 427 start_time,
428 end_time, 428 end_time,
429 base::Bind(&HistoryDeleteRangeFunction::DeleteComplete, 429 base::Bind(&HistoryDeleteRangeFunction::DeleteComplete,
430 base::Unretained(this)), 430 base::Unretained(this)),
431 &task_tracker_); 431 &task_tracker_);
432 432
433 // Also clean from the activity log unless in testing mode. 433 // Also clean from the activity log unless in testing mode.
434 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 434 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
435 switches::kEnableExtensionActivityLogTesting)) { 435 switches::kEnableExtensionActivityLogTesting)) {
436 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); 436 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile());
437 DCHECK(activity_log); 437 DCHECK(activity_log);
438 activity_log->RemoveURLs(restrict_urls); 438 activity_log->RemoveURLs(restrict_urls);
439 } 439 }
440 440
441 return true; 441 return true;
442 } 442 }
443 443
444 void HistoryDeleteRangeFunction::DeleteComplete() { 444 void HistoryDeleteRangeFunction::DeleteComplete() {
445 SendAsyncResponse(); 445 SendAsyncResponse();
446 } 446 }
447 447
448 bool HistoryDeleteAllFunction::RunAsyncImpl() { 448 bool HistoryDeleteAllFunction::RunAsyncImpl() {
449 if (!VerifyDeleteAllowed()) 449 if (!VerifyDeleteAllowed())
450 return false; 450 return false;
451 451
452 std::set<GURL> restrict_urls; 452 std::set<GURL> restrict_urls;
453 HistoryService* hs = HistoryServiceFactory::GetForProfile( 453 HistoryService* hs = HistoryServiceFactory::GetForProfile(
454 GetProfile(), Profile::EXPLICIT_ACCESS); 454 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS);
455 hs->ExpireHistoryBetween( 455 hs->ExpireHistoryBetween(
456 restrict_urls, 456 restrict_urls,
457 base::Time(), // Unbounded beginning... 457 base::Time(), // Unbounded beginning...
458 base::Time(), // ...and the end. 458 base::Time(), // ...and the end.
459 base::Bind(&HistoryDeleteAllFunction::DeleteComplete, 459 base::Bind(&HistoryDeleteAllFunction::DeleteComplete,
460 base::Unretained(this)), 460 base::Unretained(this)),
461 &task_tracker_); 461 &task_tracker_);
462 462
463 // Also clean from the activity log unless in testing mode. 463 // Also clean from the activity log unless in testing mode.
464 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 464 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
465 switches::kEnableExtensionActivityLogTesting)) { 465 switches::kEnableExtensionActivityLogTesting)) {
466 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile()); 466 ActivityLog* activity_log = ActivityLog::GetInstance(GetProfile());
467 DCHECK(activity_log); 467 DCHECK(activity_log);
468 activity_log->RemoveURLs(restrict_urls); 468 activity_log->RemoveURLs(restrict_urls);
469 } 469 }
470 470
471 return true; 471 return true;
472 } 472 }
473 473
474 void HistoryDeleteAllFunction::DeleteComplete() { 474 void HistoryDeleteAllFunction::DeleteComplete() {
475 SendAsyncResponse(); 475 SendAsyncResponse();
476 } 476 }
477 477
478 } // namespace extensions 478 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698