| 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/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/history/history_notifications.h" | |
| 28 #include "chrome/browser/history/in_memory_history_backend.h" | 27 #include "chrome/browser/history/in_memory_history_backend.h" |
| 29 #include "chrome/browser/history/in_memory_history_backend.h" | 28 #include "chrome/browser/history/in_memory_history_backend.h" |
| 30 #include "chrome/browser/history/top_sites.h" | 29 #include "chrome/browser/history/top_sites.h" |
| 31 #include "chrome/browser/history/typed_url_syncable_service.h" | 30 #include "chrome/browser/history/typed_url_syncable_service.h" |
| 32 #include "chrome/browser/history/typed_url_syncable_service.h" | 31 #include "chrome/browser/history/typed_url_syncable_service.h" |
| 33 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/importer/imported_favicon_usage.h" | 33 #include "chrome/common/importer/imported_favicon_usage.h" |
| 35 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 36 #include "components/favicon_base/select_favicon_frames.h" | 35 #include "components/favicon_base/select_favicon_frames.h" |
| 37 #include "components/history/core/browser/download_constants.h" | 36 #include "components/history/core/browser/download_constants.h" |
| (...skipping 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2482 scoped_ptr<HistoryDBTask> task, | 2481 scoped_ptr<HistoryDBTask> task, |
| 2483 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, | 2482 scoped_refptr<base::SingleThreadTaskRunner> origin_loop, |
| 2484 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { | 2483 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { |
| 2485 bool scheduled = !queued_history_db_tasks_.empty(); | 2484 bool scheduled = !queued_history_db_tasks_.empty(); |
| 2486 queued_history_db_tasks_.push_back( | 2485 queued_history_db_tasks_.push_back( |
| 2487 new QueuedHistoryDBTask(task.Pass(), origin_loop, is_canceled)); | 2486 new QueuedHistoryDBTask(task.Pass(), origin_loop, is_canceled)); |
| 2488 if (!scheduled) | 2487 if (!scheduled) |
| 2489 ProcessDBTaskImpl(); | 2488 ProcessDBTaskImpl(); |
| 2490 } | 2489 } |
| 2491 | 2490 |
| 2492 void HistoryBackend::BroadcastNotifications( | |
| 2493 int type, | |
| 2494 scoped_ptr<HistoryDetails> details) { | |
| 2495 // |delegate_| may be NULL if |this| is in the process of closing (closed by | |
| 2496 // HistoryService -> HistoryBackend::Closing(). | |
| 2497 if (delegate_) | |
| 2498 delegate_->BroadcastNotifications(type, details.Pass()); | |
| 2499 } | |
| 2500 | |
| 2501 void HistoryBackend::NotifyFaviconChanged(const std::set<GURL>& urls) { | 2491 void HistoryBackend::NotifyFaviconChanged(const std::set<GURL>& urls) { |
| 2502 if (delegate_) | 2492 if (delegate_) |
| 2503 delegate_->NotifyFaviconChanged(urls); | 2493 delegate_->NotifyFaviconChanged(urls); |
| 2504 } | 2494 } |
| 2505 | 2495 |
| 2506 void HistoryBackend::NotifyURLVisited(ui::PageTransition transition, | 2496 void HistoryBackend::NotifyURLVisited(ui::PageTransition transition, |
| 2507 const URLRow& row, | 2497 const URLRow& row, |
| 2508 const RedirectList& redirects, | 2498 const RedirectList& redirects, |
| 2509 base::Time visit_time) { | 2499 base::Time visit_time) { |
| 2510 URLRow url_info(row); | 2500 URLRow url_info(row); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2535 // an HistoryBackendObserver and register it so that we can remove this | 2525 // an HistoryBackendObserver and register it so that we can remove this |
| 2536 // method. | 2526 // method. |
| 2537 if (delegate_) | 2527 if (delegate_) |
| 2538 delegate_->NotifyURLsModified(changed_urls); | 2528 delegate_->NotifyURLsModified(changed_urls); |
| 2539 } | 2529 } |
| 2540 | 2530 |
| 2541 void HistoryBackend::NotifyURLsDeleted(bool all_history, | 2531 void HistoryBackend::NotifyURLsDeleted(bool all_history, |
| 2542 bool expired, | 2532 bool expired, |
| 2543 const URLRows& rows, | 2533 const URLRows& rows, |
| 2544 const std::set<GURL>& favicon_urls) { | 2534 const std::set<GURL>& favicon_urls) { |
| 2545 scoped_ptr<URLsDeletedDetails> details(new URLsDeletedDetails); | 2535 URLRows copied_rows(rows); |
| 2546 details->all_history = all_history; | |
| 2547 details->expired = expired; | |
| 2548 details->rows = rows; | |
| 2549 details->favicon_urls = favicon_urls; | |
| 2550 | |
| 2551 if (typed_url_syncable_service_.get()) { | 2536 if (typed_url_syncable_service_.get()) { |
| 2552 typed_url_syncable_service_->OnUrlsDeleted( | 2537 typed_url_syncable_service_->OnUrlsDeleted(all_history, expired, |
| 2553 all_history, expired, &details->rows); | 2538 &copied_rows); |
| 2554 } | 2539 } |
| 2555 | 2540 |
| 2556 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 2541 FOR_EACH_OBSERVER( |
| 2557 details.Pass()); | 2542 HistoryBackendObserver, observers_, |
| 2543 OnURLsDeleted(this, all_history, expired, copied_rows, favicon_urls)); |
| 2544 |
| 2545 // TODO(sdefresne): turn HistoryBackend::Delegate from HistoryService into |
| 2546 // an HistoryBackendObserver and register it so that we can remove this |
| 2547 // method. |
| 2548 if (delegate_) |
| 2549 delegate_->NotifyURLsDeleted(all_history, expired, copied_rows, |
| 2550 favicon_urls); |
| 2558 } | 2551 } |
| 2559 | 2552 |
| 2560 // Deleting -------------------------------------------------------------------- | 2553 // Deleting -------------------------------------------------------------------- |
| 2561 | 2554 |
| 2562 void HistoryBackend::DeleteAllHistory() { | 2555 void HistoryBackend::DeleteAllHistory() { |
| 2563 // Our approach to deleting all history is: | 2556 // Our approach to deleting all history is: |
| 2564 // 1. Copy the bookmarks and their dependencies to new tables with temporary | 2557 // 1. Copy the bookmarks and their dependencies to new tables with temporary |
| 2565 // names. | 2558 // names. |
| 2566 // 2. Delete the original tables. Since tables can not share pages, we know | 2559 // 2. Delete the original tables. Since tables can not share pages, we know |
| 2567 // that any data we don't want to keep is now in an unused page. | 2560 // that any data we don't want to keep is now in an unused page. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2701 info.url_id = visit.url_id; | 2694 info.url_id = visit.url_id; |
| 2702 info.time = visit.visit_time; | 2695 info.time = visit.visit_time; |
| 2703 info.transition = visit.transition; | 2696 info.transition = visit.transition; |
| 2704 // If we don't have a delegate yet during setup or shutdown, we will drop | 2697 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 2705 // these notifications. | 2698 // these notifications. |
| 2706 if (delegate_) | 2699 if (delegate_) |
| 2707 delegate_->NotifyAddVisit(info); | 2700 delegate_->NotifyAddVisit(info); |
| 2708 } | 2701 } |
| 2709 | 2702 |
| 2710 } // namespace history | 2703 } // namespace history |
| OLD | NEW |