1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_SERVICE_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_SERVICE_H_ 7 8 #include <vector> 9 10 #include "base/strings/string16.h" 11 #include "url/gurl.h" 12 13 namespace content { 14 class BrowserContext; 15 } 16 17 // BookmarkService provides a thread safe view of bookmarks. It is used by 18 // HistoryBackend when it needs to determine the set of bookmarked URLs 19 // or if a URL is bookmarked. 20 // 21 // BookmarkService is owned by Profile and deleted when the Profile is deleted. 22 class BookmarkService { 23 public: 24 struct URLAndTitle { 25 GURL url; 26 base::string16 title; 27 }; 28 29 static BookmarkService* FromBrowserContext( 30 content::BrowserContext* browser_context); 31 32 // Returns true if the specified URL is bookmarked. 33 // 34 // If not on the main thread you *must* invoke BlockTillLoaded first. 35 virtual bool IsBookmarked(const GURL& url) = 0; 36 37 // Returns, by reference in |bookmarks|, the set of bookmarked urls and their 38 // titles. This returns the unique set of URLs. For example, if two bookmarks 39 // reference the same URL only one entry is added not matter the titles are 40 // same or not. 41 // 42 // If not on the main thread you *must* invoke BlockTillLoaded first. 43 virtual void GetBookmarks(std::vector<URLAndTitle>* bookmarks) = 0; 44 45 // Blocks until loaded. This is intended for usage on a thread other than 46 // the main thread. 47 virtual void BlockTillLoaded() = 0; 48 49 protected: 50 virtual ~BookmarkService() {} 51 }; 52 53 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_SERVICE_H_ 54