Implement the GlobalBrowsingHistory class to maintain the pages visited across all normal tabs and windows of one browser profile.
Every successfully loaded page in normal browsing mode creates a separate history entry containing its globally unique visit identifier, URL, title and visit time. Visits made in private browsing mode must not be stored.
Each returned history entry must use the following string format:
"visitId,url,title,visitedAt"
GlobalBrowsingHistory()
Creates an empty global browsing history.
void recordVisit(String visitId, String url, String title, long visitedAt, boolean privateVisit)
visitId: A globally unique identifier supplied for the visit.url: The URL of the successfully loaded page.title: The title of the page.visitedAt: The time at which the page was visited.privateVisit: Whether the visit occurred in private browsing mode.If privateVisit is false, save a new history entry using the supplied identifier. If it is true, do not save the entry.
List<String> getRecentHistory(int limit)
limit: The maximum number of history entries to return.Return at most limit entries ordered by visitedAt from greatest to smallest. If two entries have the same visit time, return the entry with the lexicographically smaller visitId first.
List<String> searchHistory(String query, long startTime, long endTime, int limit)
query: Text to find in the URL or title.startTime: The earliest allowed visit time.endTime: The latest allowed visit time.limit: The maximum number of matching entries to return.Return entries whose URL or title contains query, ignoring letter case, and whose visit time is within the inclusive range [startTime, endTime]. An empty query matches every stored entry within the requested range.
Order matching entries using the same rules as getRecentHistory.
boolean deleteVisit(String visitId)
visitId: The globally unique identifier of the visit to delete.Delete the specified entry and return true. Return false if the entry does not exist.
int deleteHistoryByUrl(String url)
url: The exact URL whose visits must be deleted.Delete every entry whose URL exactly matches url and return the number of deleted entries. URL comparison is case-sensitive.
int clearHistory(long startTime, long endTime)
startTime: The earliest visit time to delete.endTime: The latest visit time to delete.Delete every entry whose visit time is within the inclusive range [startTime, endTime] and return the number of deleted entries.
int clearAllHistory()
Delete every stored history entry and return the number of deleted entries.
visitId supplied to recordVisit is globally unique.recordVisit.100,000 method calls will be made.1 ≤ visitId.length() ≤ 100visitId is globally unique for every call to recordVisit.1 ≤ url.length() ≤ 2,0000 ≤ title.length() ≤ 5000 ≤ visitedAt ≤ 1,000,000,000,000,0000 ≤ startTime ≤ endTime ≤ 1,000,000,000,000,0001 ≤ limit ≤ 500Constructor: GlobalBrowsingHistory history = new GlobalBrowsingHistory()
Method call: history.recordVisit(visitId = "visit-1001", url = "https://docs.example.com", title = "Developer Docs", visitedAt = 100, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-1002", url = "https://news.example.com", title = "Morning News", visitedAt = 180, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-1003", url = "https://docs.example.com/guide", title = "Setup Guide", visitedAt = 140, privateVisit = false)
Output: No return value
Method call: history.getRecentHistory(limit = 2)
Output: ["visit-1002,https://news.example.com,Morning News,180", "visit-1003,https://docs.example.com/guide,Setup Guide,140"]
Constructor: GlobalBrowsingHistory history = new GlobalBrowsingHistory()
Method call: history.recordVisit(visitId = "visit-2001", url = "https://learn.example.com/java", title = "Java Course", visitedAt = 210, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-2002", url = "https://private.example.com", title = "Private Page", visitedAt = 220, privateVisit = true)
Output: No return value
Method call: history.recordVisit(visitId = "visit-2003", url = "https://learn.example.com/python", title = "Python Course", visitedAt = 230, privateVisit = false)
Output: No return value
Method call: history.searchHistory(query = "course", startTime = 200, endTime = 240, limit = 10)
Output: ["visit-2003,https://learn.example.com/python,Python Course,230", "visit-2001,https://learn.example.com/java,Java Course,210"]
Constructor: GlobalBrowsingHistory history = new GlobalBrowsingHistory()
Method call: history.recordVisit(visitId = "visit-3001", url = "https://shop.example.com", title = "Online Shop", visitedAt = 300, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-3002", url = "https://shop.example.com", title = "Online Shop", visitedAt = 320, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-3003", url = "https://pay.example.com", title = "Payment", visitedAt = 340, privateVisit = false)
Output: No return value
Method call: history.deleteVisit(visitId = "visit-3001")
Output: true
Method call: history.deleteHistoryByUrl(url = "https://shop.example.com")
Output: 1
Constructor: GlobalBrowsingHistory history = new GlobalBrowsingHistory()
Method call: history.recordVisit(visitId = "visit-4001", url = "https://alpha.example.com", title = "Alpha", visitedAt = 400, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-4002", url = "https://beta.example.com", title = "Beta", visitedAt = 500, privateVisit = false)
Output: No return value
Method call: history.recordVisit(visitId = "visit-4003", url = "https://gamma.example.com", title = "Gamma", visitedAt = 600, privateVisit = false)
Output: No return value
Method call: history.clearHistory(startTime = 450, endTime = 550)
Output: 1
Method call: history.clearAllHistory()
Output: 2