History Implementation using Browser Provider.
[profile/tv/apps/web/browser.git] / services / HistoryService / HistoryService.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #ifndef __HISTORY_SERVICE_H
18 #define __HISTORY_SERVICE_H
19
20 #include <vector>
21 #include <memory>
22 #include <boost/date_time/gregorian/gregorian.hpp>
23 #include <boost/signals2/signal.hpp>
24
25 #include "ServiceFactory.h"
26 #include "service_macros.h"
27 #include "BrowserImage.h"
28 #include "HistoryItem.h"
29 #include "HistoryStorage.h"
30 #include "StorageService.h"
31 #include <web/web_history.h>
32 #define DOMAIN_HISTORY_SERVICE "org.tizen.browser.historyservice"
33
34 namespace tizen_browser
35 {
36 namespace services
37 {
38
39 class BROWSER_EXPORT HistoryService: public tizen_browser::core::AbstractService
40 {
41 public:
42     HistoryService();
43     virtual ~HistoryService();
44     virtual std::string getName();
45
46     /**
47      * @throws HistoryException on error
48      */
49     void addHistoryItem(std::shared_ptr<HistoryItem> hi);
50
51     /**
52      * If hi->getUrl() exists on a table HISTORY update visit_counter and visit_date, unless insert hi to database.
53      *
54      * @throws HistoryException on error
55      */
56     void insertOrRefresh(std::shared_ptr<HistoryItem> hi);
57
58     /**
59      * @throws HistoryException on error
60      */
61     void clearAllHistory();
62
63     /**
64      * @throws HistoryException on error
65      */
66     void clearURLHistory(const std::string & url);
67
68     /**
69      * @throws HistoryException on error
70      */
71     std::shared_ptr<HistoryItem> getHistoryItem(const std::string & url);
72
73     /**
74      * @throws HistoryException on error
75      */
76     HistoryItemVector & getHistoryItems(int historyDepthInDays = 7, int maxItems = 50);
77
78     /**
79      * @throws HistoryException on error
80      */
81     int getHistoryItemsCount();
82
83     /**
84      * @throws HistoryException on error
85      */
86     int getHistoryVisitCounter(const std::string & url);
87
88     void setStorageServiceTestMode(bool testmode = true);
89
90     boost::signals2::signal<void (bool)>historyEmpty;
91 private:
92     bool m_testDbMod;;
93     std::vector<std::shared_ptr<HistoryItem>> history_list;
94     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
95
96     /**
97      * @throws StorageExceptionInitialization on error
98      */
99     void initDatabaseBookmark(const std::string & db_str);
100
101     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
102
103 };
104
105 }
106 }
107
108 #endif