2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <BrowserAssert.h>
19 #include <boost/date_time/posix_time/posix_time.hpp>
21 #include "ServiceManager.h"
22 #include "HistoryService.h"
23 #include "AbstractWebEngine.h"
25 namespace tizen_browser
30 EXPORT_SERVICE(HistoryService, DOMAIN_HISTORY_SERVICE)
32 HistoryService::HistoryService() : m_testDbMod(false)
34 BROWSER_LOGD("HistoryService");
37 HistoryService::~HistoryService()
41 std::shared_ptr<tizen_browser::services::StorageService> HistoryService::getStorageManager()
43 if (!m_storageManager) {
44 m_storageManager = std::dynamic_pointer_cast <
45 tizen_browser::services::StorageService,
46 tizen_browser::core::AbstractService > (
47 tizen_browser::core::ServiceManager::getInstance().getService(
48 DOMAIN_STORAGE_SERVICE));
51 M_ASSERT(m_storageManager);
52 m_storageManager->init(m_testDbMod);
54 return m_storageManager;
57 void HistoryService::setStorageServiceTestMode(bool testmode) {
58 m_testDbMod = testmode;
62 * @throws HistoryException on error
64 void HistoryService::addHistoryItem(std::shared_ptr<HistoryItem> hi)
66 getStorageManager()->addHistoryItem(hi);
70 * If hi->getUrl() exists on a table HISTORY update visit_counter and visit_date, unless insert hi to database.
72 * @throws HistoryException on error
74 void HistoryService::insertOrRefresh(std::shared_ptr<HistoryItem> hi) {
75 getStorageManager()->insertOrRefresh(hi);
79 * @throws HistoryException on error
81 void HistoryService::clearAllHistory()
83 getStorageManager()->deleteHistory();
87 * @throws HistoryException on error
89 void HistoryService::clearURLHistory(const std::string & url)
91 getStorageManager()->deleteHistory(url);
92 if(0 == getHistoryItemsCount()){
98 * @throws HistoryException on error
100 std::shared_ptr<HistoryItem> HistoryService::getHistoryItem(const std::string & url)
102 return getStorageManager()->getHistoryItem(url);
106 * @throws HistoryException on error
108 HistoryItemVector& HistoryService::getHistoryItems(int historyDepthInDays, int maxItems)
110 return getStorageManager()->getHistoryItems(historyDepthInDays, maxItems);
114 * @throws HistoryException on error
116 int HistoryService::getHistoryItemsCount()
118 return getStorageManager()->getHistoryItemsCount();
122 * @throws HistoryException on error
124 int HistoryService::getHistoryVisitCounter(const std::string & url)
126 return getStorageManager()->getHistoryVisitCounter(url);