f8e10e124ec82fd1153e60bdfef22425bdcc9de6
[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 "StorageService.h"
30 #include <web/web_history.h>
31 #define DOMAIN_HISTORY_SERVICE "org.tizen.browser.historyservice"
32
33 namespace tizen_browser
34 {
35 namespace services
36 {
37
38 class BROWSER_EXPORT HistoryService: public tizen_browser::core::AbstractService
39 {
40 public:
41     HistoryService();
42     virtual ~HistoryService();
43     virtual std::string getName();
44     int getHistoryId(const std::string & url);
45     void addHistoryItem(std::shared_ptr<HistoryItem> hi,
46                         std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail=std::shared_ptr<tizen_browser::tools::BrowserImage>());
47     void insertOrRefresh(std::shared_ptr<HistoryItem> hi);
48     void clearAllHistory();
49     void clearURLHistory(const std::string & url);
50     std::shared_ptr<HistoryItem> getHistoryItem(const std::string & url);
51     std::shared_ptr<HistoryItemVector> getHistoryAll();
52     std::shared_ptr<HistoryItemVector> getHistoryToday();
53     std::shared_ptr<HistoryItemVector> getHistoryYesterday();
54     std::shared_ptr<HistoryItemVector> getHistoryLastWeek();
55     std::shared_ptr<HistoryItemVector> getHistoryLastMonth();
56     std::shared_ptr<HistoryItemVector> getHistoryOlder();
57     std::shared_ptr<HistoryItem> getCurrentTab();
58     std::shared_ptr<HistoryItemVector> getMostVisitedHistoryItems();
59     std::shared_ptr<HistoryItemVector> getHistoryItemsByURL(const std::string & url, int maxItems);
60     int getHistoryItemsCount();
61     int getHistoryVisitCounter(const std::string & url);
62     void setStorageServiceTestMode(bool testmode = true);
63
64     boost::signals2::signal<void (bool)>historyEmpty;
65     boost::signals2::signal<void (std::shared_ptr<tizen_browser::services::HistoryItem>)> historyAdded;
66     boost::signals2::signal<void (const std::string& uri)> historyDeleted;
67     boost::signals2::signal<void ()> historyAllDeleted;
68
69 private:
70     bool m_testDbMod;;
71     std::vector<std::shared_ptr<HistoryItem>> history_list;
72     std::shared_ptr<tizen_browser::services::StorageService> m_storageManager;
73
74     /**
75      * @throws StorageExceptionInitialization on error
76      */
77     void initDatabaseBookmark(const std::string & db_str);
78
79     std::shared_ptr<HistoryItem> getHistoryItem(int* ids, int idNumber = 0);
80     std::shared_ptr<HistoryItemVector> getHistoryItems(bp_history_date_defs period = BP_HISTORY_DATE_TODAY);
81     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
82
83 };
84
85 }
86 }
87
88 #endif