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_HISTORY_ANDROID_BOOKMARK_MODEL_SQL_HANDLER_H_ 6 #define CHROME_BROWSER_HISTORY_ANDROID_BOOKMARK_MODEL_SQL_HANDLER_H_ 7 8 #include "chrome/browser/history/android/sql_handler.h" 9 10 class BookmarkModel; 11 class Profile; 12 13 namespace history { 14 15 class HistoryDatabase; 16 17 // The SQL handler for bookmarking_mapping table. 18 class BookmarkModelSQLHandler : public SQLHandler { 19 public: 20 explicit BookmarkModelSQLHandler(URLDatabase* url_database); 21 22 virtual ~BookmarkModelSQLHandler(); 23 24 // SQLHandler overrides: 25 virtual bool Update(const HistoryAndBookmarkRow& row, 26 const TableIDRows& ids_set) OVERRIDE; 27 virtual bool Delete(const TableIDRows& ids_set) OVERRIDE; 28 virtual bool Insert(HistoryAndBookmarkRow* row) OVERRIDE; 29 30 private: 31 // This class helps to modify the bookmark model in UI thread. 32 // The instance of this class is created in history thread and posted to 33 // UI thread to access the bookmark. All method must be run in UI thread. 34 class Task : public base::RefCountedThreadSafe<Task> { 35 public: 36 // |profile| is the profile whose BookmarkModel will be modified. 37 // 38 // As this class is instantiated in history thread, the |profile| will be 39 // checked to see if it is still valid in ProfileManger before it used to 40 // get bookmark model in UI thread; So we can make sure the bookmark model 41 // we working on is still valid at the time it is used. 42 Task(); 43 44 // Add the a bookmark with the given |url| to mobile folder. 45 void AddBookmarkToMobileFolder(const GURL& url, 46 const base::string16& title); 47 48 // Adds a bookmark with the given |url|, |title| and |parent_id|. 49 void AddBookmark(const GURL& url, 50 const base::string16& title, 51 int64 parent_id); 52 53 // Removes the bookmark with the given |url|. 54 void RemoveBookmark(const GURL& url); 55 56 // Updates the given bookmark's title. 57 void UpdateBookmarkTitle(const GURL& url, 58 const base::string16& title); 59 60 private: 61 friend class base::RefCountedThreadSafe<Task>; 62 ~Task(); 63 64 // Returns profile_'s BookmarkModel if the profile_ is valid. 65 BookmarkModel* GetBookmarkModel(); 66 67 DISALLOW_COPY_AND_ASSIGN(Task); 68 }; 69 70 URLDatabase* url_database_; 71 72 DISALLOW_COPY_AND_ASSIGN(BookmarkModelSQLHandler); 73 }; 74 75 } // namespace history. 76 77 #endif // CHROME_BROWSER_HISTORY_ANDROID_BOOKMARK_MODEL_SQL_HANDLER_H_ 78