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/file_util.h" | 17 #include "base/file_util.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.h" | 20 #include "base/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/string_util.h" | 23 #include "base/string_util.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
26 #include "chrome/browser/autocomplete/history_url_provider.h" | 26 #include "chrome/browser/autocomplete/history_url_provider.h" |
27 #include "chrome/browser/bookmarks/bookmark_service.h" | 27 #include "chrome/browser/bookmarks/bookmark_service.h" |
| 28 #include "chrome/browser/favicon/favicon_changed_details.h" |
28 #include "chrome/browser/favicon/imported_favicon_usage.h" | 29 #include "chrome/browser/favicon/imported_favicon_usage.h" |
29 #include "chrome/browser/history/download_row.h" | 30 #include "chrome/browser/history/download_row.h" |
30 #include "chrome/browser/history/history_db_task.h" | 31 #include "chrome/browser/history/history_db_task.h" |
31 #include "chrome/browser/history/history_notifications.h" | 32 #include "chrome/browser/history/history_notifications.h" |
32 #include "chrome/browser/history/history_publisher.h" | 33 #include "chrome/browser/history/history_publisher.h" |
33 #include "chrome/browser/history/in_memory_history_backend.h" | 34 #include "chrome/browser/history/in_memory_history_backend.h" |
34 #include "chrome/browser/history/page_usage_data.h" | 35 #include "chrome/browser/history/page_usage_data.h" |
35 #include "chrome/browser/history/select_favicon_frames.h" | 36 #include "chrome/browser/history/select_favicon_frames.h" |
36 #include "chrome/browser/history/top_sites.h" | 37 #include "chrome/browser/history/top_sites.h" |
37 #include "chrome/browser/history/typed_url_syncable_service.h" | 38 #include "chrome/browser/history/typed_url_syncable_service.h" |
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2230 // set already. | 2231 // set already. |
2231 thumbnail_db_->AddIconMapping(*url, favicon_id); | 2232 thumbnail_db_->AddIconMapping(*url, favicon_id); |
2232 favicons_changed.insert(*url); | 2233 favicons_changed.insert(*url); |
2233 } | 2234 } |
2234 } | 2235 } |
2235 } | 2236 } |
2236 } | 2237 } |
2237 | 2238 |
2238 if (!favicons_changed.empty()) { | 2239 if (!favicons_changed.empty()) { |
2239 // Send the notification about the changed favicon URLs. | 2240 // Send the notification about the changed favicon URLs. |
2240 FaviconChangeDetails* changed_details = new FaviconChangeDetails; | 2241 chrome::FaviconChangedDetails* changed_details = |
| 2242 new chrome::FaviconChangedDetails; |
2241 changed_details->urls.swap(favicons_changed); | 2243 changed_details->urls.swap(favicons_changed); |
2242 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, | |
2243 changed_details); | |
2244 } | 2244 } |
2245 } | 2245 } |
2246 | 2246 |
| 2247 |
| 2248 |
2247 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 2249 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
2248 const GURL* page_url, | 2250 const GURL* page_url, |
2249 const std::vector<GURL>& icon_urls, | 2251 const std::vector<GURL>& icon_urls, |
2250 int icon_types, | 2252 int icon_types, |
2251 int desired_size_in_dip, | 2253 int desired_size_in_dip, |
2252 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2254 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
2253 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { | 2255 std::vector<chrome::FaviconBitmapResult>* bitmap_results) { |
2254 // If |page_url| is specified, |icon_types| must be either a single icon | 2256 // If |page_url| is specified, |icon_types| must be either a single icon |
2255 // type or icon types which are equivalent. | 2257 // type or icon types which are equivalent. |
2256 DCHECK(!page_url || | 2258 DCHECK(!page_url || |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2597 // No known redirects, construct mock redirect chain containing |page_url|. | 2599 // No known redirects, construct mock redirect chain containing |page_url|. |
2598 redirect_list->push_back(page_url); | 2600 redirect_list->push_back(page_url); |
2599 } | 2601 } |
2600 } | 2602 } |
2601 | 2603 |
2602 void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects( | 2604 void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects( |
2603 const GURL& page_url) { | 2605 const GURL& page_url) { |
2604 history::RedirectList redirect_list; | 2606 history::RedirectList redirect_list; |
2605 GetCachedRecentRedirects(page_url, &redirect_list); | 2607 GetCachedRecentRedirects(page_url, &redirect_list); |
2606 | 2608 |
2607 FaviconChangeDetails* changed_details = new FaviconChangeDetails; | 2609 chrome::FaviconChangedDetails* changed_details = |
| 2610 new chrome::FaviconChangedDetails(); |
2608 for (size_t i = 0; i < redirect_list.size(); ++i) | 2611 for (size_t i = 0; i < redirect_list.size(); ++i) |
2609 changed_details->urls.insert(redirect_list[i]); | 2612 changed_details->urls.insert(redirect_list[i]); |
2610 | 2613 |
2611 BroadcastNotifications(chrome::NOTIFICATION_FAVICON_CHANGED, | 2614 SendFaviconChangedNotification(changed_details); |
2612 changed_details); | |
2613 } | 2615 } |
2614 | 2616 |
2615 void HistoryBackend::Commit() { | 2617 void HistoryBackend::Commit() { |
2616 if (!db_) | 2618 if (!db_) |
2617 return; | 2619 return; |
2618 | 2620 |
2619 // Note that a commit may not actually have been scheduled if a caller | 2621 // Note that a commit may not actually have been scheduled if a caller |
2620 // explicitly calls this instead of using ScheduleCommit. Likewise, we | 2622 // explicitly calls this instead of using ScheduleCommit. Likewise, we |
2621 // may reset the flag written by a pending commit. But this is OK! It | 2623 // may reset the flag written by a pending commit. But this is OK! It |
2622 // will merely cause extra commits (which is kind of the idea). We | 2624 // will merely cause extra commits (which is kind of the idea). We |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2877 // Make sure we up the refcount of the request. ProcessDBTaskImpl will | 2879 // Make sure we up the refcount of the request. ProcessDBTaskImpl will |
2878 // release when done with the task. | 2880 // release when done with the task. |
2879 request->AddRef(); | 2881 request->AddRef(); |
2880 db_task_requests_.push_back(request.get()); | 2882 db_task_requests_.push_back(request.get()); |
2881 if (!task_scheduled) { | 2883 if (!task_scheduled) { |
2882 // No other tasks are scheduled. Process request now. | 2884 // No other tasks are scheduled. Process request now. |
2883 ProcessDBTaskImpl(); | 2885 ProcessDBTaskImpl(); |
2884 } | 2886 } |
2885 } | 2887 } |
2886 | 2888 |
| 2889 void HistoryBackend::SendFaviconChangedNotification( |
| 2890 chrome::FaviconChangedDetails* details) { |
| 2891 // |delegate_| may be NULL if |this| is in the process of closing (closed by |
| 2892 // HistoryService -> HistoryBackend::Closing(). |
| 2893 if (delegate_) |
| 2894 delegate_->SendFaviconChangedNotification(details); |
| 2895 else |
| 2896 delete details; |
| 2897 } |
| 2898 |
2887 void HistoryBackend::BroadcastNotifications( | 2899 void HistoryBackend::BroadcastNotifications( |
2888 int type, | 2900 int type, |
2889 HistoryDetails* details_deleted) { | 2901 HistoryDetails* details_deleted) { |
2890 // |delegate_| may be NULL if |this| is in the process of closing (closed by | 2902 // |delegate_| may be NULL if |this| is in the process of closing (closed by |
2891 // HistoryService -> HistoryBackend::Closing(). | 2903 // HistoryService -> HistoryBackend::Closing(). |
2892 if (delegate_) | 2904 if (delegate_) |
2893 delegate_->BroadcastNotifications(type, details_deleted); | 2905 delegate_->BroadcastNotifications(type, details_deleted); |
2894 else | 2906 else |
2895 delete details_deleted; | 2907 delete details_deleted; |
2896 } | 2908 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3097 info.url_id = visit.url_id; | 3109 info.url_id = visit.url_id; |
3098 info.time = visit.visit_time; | 3110 info.time = visit.visit_time; |
3099 info.transition = visit.transition; | 3111 info.transition = visit.transition; |
3100 // If we don't have a delegate yet during setup or shutdown, we will drop | 3112 // If we don't have a delegate yet during setup or shutdown, we will drop |
3101 // these notifications. | 3113 // these notifications. |
3102 if (delegate_) | 3114 if (delegate_) |
3103 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3115 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3104 } | 3116 } |
3105 | 3117 |
3106 } // namespace history | 3118 } // namespace history |
OLD | NEW |