| OLD | NEW |
| 1 // Copyright (c) 008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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_publisher.h" | 5 #include "chrome/browser/history/history_publisher.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | |
| 8 #include <atlsafe.h> | |
| 9 #include <objbase.h> | |
| 10 #include <oleauto.h> | |
| 11 #include <wtypes.h> | |
| 12 #endif | |
| 13 | |
| 14 #include "base/registry.h" | |
| 15 | |
| 16 namespace history { | 7 namespace history { |
| 17 | 8 |
| 18 const wchar_t* HistoryPublisher::kRegKeyRegisteredIndexersInfo = | |
| 19 L"Software\\Google\\Google Chrome\\IndexerPlugins"; | |
| 20 const char* HistoryPublisher::kThumbnailImageFormat = "image/jpeg"; | 9 const char* HistoryPublisher::kThumbnailImageFormat = "image/jpeg"; |
| 21 | 10 |
| 22 // static | |
| 23 double HistoryPublisher::TimeToUTCVariantTime(const base::Time& time) { | |
| 24 double var_time = 0; | |
| 25 #if defined(OS_WIN) | |
| 26 if (!time.is_null()) { | |
| 27 base::Time::Exploded exploded; | |
| 28 time.UTCExplode(&exploded); | |
| 29 | |
| 30 // Create the system time struct representing our exploded time. | |
| 31 SYSTEMTIME system_time; | |
| 32 system_time.wYear = exploded.year; | |
| 33 system_time.wMonth = exploded.month; | |
| 34 system_time.wDayOfWeek = exploded.day_of_week; | |
| 35 system_time.wDay = exploded.day_of_month; | |
| 36 system_time.wHour = exploded.hour; | |
| 37 system_time.wMinute = exploded.minute; | |
| 38 system_time.wSecond = exploded.second; | |
| 39 system_time.wMilliseconds = exploded.millisecond; | |
| 40 SystemTimeToVariantTime(&system_time, &var_time); | |
| 41 } | |
| 42 #endif | |
| 43 | |
| 44 return var_time; | |
| 45 } | |
| 46 | |
| 47 HistoryPublisher::HistoryPublisher() { | |
| 48 #if defined(OS_WIN) | |
| 49 CoInitialize(NULL); | |
| 50 #endif | |
| 51 } | |
| 52 | |
| 53 HistoryPublisher::~HistoryPublisher() { | |
| 54 #if defined(OS_WIN) | |
| 55 CoUninitialize(); | |
| 56 #endif | |
| 57 } | |
| 58 | |
| 59 bool HistoryPublisher::Init() { | |
| 60 return ReadRegisteredIndexersFromRegistry(); | |
| 61 } | |
| 62 | |
| 63 bool HistoryPublisher::ReadRegisteredIndexersFromRegistry() { | |
| 64 #if defined(OS_WIN) | |
| 65 RegistryKeyIterator iter(HKEY_CURRENT_USER, kRegKeyRegisteredIndexersInfo); | |
| 66 while (iter.Valid()) { | |
| 67 // The subkey name is the GUID of the Indexer COM object which implements | |
| 68 // the IChromeHistoryIndexer interface. We shall store that and use it to | |
| 69 // send historical data to the indexer. | |
| 70 CLSID clsid; | |
| 71 CLSIDFromString(static_cast<LPOLESTR>( | |
| 72 const_cast<TCHAR*>(iter.Name())), &clsid); | |
| 73 CComPtr<IChromeHistoryIndexer> indexer; | |
| 74 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC, | |
| 75 __uuidof(IChromeHistoryIndexer), | |
| 76 reinterpret_cast<void**>(&indexer)); | |
| 77 if (SUCCEEDED(hr) && indexer != NULL) | |
| 78 indexers_.push_back(indexer); | |
| 79 ++iter; | |
| 80 } | |
| 81 return indexers_.size() > 0; | |
| 82 #else | |
| 83 // The indexing plublisher is implemented only for Windows platform as of | |
| 84 // now. Hence returning false for other platforms. | |
| 85 return false; | |
| 86 #endif | |
| 87 } | |
| 88 | |
| 89 void HistoryPublisher::PublishPageThumbnail( | 11 void HistoryPublisher::PublishPageThumbnail( |
| 90 const std::vector<unsigned char>& thumbnail, const GURL& url, | 12 const std::vector<unsigned char>& thumbnail, const GURL& url, |
| 91 const base::Time& time) const { | 13 const base::Time& time) const { |
| 92 PageData page_data = { | 14 PageData page_data = { |
| 93 time, | 15 time, |
| 94 url, | 16 url, |
| 95 NULL, | 17 NULL, |
| 96 NULL, | 18 NULL, |
| 97 kThumbnailImageFormat, | 19 kThumbnailImageFormat, |
| 98 &thumbnail, | 20 &thumbnail, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 110 url, | 32 url, |
| 111 contents.c_str(), | 33 contents.c_str(), |
| 112 title.c_str(), | 34 title.c_str(), |
| 113 NULL, | 35 NULL, |
| 114 NULL, | 36 NULL, |
| 115 }; | 37 }; |
| 116 | 38 |
| 117 PublishDataToIndexers(page_data); | 39 PublishDataToIndexers(page_data); |
| 118 } | 40 } |
| 119 | 41 |
| 120 void HistoryPublisher::PublishDataToIndexers(const PageData& page_data) | |
| 121 const { | |
| 122 #if defined(OS_WIN) | |
| 123 double var_time = TimeToUTCVariantTime(page_data.time); | |
| 124 | |
| 125 CComSafeArray<unsigned char> thumbnail_arr; | |
| 126 if (page_data.thumbnail) { | |
| 127 for(size_t i = 0; i < page_data.thumbnail->size(); ++i) | |
| 128 thumbnail_arr.Add((*page_data.thumbnail)[i]); | |
| 129 } | |
| 130 | |
| 131 // Send data to registered indexers. | |
| 132 for(size_t i = 0; i < indexers_.size(); ++i) { | |
| 133 indexers_[i]->SendPageData( | |
| 134 CComVariant(var_time, VT_DATE), | |
| 135 CComBSTR(page_data.url.spec().c_str()), | |
| 136 CComBSTR(page_data.html), | |
| 137 CComBSTR(page_data.title), | |
| 138 CComBSTR(page_data.thumbnail_format), | |
| 139 CComVariant(thumbnail_arr.m_psa)); | |
| 140 } | |
| 141 #endif | |
| 142 } | |
| 143 | |
| 144 void HistoryPublisher::DeleteUserHistoryBetween(const base::Time& begin_time, | |
| 145 const base::Time& end_time) cons
t { | |
| 146 #if defined(OS_WIN) | |
| 147 double var_begin_time = TimeToUTCVariantTime(begin_time); | |
| 148 double var_end_time = TimeToUTCVariantTime(end_time); | |
| 149 for(size_t i = 0; i < indexers_.size(); ++i) { | |
| 150 indexers_[i]->DeleteUserHistoryBetween(CComVariant(var_begin_time, VT_DATE), | |
| 151 CComVariant(var_end_time, VT_DATE)); | |
| 152 } | |
| 153 #endif | |
| 154 } | |
| 155 | |
| 156 } // namespace history | 42 } // namespace history |
| OLD | NEW |