15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_HISTORY_ANDROID_ANDROID_URLS_DATABASE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_HISTORY_ANDROID_ANDROID_URLS_DATABASE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "components/history/core/android/android_history_types.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace history { 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The table is used to stores the raw url which was passed in from 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ContentProvider APIs' client. 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Android BookmarmkCoulmns API allows the url without protocol like 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "www.bookmarks.com", but Chrome requires the url to be unique, like 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "http://www.bookmarks.com/". To support client queries by the orignal URL, 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the raw URL and corresponding URLID is stored in this table. 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Though the raw URL is stored. The 'www.bookmark.com' and 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 'http://www.bookmark.com' are still treated as the same URL, which means 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// if adding these two urls, the later one will fail. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AndroidURLsDatabase { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AndroidURLsDatabase(); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~AndroidURLsDatabase(); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Creates the android_urls table if it doesn't exist. Returns true if the 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // table was created or already exists. 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CreateAndroidURLsTable(); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Adds a new mapping between |raw_url| and |url_id|, returns the id if it 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // succeeds, otherwise 0 is returned. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AndroidURLID AddAndroidURLRow(const std::string& raw_url, URLID url_id); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Looks up the given |url_id| in android_urls table. Returns true if success, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and fill in the |row| if it not NULL, returns false if the |url_id| is not 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // found. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetAndroidURLRow(URLID url_id, AndroidURLRow* row); 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deletes the rows whose url_id is in |url_ids|. Returns true if all 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |url_ids| were found and deleted, otherwise false is returned. 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool DeleteAndroidURLRows(const std::vector<URLID>& url_ids); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deletes all the rows whose url_id doesn't exist in urls table. Returns true 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on success. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool DeleteUnusedAndroidURLs(); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the row of |id| with the given |raw_url| and |url_id|. Returns true 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on success. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool UpdateAndroidURLRow(AndroidURLID id, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string&raw_url, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLID url_id); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears all the rows in android_urls table, returns true on success, false 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on error. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool ClearAndroidURLRows(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Migrate from version 21 to 22. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool MigrateToVersion22(); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the database for the functions in this interface. The decendent of 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this class implements these functions to return its objects. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual sql::Connection& GetDB() = 0; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AndroidURLsDatabase); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace history 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_HISTORY_ANDROID_ANDROID_URLS_DATABASE_H_ 74