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 "HistoryItem.h"
24 #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;
61 int HistoryService::getHistoryItemsCount(){
63 //return getStorageManager()->getHistoryItemsCount();
66 static int __get_duplicated_ids_p(int **ids, int *count, const int limit, const int offset,
67 const bp_history_offset order_column_offset, const int ordering,
68 const bp_history_offset check_column_offset,
69 const char *keyword, const int is_like)
71 bp_history_rows_cond_fmt conds;
72 memset(&conds, 0x00, sizeof(bp_history_rows_cond_fmt));
75 conds.offset = offset;
76 conds.ordering = ordering;
77 conds.order_offset = order_column_offset;
78 conds.period_offset = BP_HISTORY_O_DATE_CREATED;
79 conds.period_type = BP_HISTORY_DATE_ALL;
81 return bp_history_adaptor_get_cond_ids_p
89 void HistoryService::addHistoryItem(std::shared_ptr<HistoryItem> his){
91 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
92 his->setFavIcon(his->getFavIcon());
93 std::shared_ptr<tizen_browser::tools::BrowserImage> favicon = his->getFavIcon();
96 int ret = bp_history_adaptor_create(&id);
98 BROWSER_LOGE("Error! Could not create new bookmark!");
106 bp_history_rows_cond_fmt conds;
107 conds.limit = 20; //no of rows to get negative means no limitation
109 conds.offset = -1; //the first row's index
110 conds.order_offset =BP_HISTORY_O_DATE_CREATED; // property to sort
112 conds.ordering = 1; //way of ordering 0 asc 1 desc
114 conds.period_offset = BP_HISTORY_O_DATE_CREATED;
115 conds.period_type = BP_HISTORY_DATE_TODAY;
117 ret = bp_history_adaptor_get_cond_ids_p(id1 ,count1, &conds, 0, NULL, 0);
119 BROWSER_LOGE("Error! Could not get ids!");
122 bp_history_adaptor_set_url(id, (his->getUrl()).c_str());
123 bp_history_adaptor_set_title(id, (his->getTitle()).c_str());
126 std::unique_ptr<tizen_browser::tools::Blob> favicon_blob = tizen_browser::tools::EflTools::getBlobPNG(favicon);
127 unsigned char * fav = std::move((unsigned char*)favicon_blob->getData());
128 bp_history_adaptor_set_icon(id, favicon->width, favicon->height, fav, favicon_blob->getLength());
130 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
134 void HistoryService::insertOrRefresh(std::shared_ptr<HistoryItem> hi) {
135 getStorageManager()->insertOrRefresh(hi);
139 * @throws HistoryException on error
141 void HistoryService::clearAllHistory()
143 getStorageManager()->deleteHistory();
147 * @throws HistoryException on error
149 void HistoryService::clearURLHistory(const std::string & url)
151 getStorageManager()->deleteHistory(url);
152 if(0 == getHistoryItemsCount()){
158 HistoryItemVector& HistoryService::getHistoryItems(int historyDepthInDays, int maxItems)
160 history_list.clear();
167 bp_history_rows_cond_fmt conds;
168 conds.limit = 20; //no of rows to get negative means no limitation
170 conds.offset = -1; //the first row's index
171 conds.order_offset =BP_HISTORY_O_DATE_CREATED; // property to sort
173 conds.ordering = 1; //way of ordering 0 asc 1 desc
175 conds.period_offset = BP_HISTORY_O_DATE_CREATED;
177 conds.period_type = BP_HISTORY_DATE_TODAY;
179 int ret = bp_history_adaptor_get_cond_ids_p(id1 ,count1, &conds, 0, NULL, 0);
181 BROWSER_LOGD("Error! Could not get ids!");
184 bp_history_offset offset = (BP_HISTORY_O_URL | BP_HISTORY_O_TITLE | BP_HISTORY_O_FAVICON);
186 for(int i = 0; i< (*count1); i++){
187 bp_history_info_fmt history_info;
188 bp_history_adaptor_get_info(ids[i],offset,&history_info);
190 std::shared_ptr<HistoryItem> history = std::make_shared<HistoryItem>(std::string(history_info.url));
191 history_list.push_back(history);
199 int HistoryService::getHistoryVisitCounter(const std::string & url)
201 return getStorageManager()->getHistoryVisitCounter(url);