Task TT-75 Implement "Main page loading UI" view
[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     int getHistoryId(const std::string & url);
47
48     /**
49      * @throws HistoryException on error
50      */
51     void addHistoryItem(std::shared_ptr<HistoryItem> hi,
52                         std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail=std::shared_ptr<tizen_browser::tools::BrowserImage>());
53
54     /**
55      * If hi->getUrl() exists on a table HISTORY update visit_counter and visit_date, unless insert hi to database.
56      *
57      * @throws HistoryException on error
58      */
59     void insertOrRefresh(std::shared_ptr<HistoryItem> hi);
60
61     /**
62      * @throws HistoryException on error
63      */
64     void clearAllHistory();
65
66     /**
67      * @throws HistoryException on error
68      */
69     void clearURLHistory(const std::string & url);
70
71     /**
72      * @throws HistoryException on error
73      */
74     std::shared_ptr<HistoryItem> getHistoryItem(const std::string & url);
75
76     /**
77      * @throws HistoryException on error
78      */
79     HistoryItemVector & getHistoryItems(int historyDepthInDays = 7, int maxItems = 50);
80     HistoryItemVector & getMostVisitedHistoryItems();
81
82     /**
83      * @throws HistoryException on error
84      */
85     int getHistoryItemsCount();
86
87     /**
88      * @throws HistoryException on error
89      */
90     int getHistoryVisitCounter(const std::string & url);
91
92     void setStorageServiceTestMode(bool testmode = true);
93
94     boost::signals2::signal<void (bool)>historyEmpty;
95     boost::signals2::signal<void (std::shared_ptr<tizen_browser::services::HistoryItem>)> historyAdded;
96     boost::signals2::signal<void (const std::string& uri)> historyDeleted;
97     boost::signals2::signal<void ()> historyAllDeleted;
98
99 private:
100     bool m_testDbMod;;
101     std::vector<std::shared_ptr<HistoryItem>> history_list;
102     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
103
104     /**
105      * @throws StorageExceptionInitialization on error
106      */
107     void initDatabaseBookmark(const std::string & db_str);
108
109     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
110
111 };
112
113 }
114 }
115
116 #endif