OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/history/history_publisher.h" |
| 6 |
| 7 #include <atlsafe.h> |
| 8 #include <objbase.h> |
| 9 #include <oleauto.h> |
| 10 #include <wtypes.h> |
| 11 |
| 12 #include "base/registry.h" |
| 13 |
| 14 namespace history { |
| 15 |
| 16 const wchar_t* HistoryPublisher::kRegKeyRegisteredIndexersInfo = |
| 17 L"Software\\Google\\Google Chrome\\IndexerPlugins"; |
| 18 |
| 19 // static |
| 20 double HistoryPublisher::TimeToUTCVariantTime(const base::Time& time) { |
| 21 double var_time = 0; |
| 22 if (!time.is_null()) { |
| 23 base::Time::Exploded exploded; |
| 24 time.UTCExplode(&exploded); |
| 25 |
| 26 // Create the system time struct representing our exploded time. |
| 27 SYSTEMTIME system_time; |
| 28 system_time.wYear = exploded.year; |
| 29 system_time.wMonth = exploded.month; |
| 30 system_time.wDayOfWeek = exploded.day_of_week; |
| 31 system_time.wDay = exploded.day_of_month; |
| 32 system_time.wHour = exploded.hour; |
| 33 system_time.wMinute = exploded.minute; |
| 34 system_time.wSecond = exploded.second; |
| 35 system_time.wMilliseconds = exploded.millisecond; |
| 36 SystemTimeToVariantTime(&system_time, &var_time); |
| 37 } |
| 38 |
| 39 return var_time; |
| 40 } |
| 41 |
| 42 HistoryPublisher::HistoryPublisher() { |
| 43 CoInitialize(NULL); |
| 44 } |
| 45 |
| 46 HistoryPublisher::~HistoryPublisher() { |
| 47 CoUninitialize(); |
| 48 } |
| 49 |
| 50 bool HistoryPublisher::Init() { |
| 51 return ReadRegisteredIndexersFromRegistry(); |
| 52 } |
| 53 |
| 54 bool HistoryPublisher::ReadRegisteredIndexersFromRegistry() { |
| 55 RegistryKeyIterator iter(HKEY_CURRENT_USER, kRegKeyRegisteredIndexersInfo); |
| 56 while (iter.Valid()) { |
| 57 // The subkey name is the GUID of the Indexer COM object which implements |
| 58 // the IChromeHistoryIndexer interface. We shall store that and use it to |
| 59 // send historical data to the indexer. |
| 60 CLSID clsid; |
| 61 CLSIDFromString(static_cast<LPOLESTR>( |
| 62 const_cast<TCHAR*>(iter.Name())), &clsid); |
| 63 CComPtr<IChromeHistoryIndexer> indexer; |
| 64 HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC, |
| 65 __uuidof(IChromeHistoryIndexer), |
| 66 reinterpret_cast<void**>(&indexer)); |
| 67 if (SUCCEEDED(hr) && indexer != NULL) |
| 68 indexers_.push_back(indexer); |
| 69 ++iter; |
| 70 } |
| 71 return indexers_.size() > 0; |
| 72 } |
| 73 |
| 74 void HistoryPublisher::PublishDataToIndexers(const PageData& page_data) |
| 75 const { |
| 76 double var_time = TimeToUTCVariantTime(page_data.time); |
| 77 |
| 78 CComSafeArray<unsigned char> thumbnail_arr; |
| 79 if (page_data.thumbnail) { |
| 80 for(size_t i = 0; i < page_data.thumbnail->size(); ++i) |
| 81 thumbnail_arr.Add((*page_data.thumbnail)[i]); |
| 82 } |
| 83 |
| 84 // Send data to registered indexers. |
| 85 for(size_t i = 0; i < indexers_.size(); ++i) { |
| 86 indexers_[i]->SendPageData( |
| 87 CComVariant(var_time, VT_DATE), |
| 88 CComBSTR(page_data.url.spec().c_str()), |
| 89 CComBSTR(page_data.html), |
| 90 CComBSTR(page_data.title), |
| 91 CComBSTR(page_data.thumbnail_format), |
| 92 CComVariant(thumbnail_arr.m_psa)); |
| 93 } |
| 94 } |
| 95 |
| 96 void HistoryPublisher::DeleteUserHistoryBetween(const base::Time& begin_time, |
| 97 const base::Time& end_time) |
| 98 const { |
| 99 double var_begin_time = TimeToUTCVariantTime(begin_time); |
| 100 double var_end_time = TimeToUTCVariantTime(end_time); |
| 101 for(size_t i = 0; i < indexers_.size(); ++i) { |
| 102 indexers_[i]->DeleteUserHistoryBetween(CComVariant(var_begin_time, VT_DATE), |
| 103 CComVariant(var_end_time, VT_DATE)); |
| 104 } |
| 105 } |
| 106 |
| 107 } // namespace history |
OLD | NEW |