| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // The history system runs on a background thread so that potentially slow | 5 // The history system runs on a background thread so that potentially slow |
| 6 // database operations don't delay the browser. This backend processing is | 6 // database operations don't delay the browser. This backend processing is |
| 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to | 7 // represented by HistoryBackend. The HistoryService's job is to dispatch to |
| 8 // that thread. | 8 // that thread. |
| 9 // | 9 // |
| 10 // Main thread History thread | 10 // Main thread History thread |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/autocomplete/history_url_provider.h" | 33 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 34 #include "chrome/browser/browser_list.h" | 34 #include "chrome/browser/browser_list.h" |
| 35 #include "chrome/browser/browser_process.h" | 35 #include "chrome/browser/browser_process.h" |
| 36 #include "chrome/browser/browser_window.h" | 36 #include "chrome/browser/browser_window.h" |
| 37 #include "chrome/browser/chrome_thread.h" | 37 #include "chrome/browser/chrome_thread.h" |
| 38 #include "chrome/browser/history/download_types.h" | 38 #include "chrome/browser/history/download_types.h" |
| 39 #include "chrome/browser/history/history_backend.h" | 39 #include "chrome/browser/history/history_backend.h" |
| 40 #include "chrome/browser/history/history_types.h" | 40 #include "chrome/browser/history/history_types.h" |
| 41 #include "chrome/browser/history/in_memory_database.h" | 41 #include "chrome/browser/history/in_memory_database.h" |
| 42 #include "chrome/browser/history/in_memory_history_backend.h" | 42 #include "chrome/browser/history/in_memory_history_backend.h" |
| 43 #include "chrome/browser/history/visit_log.h" |
| 43 #include "chrome/browser/profile.h" | 44 #include "chrome/browser/profile.h" |
| 44 #include "chrome/browser/visitedlink_master.h" | 45 #include "chrome/browser/visitedlink_master.h" |
| 45 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
| 46 #include "chrome/common/notification_service.h" | 47 #include "chrome/common/notification_service.h" |
| 47 #include "chrome/common/thumbnail_score.h" | 48 #include "chrome/common/thumbnail_score.h" |
| 48 #include "chrome/common/url_constants.h" | 49 #include "chrome/common/url_constants.h" |
| 49 #include "grit/chromium_strings.h" | 50 #include "grit/chromium_strings.h" |
| 50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
| 51 #include "third_party/skia/include/core/SkBitmap.h" | 52 #include "third_party/skia/include/core/SkBitmap.h" |
| 52 | 53 |
| 53 using base::Time; | 54 using base::Time; |
| 54 using history::HistoryBackend; | 55 using history::HistoryBackend; |
| 55 | 56 |
| 56 static const char* kHistoryThreadName = "Chrome_HistoryThread"; | 57 namespace { |
| 58 |
| 59 class ChromeHistoryThread : public ChromeThread { |
| 60 public: |
| 61 ChromeHistoryThread() : ChromeThread(ChromeThread::HISTORY) {} |
| 62 virtual ~ChromeHistoryThread() { |
| 63 // We cannot rely on our base class to call Stop() in case we want our |
| 64 // CleanUp function to run. |
| 65 Stop(); |
| 66 } |
| 67 protected: |
| 68 virtual void Run(MessageLoop* message_loop) { |
| 69 // Allocate VisitLog on local stack so it will be saved in crash dump. |
| 70 history::VisitLog visit_log; |
| 71 history::InitVisitLog(&visit_log); |
| 72 message_loop->Run(); |
| 73 } |
| 74 }; |
| 75 |
| 76 } // namespace |
| 57 | 77 |
| 58 // Sends messages from the backend to us on the main thread. This must be a | 78 // Sends messages from the backend to us on the main thread. This must be a |
| 59 // separate class from the history service so that it can hold a reference to | 79 // separate class from the history service so that it can hold a reference to |
| 60 // the history service (otherwise we would have to manually AddRef and | 80 // the history service (otherwise we would have to manually AddRef and |
| 61 // Release when the Backend has a reference to us). | 81 // Release when the Backend has a reference to us). |
| 62 class HistoryService::BackendDelegate : public HistoryBackend::Delegate { | 82 class HistoryService::BackendDelegate : public HistoryBackend::Delegate { |
| 63 public: | 83 public: |
| 64 explicit BackendDelegate(HistoryService* history_service) | 84 explicit BackendDelegate(HistoryService* history_service) |
| 65 : history_service_(history_service), | 85 : history_service_(history_service), |
| 66 message_loop_(MessageLoop::current()) { | 86 message_loop_(MessageLoop::current()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 | 113 |
| 94 private: | 114 private: |
| 95 scoped_refptr<HistoryService> history_service_; | 115 scoped_refptr<HistoryService> history_service_; |
| 96 MessageLoop* message_loop_; | 116 MessageLoop* message_loop_; |
| 97 }; | 117 }; |
| 98 | 118 |
| 99 // static | 119 // static |
| 100 const history::StarID HistoryService::kBookmarkBarID = 1; | 120 const history::StarID HistoryService::kBookmarkBarID = 1; |
| 101 | 121 |
| 102 HistoryService::HistoryService() | 122 HistoryService::HistoryService() |
| 103 : thread_(new base::Thread(kHistoryThreadName)), | 123 : thread_(new ChromeHistoryThread()), |
| 104 profile_(NULL), | 124 profile_(NULL), |
| 105 backend_loaded_(false) { | 125 backend_loaded_(false) { |
| 106 // Is NULL when running generate_profile. | 126 // Is NULL when running generate_profile. |
| 107 if (NotificationService::current()) { | 127 if (NotificationService::current()) { |
| 108 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, | 128 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, |
| 109 Source<Profile>(profile_)); | 129 Source<Profile>(profile_)); |
| 110 } | 130 } |
| 111 } | 131 } |
| 112 | 132 |
| 113 HistoryService::HistoryService(Profile* profile) | 133 HistoryService::HistoryService(Profile* profile) |
| 114 : thread_(new base::Thread(kHistoryThreadName)), | 134 : thread_(new ChromeHistoryThread()), |
| 115 profile_(profile), | 135 profile_(profile), |
| 116 backend_loaded_(false) { | 136 backend_loaded_(false) { |
| 117 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, | 137 registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, |
| 118 Source<Profile>(profile_)); | 138 Source<Profile>(profile_)); |
| 119 } | 139 } |
| 120 | 140 |
| 121 HistoryService::~HistoryService() { | 141 HistoryService::~HistoryService() { |
| 122 // Shutdown the backend. This does nothing if Cleanup was already invoked. | 142 // Shutdown the backend. This does nothing if Cleanup was already invoked. |
| 123 Cleanup(); | 143 Cleanup(); |
| 124 } | 144 } |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 NotificationService::current()->Notify(type, source, det); | 699 NotificationService::current()->Notify(type, source, det); |
| 680 } | 700 } |
| 681 | 701 |
| 682 void HistoryService::OnDBLoaded() { | 702 void HistoryService::OnDBLoaded() { |
| 683 LOG(INFO) << "History backend finished loading"; | 703 LOG(INFO) << "History backend finished loading"; |
| 684 backend_loaded_ = true; | 704 backend_loaded_ = true; |
| 685 NotificationService::current()->Notify(NotificationType::HISTORY_LOADED, | 705 NotificationService::current()->Notify(NotificationType::HISTORY_LOADED, |
| 686 Source<Profile>(profile_), | 706 Source<Profile>(profile_), |
| 687 Details<HistoryService>(this)); | 707 Details<HistoryService>(this)); |
| 688 } | 708 } |
| OLD | NEW |