summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 15:35:25 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-23 15:35:25 +0000
commite5366896e9ccb3dd17c590d115bd999e987a33af (patch)
tree52f4fc2f07b73aaca1199adb1384b123130c22ed /chrome/browser/history
parentb133cc2db84fc83d5c4aa53020237788fa344c75 (diff)
downloadchromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.zip
chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.gz
chromium_src-e5366896e9ccb3dd17c590d115bd999e987a33af.tar.bz2
Replace wstring with string16 in history. The only time wstring is used now in history is for bookmark-related stuff (the bookmarks system is still wstring-based).
The substantial change here is in RTL to make a string16 variant of the functions and in changing the WordIterator to use string16 (this cleaned up some weird utf-32 code). TEST=none BUG=none Review URL: http://codereview.chromium.org/2808017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/download_database.cc11
-rw-r--r--chrome/browser/history/download_database.h7
-rw-r--r--chrome/browser/history/expire_history_backend_unittest.cc14
-rw-r--r--chrome/browser/history/history.cc14
-rw-r--r--chrome/browser/history/history.h21
-rw-r--r--chrome/browser/history/history_backend.cc14
-rw-r--r--chrome/browser/history/history_backend.h14
-rw-r--r--chrome/browser/history/history_backend_unittest.cc9
-rw-r--r--chrome/browser/history/history_publisher.cc5
-rw-r--r--chrome/browser/history/history_publisher.h2
-rw-r--r--chrome/browser/history/history_querying_unittest.cc58
-rw-r--r--chrome/browser/history/history_types.h11
-rw-r--r--chrome/browser/history/history_unittest.cc6
-rw-r--r--chrome/browser/history/query_parser.cc75
-rw-r--r--chrome/browser/history/query_parser.h36
-rw-r--r--chrome/browser/history/query_parser_unittest.cc130
-rw-r--r--chrome/browser/history/redirect_uitest.cc11
-rw-r--r--chrome/browser/history/snippet.cc40
-rw-r--r--chrome/browser/history/snippet.h7
-rw-r--r--chrome/browser/history/snippet_unittest.cc38
-rw-r--r--chrome/browser/history/starred_url_database.cc12
-rw-r--r--chrome/browser/history/starred_url_database.h7
-rw-r--r--chrome/browser/history/starred_url_database_unittest.cc2
-rw-r--r--chrome/browser/history/text_database.cc2
-rw-r--r--chrome/browser/history/text_database.h3
-rw-r--r--chrome/browser/history/text_database_manager.cc25
-rw-r--r--chrome/browser/history/text_database_manager.h13
-rw-r--r--chrome/browser/history/text_database_manager_unittest.cc94
-rw-r--r--chrome/browser/history/text_database_unittest.cc12
-rw-r--r--chrome/browser/history/url_database.cc26
-rw-r--r--chrome/browser/history/url_database.h8
-rw-r--r--chrome/browser/history/url_database_unittest.cc23
32 files changed, 392 insertions, 358 deletions
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index ea0649d..26780ad 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +9,7 @@
#include "app/sql/connection.h"
#include "app/sql/statement.h"
+#include "base/file_path.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_manager.h"
@@ -122,7 +123,7 @@ bool DownloadDatabase::UpdateDownload(int64 received_bytes,
return statement.Run();
}
-bool DownloadDatabase::UpdateDownloadPath(const std::wstring& path,
+bool DownloadDatabase::UpdateDownloadPath(const FilePath& path,
DownloadID db_handle) {
DCHECK(db_handle > 0);
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
@@ -130,7 +131,7 @@ bool DownloadDatabase::UpdateDownloadPath(const std::wstring& path,
if (!statement)
return false;
- statement.BindString(0, WideToUTF8(path));
+ BindFilePath(statement, path, 0);
statement.BindInt64(1, db_handle);
return statement.Run();
}
@@ -197,7 +198,7 @@ void DownloadDatabase::RemoveDownloadsBetween(base::Time delete_begin,
}
void DownloadDatabase::SearchDownloads(std::vector<int64>* results,
- const std::wstring& search_text) {
+ const string16& search_text) {
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"SELECT id FROM downloads WHERE url LIKE ? "
"OR full_path LIKE ? ORDER BY id"));
@@ -205,7 +206,7 @@ void DownloadDatabase::SearchDownloads(std::vector<int64>* results,
return;
std::string text("%");
- text.append(WideToUTF8(search_text));
+ text.append(UTF16ToUTF8(search_text));
text.push_back('%');
statement.BindString(0, text);
statement.BindString(1, text);
diff --git a/chrome/browser/history/download_database.h b/chrome/browser/history/download_database.h
index 8ba2e7a..11adf31 100644
--- a/chrome/browser/history/download_database.h
+++ b/chrome/browser/history/download_database.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include "chrome/browser/history/history_types.h"
struct DownloadCreateInfo;
+class FilePath;
namespace sql {
class Connection;
@@ -29,7 +30,7 @@ class DownloadDatabase {
bool UpdateDownload(int64 received_bytes, int32 state, DownloadID db_handle);
// Update the path of one download. Returns true if successful.
- bool UpdateDownloadPath(const std::wstring& path, DownloadID db_handle);
+ bool UpdateDownloadPath(const FilePath& path, DownloadID db_handle);
// Fixes state of the download entries. Sometimes entries with IN_PROGRESS
// state are not updated during browser shutdown (particularly when crashing).
@@ -51,7 +52,7 @@ class DownloadDatabase {
// Search for downloads matching the search text.
void SearchDownloads(std::vector<int64>* results,
- const std::wstring& search_text);
+ const string16& search_text);
protected:
// Returns the database for the functions in this interface.
diff --git a/chrome/browser/history/expire_history_backend_unittest.cc b/chrome/browser/history/expire_history_backend_unittest.cc
index 927ba5c..ca822bc 100644
--- a/chrome/browser/history/expire_history_backend_unittest.cc
+++ b/chrome/browser/history/expire_history_backend_unittest.cc
@@ -243,17 +243,20 @@ void ExpireHistoryTest::AddExampleData(URLID url_ids[3], Time visit_times[4]) {
// Full text index for each visit.
text_db_->AddPageData(url_row1.url(), visit_row1.url_id, visit_row1.visit_id,
- visit_row1.visit_time, L"title", UTF8ToUTF16("body"));
+ visit_row1.visit_time, UTF8ToUTF16("title"),
+ UTF8ToUTF16("body"));
text_db_->AddPageData(url_row2.url(), visit_row2.url_id, visit_row2.visit_id,
- visit_row2.visit_time, L"title", UTF8ToUTF16("body"));
+ visit_row2.visit_time, UTF8ToUTF16("title"),
+ UTF8ToUTF16("body"));
text_db_->AddPageData(url_row2.url(), visit_row3.url_id, visit_row3.visit_id,
- visit_row3.visit_time, L"title", UTF8ToUTF16("body"));
+ visit_row3.visit_time, UTF8ToUTF16("title"),
+ UTF8ToUTF16("body"));
// Note the special text in this URL. We'll search the file for this string
// to make sure it doesn't hang around after the delete.
text_db_->AddPageData(url_row3.url(), visit_row4.url_id, visit_row4.visit_id,
- visit_row4.visit_time, L"title",
+ visit_row4.visit_time, UTF8ToUTF16("title"),
UTF8ToUTF16("goats body"));
}
@@ -280,7 +283,8 @@ int ExpireHistoryTest::CountTextMatchesForURL(const GURL& url) {
std::vector<TextDatabase::Match> results;
QueryOptions options;
Time first_time;
- text_db_->GetTextMatches(L"body", options, &results, &first_time);
+ text_db_->GetTextMatches(UTF8ToUTF16("body"), options,
+ &results, &first_time);
int count = 0;
for (size_t i = 0; i < results.size(); i++) {
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index d115795..c692963 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -224,7 +224,7 @@ void HistoryService::SetSegmentPresentationIndex(int64 segment_id, int index) {
void HistoryService::SetKeywordSearchTermsForURL(const GURL& url,
TemplateURL::IDType keyword_id,
- const std::wstring& term) {
+ const string16& term) {
ScheduleAndForget(PRIORITY_UI,
&HistoryBackend::SetKeywordSearchTermsForURL,
url, keyword_id, term);
@@ -239,7 +239,7 @@ void HistoryService::DeleteAllSearchTermsForKeyword(
HistoryService::Handle HistoryService::GetMostRecentKeywordSearchTerms(
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count,
CancelableRequestConsumerBase* consumer,
GetMostRecentKeywordSearchTermsCallback* callback) {
@@ -331,12 +331,12 @@ void HistoryService::AddPage(const GURL& url,
}
void HistoryService::SetPageTitle(const GURL& url,
- const std::wstring& title) {
+ const string16& title) {
ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::SetPageTitle, url, title);
}
void HistoryService::AddPageWithDetails(const GURL& url,
- const std::wstring& title,
+ const string16& title,
int visit_count,
int typed_count,
Time last_visit,
@@ -504,7 +504,7 @@ void HistoryService::UpdateDownload(int64 received_bytes,
received_bytes, state, db_handle);
}
-void HistoryService::UpdateDownloadPath(const std::wstring& path,
+void HistoryService::UpdateDownloadPath(const FilePath& path,
int64 db_handle) {
ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::UpdateDownloadPath,
path, db_handle);
@@ -524,7 +524,7 @@ void HistoryService::RemoveDownloadsBetween(Time remove_begin,
}
HistoryService::Handle HistoryService::SearchDownloads(
- const std::wstring& search_text,
+ const string16& search_text,
CancelableRequestConsumerBase* consumer,
DownloadSearchCallback* callback) {
return Schedule(PRIORITY_NORMAL, &HistoryBackend::SearchDownloads, consumer,
@@ -532,7 +532,7 @@ HistoryService::Handle HistoryService::SearchDownloads(
}
HistoryService::Handle HistoryService::QueryHistory(
- const std::wstring& text_query,
+ const string16& text_query,
const history::QueryOptions& options,
CancelableRequestConsumerBase* consumer,
QueryHistoryCallback* callback) {
diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h
index 8e68a86..e9abbac 100644
--- a/chrome/browser/history/history.h
+++ b/chrome/browser/history/history.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_HISTORY_HISTORY_H__
-#define CHROME_BROWSER_HISTORY_HISTORY_H__
+#ifndef CHROME_BROWSER_HISTORY_HISTORY_H_
+#define CHROME_BROWSER_HISTORY_HISTORY_H_
#include <string>
#include <vector>
@@ -13,6 +13,7 @@
#include "base/file_path.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "base/string16.h"
#include "base/task.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/favicon_service.h"
@@ -204,7 +205,7 @@ class HistoryService : public CancelableRequestProvider,
// is not, this operation is ignored. This call will not update the full
// text index. The last title set when the page is indexed will be the
// title in the full text index.
- void SetPageTitle(const GURL& url, const std::wstring& title);
+ void SetPageTitle(const GURL& url, const string16& title);
// Indexing ------------------------------------------------------------------
@@ -274,7 +275,7 @@ class HistoryService : public CancelableRequestProvider,
//
// This isn't totally hooked up yet, this will query the "new" full text
// database (see SetPageContents) which won't generally be set yet.
- Handle QueryHistory(const std::wstring& text_query,
+ Handle QueryHistory(const string16& text_query,
const history::QueryOptions& options,
CancelableRequestConsumerBase* consumer,
QueryHistoryCallback* callback);
@@ -428,7 +429,7 @@ class HistoryService : public CancelableRequestProvider,
// Called to update the history service about the path of a download.
// This is a 'fire and forget' query.
- void UpdateDownloadPath(const std::wstring& path, int64 db_handle);
+ void UpdateDownloadPath(const FilePath& path, int64 db_handle);
// Permanently remove a download from the history system. This is a 'fire and
// forget' operation.
@@ -446,7 +447,7 @@ class HistoryService : public CancelableRequestProvider,
typedef Callback2<Handle, std::vector<int64>*>::Type DownloadSearchCallback;
// Search for downloads that match the search text.
- Handle SearchDownloads(const std::wstring& search_text,
+ Handle SearchDownloads(const string16& search_text,
CancelableRequestConsumerBase* consumer,
DownloadSearchCallback* callback);
@@ -482,7 +483,7 @@ class HistoryService : public CancelableRequestProvider,
// id of the url, keyword_id the id of the keyword and term the search term.
void SetKeywordSearchTermsForURL(const GURL& url,
TemplateURL::IDType keyword_id,
- const std::wstring& term);
+ const string16& term);
// Deletes all search terms for the specified keyword.
void DeleteAllSearchTermsForKeyword(TemplateURL::IDType keyword_id);
@@ -496,7 +497,7 @@ class HistoryService : public CancelableRequestProvider,
// first.
Handle GetMostRecentKeywordSearchTerms(
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count,
CancelableRequestConsumerBase* consumer,
GetMostRecentKeywordSearchTermsCallback* callback);
@@ -536,7 +537,7 @@ class HistoryService : public CancelableRequestProvider,
// transaction. If this functionality is needed for importing many URLs, a
// version that takes an array should probably be added.
void AddPageWithDetails(const GURL& url,
- const std::wstring& title,
+ const string16& title,
int visit_count,
int typed_count,
base::Time last_visit,
@@ -840,4 +841,4 @@ class HistoryService : public CancelableRequestProvider,
DISALLOW_COPY_AND_ASSIGN(HistoryService);
};
-#endif // CHROME_BROWSER_HISTORY_HISTORY_H__
+#endif // CHROME_BROWSER_HISTORY_HISTORY_H_
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index a001233..2e57b46 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -792,7 +792,7 @@ void HistoryBackend::AddPagesWithDetails(const std::vector<URLRow>& urls) {
}
void HistoryBackend::SetPageTitle(const GURL& url,
- const std::wstring& title) {
+ const string16& title) {
if (!db_.get())
return;
@@ -1005,7 +1005,7 @@ void HistoryBackend::QuerySegmentUsage(
void HistoryBackend::SetKeywordSearchTermsForURL(const GURL& url,
TemplateURL::IDType keyword_id,
- const std::wstring& term) {
+ const string16& term) {
if (!db_.get())
return;
@@ -1034,7 +1034,7 @@ void HistoryBackend::DeleteAllSearchTermsForKeyword(
void HistoryBackend::GetMostRecentKeywordSearchTerms(
scoped_refptr<GetMostRecentKeywordSearchTermsRequest> request,
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count) {
if (request->canceled())
return;
@@ -1078,7 +1078,7 @@ void HistoryBackend::UpdateDownload(int64 received_bytes,
}
// Update the path of a particular download entry.
-void HistoryBackend::UpdateDownloadPath(const std::wstring& path,
+void HistoryBackend::UpdateDownloadPath(const FilePath& path,
int64 db_handle) {
if (db_.get())
db_->UpdateDownloadPath(path, db_handle);
@@ -1110,7 +1110,7 @@ void HistoryBackend::RemoveDownloadsBetween(const Time remove_begin,
void HistoryBackend::SearchDownloads(
scoped_refptr<DownloadSearchRequest> request,
- const std::wstring& search_text) {
+ const string16& search_text) {
if (request->canceled())
return;
if (db_.get())
@@ -1120,7 +1120,7 @@ void HistoryBackend::SearchDownloads(
}
void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request,
- const std::wstring& text_query,
+ const string16& text_query,
const QueryOptions& options) {
if (request->canceled())
return;
@@ -1196,7 +1196,7 @@ void HistoryBackend::QueryHistoryBasic(URLDatabase* url_db,
result->set_reached_beginning(true);
}
-void HistoryBackend::QueryHistoryFTS(const std::wstring& text_query,
+void HistoryBackend::QueryHistoryFTS(const string16& text_query,
const QueryOptions& options,
QueryResults* result) {
if (!text_database_.get())
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index 386f393..37bc80e 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -112,7 +112,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Navigation ----------------------------------------------------------------
void AddPage(scoped_refptr<HistoryAddPageArgs> request);
- virtual void SetPageTitle(const GURL& url, const std::wstring& title);
+ virtual void SetPageTitle(const GURL& url, const string16& title);
// Indexing ------------------------------------------------------------------
@@ -131,7 +131,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
const GURL& url,
bool want_visits);
void QueryHistory(scoped_refptr<QueryHistoryRequest> request,
- const std::wstring& text_query,
+ const string16& text_query,
const QueryOptions& options);
void QueryRedirectsFrom(scoped_refptr<QueryRedirectsRequest> request,
const GURL& url);
@@ -212,7 +212,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
void QueryDownloads(scoped_refptr<DownloadQueryRequest> request);
void CleanUpInProgressEntries();
void UpdateDownload(int64 received_bytes, int32 state, int64 db_handle);
- void UpdateDownloadPath(const std::wstring& path, int64 db_handle);
+ void UpdateDownloadPath(const FilePath& path, int64 db_handle);
void CreateDownload(scoped_refptr<DownloadCreateRequest> request,
const DownloadCreateInfo& info);
void RemoveDownload(int64 db_handle);
@@ -220,7 +220,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
const base::Time remove_end);
void RemoveDownloads(const base::Time remove_end);
void SearchDownloads(scoped_refptr<DownloadSearchRequest>,
- const std::wstring& search_text);
+ const string16& search_text);
// Segment usage -------------------------------------------------------------
@@ -234,14 +234,14 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
void SetKeywordSearchTermsForURL(const GURL& url,
TemplateURL::IDType keyword_id,
- const std::wstring& term);
+ const string16& term);
void DeleteAllSearchTermsForKeyword(TemplateURL::IDType keyword_id);
void GetMostRecentKeywordSearchTerms(
scoped_refptr<GetMostRecentKeywordSearchTermsRequest> request,
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count);
// Generic operations --------------------------------------------------------
@@ -360,7 +360,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Both functions assume QueryHistory already checked the DB for validity.
void QueryHistoryBasic(URLDatabase* url_db, VisitDatabase* visit_db,
const QueryOptions& options, QueryResults* result);
- void QueryHistoryFTS(const std::wstring& text_query,
+ void QueryHistoryFTS(const string16& text_query,
const QueryOptions& options,
QueryResults* result);
diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc
index 1628d76..4d1dca6 100644
--- a/chrome/browser/history/history_backend_unittest.cc
+++ b/chrome/browser/history/history_backend_unittest.cc
@@ -250,10 +250,12 @@ TEST_F(HistoryBackendTest, DeleteAll) {
// Set full text index for each one.
backend_->text_database_->AddPageData(row1.url(), row1_id, visit1_id,
row1.last_visit(),
- L"Title 1", UTF8ToUTF16("Body 1"));
+ UTF8ToUTF16("Title 1"),
+ UTF8ToUTF16("Body 1"));
backend_->text_database_->AddPageData(row2.url(), row2_id, visit2_id,
row2.last_visit(),
- L"Title 2", UTF8ToUTF16("Body 2"));
+ UTF8ToUTF16("Title 2"),
+ UTF8ToUTF16("Body 2"));
// Now finally clear all history.
backend_->DeleteAllHistory();
@@ -298,7 +300,8 @@ TEST_F(HistoryBackendTest, DeleteAll) {
// The full text database should have no data.
std::vector<TextDatabase::Match> text_matches;
Time first_time_searched;
- backend_->text_database_->GetTextMatches(L"Body", QueryOptions(),
+ backend_->text_database_->GetTextMatches(UTF8ToUTF16("Body"),
+ QueryOptions(),
&text_matches,
&first_time_searched);
EXPECT_EQ(0U, text_matches.size());
diff --git a/chrome/browser/history/history_publisher.cc b/chrome/browser/history/history_publisher.cc
index 2c70a31..0392632 100644
--- a/chrome/browser/history/history_publisher.cc
+++ b/chrome/browser/history/history_publisher.cc
@@ -27,14 +27,15 @@ void HistoryPublisher::PublishPageThumbnail(
void HistoryPublisher::PublishPageContent(const base::Time& time,
const GURL& url,
- const std::wstring& title,
+ const string16& title,
const string16& contents) const {
+ std::wstring wide_title = UTF16ToWide(title);
std::wstring wide_contents = UTF16ToWide(contents);
PageData page_data = {
time,
url,
wide_contents.c_str(),
- title.c_str(),
+ wide_title.c_str(),
NULL,
NULL,
};
diff --git a/chrome/browser/history/history_publisher.h b/chrome/browser/history/history_publisher.h
index c7a3530..5fafc3e 100644
--- a/chrome/browser/history/history_publisher.h
+++ b/chrome/browser/history/history_publisher.h
@@ -37,7 +37,7 @@ class HistoryPublisher {
void PublishPageThumbnail(const std::vector<unsigned char>& thumbnail,
const GURL& url, const base::Time& time) const;
void PublishPageContent(const base::Time& time, const GURL& url,
- const std::wstring& title,
+ const string16& title,
const string16& contents) const;
void DeleteUserHistoryBetween(const base::Time& begin_time,
const base::Time& end_time) const;
diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc
index 1265eef..7512786 100644
--- a/chrome/browser/history/history_querying_unittest.cc
+++ b/chrome/browser/history/history_querying_unittest.cc
@@ -22,27 +22,27 @@ namespace {
struct TestEntry {
const char* url;
- const wchar_t* title;
+ const char* title;
const int days_ago;
const char* body;
Time time; // Filled by SetUp.
} test_entries[] = {
// This one is visited super long ago so it will be in a different database
// from the next appearance of it at the end.
- {"http://example.com/", L"Other", 180, "Other"},
+ {"http://example.com/", "Other", 180, "Other"},
// These are deliberately added out of chronological order. The history
// service should sort them by visit time when returning query results.
// The correct index sort order is 4 2 3 1 0.
- {"http://www.google.com/1", L"Title 1", 10,
+ {"http://www.google.com/1", "Title 1", 10,
"PAGEONE FOO some body text"},
- {"http://www.google.com/3", L"Title 3", 8,
+ {"http://www.google.com/3", "Title 3", 8,
"PAGETHREE BAR some hello world for you"},
- {"http://www.google.com/2", L"Title 2", 9,
+ {"http://www.google.com/2", "Title 2", 9,
"PAGETWO FOO some more blah blah blah"},
// A more recent visit of the first one.
- {"http://example.com/", L"Other", 6, "Other"},
+ {"http://example.com/", "Other", 6, "Other"},
};
// Returns true if the nth result in the given results set matches. It will
@@ -61,7 +61,7 @@ bool NthResultIs(const QueryResults& results,
// Now check the URL & title.
return result.url() == GURL(test_entries[test_entry_index].url) &&
- result.title() == std::wstring(test_entries[test_entry_index].title);
+ result.title() == UTF8ToUTF16(test_entries[test_entry_index].title);
}
} // namespace
@@ -72,10 +72,10 @@ class HistoryQueryTest : public testing::Test {
}
// Acts like a synchronous call to history's QueryHistory.
- void QueryHistory(const std::wstring& text_query,
+ void QueryHistory(const std::string& text_query,
const QueryOptions& options,
QueryResults* results) {
- history_->QueryHistory(text_query, options, &consumer_,
+ history_->QueryHistory(UTF8ToUTF16(text_query), options, &consumer_,
NewCallback(this, &HistoryQueryTest::QueryHistoryComplete));
MessageLoop::current()->Run(); // Will go until ...Complete calls Quit.
results->Swap(&last_query_results_);
@@ -112,7 +112,7 @@ class HistoryQueryTest : public testing::Test {
history_->AddPage(url, test_entries[i].time, id_scope, page_id, GURL(),
PageTransition::LINK, history::RedirectList(),
false);
- history_->SetPageTitle(url, test_entries[i].title);
+ history_->SetPageTitle(url, UTF8ToUTF16(test_entries[i].title));
history_->SetPageContents(url, UTF8ToUTF16(test_entries[i].body));
}
}
@@ -152,7 +152,7 @@ TEST_F(HistoryQueryTest, Basic) {
QueryResults results;
// Test duplicate collapsing.
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_EQ(4U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 4));
EXPECT_TRUE(NthResultIs(results, 1, 2));
@@ -163,7 +163,7 @@ TEST_F(HistoryQueryTest, Basic) {
// should be exclusive.
options.begin_time = test_entries[3].time;
options.end_time = test_entries[2].time;
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_EQ(1U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 3));
}
@@ -178,7 +178,7 @@ TEST_F(HistoryQueryTest, BasicCount) {
// Query all time but with a limit on the number of entries. We should
// get the N most recent entries.
options.max_count = 2;
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_EQ(2U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 4));
EXPECT_TRUE(NthResultIs(results, 1, 2));
@@ -190,23 +190,23 @@ TEST_F(HistoryQueryTest, ReachedBeginning) {
QueryOptions options;
QueryResults results;
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_TRUE(results.reached_beginning());
options.begin_time = test_entries[1].time;
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_FALSE(results.reached_beginning());
options.begin_time = test_entries[0].time + TimeDelta::FromMicroseconds(1);
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_FALSE(results.reached_beginning());
options.begin_time = test_entries[0].time;
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_TRUE(results.reached_beginning());
options.begin_time = test_entries[0].time - TimeDelta::FromMicroseconds(1);
- QueryHistory(std::wstring(), options, &results);
+ QueryHistory(std::string(), options, &results);
EXPECT_TRUE(results.reached_beginning());
}
@@ -221,14 +221,14 @@ TEST_F(HistoryQueryTest, FTS) {
// Query all of them to make sure they are there and in order. Note that
// this query will return the starred item twice since we requested all
// starred entries and no de-duping.
- QueryHistory(std::wstring(L"some"), options, &results);
+ QueryHistory("some", options, &results);
EXPECT_EQ(3U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 2));
EXPECT_TRUE(NthResultIs(results, 1, 3));
EXPECT_TRUE(NthResultIs(results, 2, 1));
// Do a query that should only match one of them.
- QueryHistory(std::wstring(L"PAGETWO"), options, &results);
+ QueryHistory("PAGETWO", options, &results);
EXPECT_EQ(1U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 3));
@@ -236,7 +236,7 @@ TEST_F(HistoryQueryTest, FTS) {
// should be exclusive.
options.begin_time = test_entries[1].time;
options.end_time = test_entries[3].time;
- QueryHistory(std::wstring(L"some"), options, &results);
+ QueryHistory("some", options, &results);
EXPECT_EQ(1U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 1));
}
@@ -250,7 +250,7 @@ TEST_F(HistoryQueryTest, FTSTitle) {
// Query all time but with a limit on the number of entries. We should
// get the N most recent entries.
- QueryHistory(std::wstring(L"title"), options, &results);
+ QueryHistory("title", options, &results);
EXPECT_EQ(3U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 2));
EXPECT_TRUE(NthResultIs(results, 1, 3));
@@ -266,7 +266,7 @@ TEST_F(HistoryQueryTest, FTSPrefix) {
// Query with a prefix search. Should return matches for "PAGETWO" and
// "PAGETHREE".
- QueryHistory(std::wstring(L"PAGET"), options, &results);
+ QueryHistory("PAGET", options, &results);
EXPECT_EQ(2U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 2));
EXPECT_TRUE(NthResultIs(results, 1, 3));
@@ -282,7 +282,7 @@ TEST_F(HistoryQueryTest, FTSCount) {
// Query all time but with a limit on the number of entries. We should
// get the N most recent entries.
options.max_count = 2;
- QueryHistory(std::wstring(L"some"), options, &results);
+ QueryHistory("some", options, &results);
EXPECT_EQ(2U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 2));
EXPECT_TRUE(NthResultIs(results, 1, 3));
@@ -291,7 +291,7 @@ TEST_F(HistoryQueryTest, FTSCount) {
// the 2nd & 3rd pages, but we should only get the 3rd one because of the one
// page max restriction.
options.max_count = 1;
- QueryHistory(std::wstring(L"FOO"), options, &results);
+ QueryHistory("FOO", options, &results);
EXPECT_EQ(1U, results.size());
EXPECT_TRUE(NthResultIs(results, 0, 3));
}
@@ -305,12 +305,12 @@ TEST_F(HistoryQueryTest, FTSArchived) {
std::vector<URLRow> urls_to_add;
URLRow row1(GURL("http://foo.bar/"));
- row1.set_title(L"archived title");
+ row1.set_title(UTF8ToUTF16("archived title"));
row1.set_last_visit(Time::Now() - TimeDelta::FromDays(365));
urls_to_add.push_back(row1);
URLRow row2(GURL("http://foo.bar/"));
- row2.set_title(L"nonarchived title");
+ row2.set_title(UTF8ToUTF16("nonarchived title"));
row2.set_last_visit(Time::Now());
urls_to_add.push_back(row2);
@@ -322,7 +322,7 @@ TEST_F(HistoryQueryTest, FTSArchived) {
// Query all time. The title we get should be the one in the full text
// database and not the most current title (since otherwise highlighting in
// the title might be wrong).
- QueryHistory(std::wstring(L"archived"), options, &results);
+ QueryHistory("archived", options, &results);
ASSERT_EQ(1U, results.size());
EXPECT_TRUE(row1.url() == results[0].url());
EXPECT_TRUE(row1.title() == results[0].title());
@@ -341,7 +341,7 @@ TEST_F(HistoryQueryTest, FTSDupes) {
QueryOptions options;
QueryResults results;
- QueryHistory(std::wstring(L"Other"), options, &results);
+ QueryHistory("Other", options, &results);
EXPECT_EQ(1, results.urls().size());
EXPECT_TRUE(NthResultIs(results, 0, 4));
}
diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h
index 1d45f6c..f7bc7fb 100644
--- a/chrome/browser/history/history_types.h
+++ b/chrome/browser/history/history_types.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/stack_container.h"
+#include "base/string16.h"
#include "base/time.h"
#include "chrome/browser/history/snippet.h"
#include "chrome/common/page_transition_types.h"
@@ -78,10 +79,10 @@ class URLRow {
URLID id() const { return id_; }
const GURL& url() const { return url_; }
- const std::wstring& title() const {
+ const string16& title() const {
return title_;
}
- void set_title(const std::wstring& title) {
+ void set_title(const string16& title) {
// The title is frequently set to the same thing, so we don't bother
// updating unless the string has changed.
if (title != title_) {
@@ -149,7 +150,7 @@ class URLRow {
// the constructor to make a new one.
GURL url_;
- std::wstring title_;
+ string16 title_;
// Total number of times this URL has been visited.
int visit_count_;
@@ -283,7 +284,7 @@ struct StarredEntry {
StarID id;
// Title.
- std::wstring title;
+ string16 title;
// When this was added.
base::Time date_added;
@@ -506,7 +507,7 @@ struct KeywordSearchTermVisit {
base::Time time;
// The search term that was used.
- std::wstring term;
+ string16 term;
};
// MostVisitedURL --------------------------------------------------------------
diff --git a/chrome/browser/history/history_unittest.cc b/chrome/browser/history/history_unittest.cc
index be0cd0a..a0e6e21 100644
--- a/chrome/browser/history/history_unittest.cc
+++ b/chrome/browser/history/history_unittest.cc
@@ -594,7 +594,7 @@ TEST_F(HistoryTest, SetTitle) {
history->AddPage(existing_url);
// Set some title.
- const std::wstring existing_title(L"Google");
+ const string16 existing_title = UTF8ToUTF16("Google");
history->SetPageTitle(existing_url, existing_title);
// Make sure the title got set.
@@ -603,12 +603,12 @@ TEST_F(HistoryTest, SetTitle) {
// set a title on a nonexistent page
const GURL nonexistent_url("http://news.google.com/");
- const std::wstring nonexistent_title(L"Google News");
+ const string16 nonexistent_title = UTF8ToUTF16("Google News");
history->SetPageTitle(nonexistent_url, nonexistent_title);
// Make sure nothing got written.
EXPECT_FALSE(QueryURL(history, nonexistent_url));
- EXPECT_EQ(std::wstring(), query_url_row_.title());
+ EXPECT_EQ(string16(), query_url_row_.title());
// TODO(brettw) this should also test redirects, which get the title of the
// destination page.
diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc
index 6bfaa7f..e1afb86 100644
--- a/chrome/browser/history/query_parser.cc
+++ b/chrome/browser/history/query_parser.cc
@@ -1,16 +1,17 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <algorithm>
-
#include "chrome/browser/history/query_parser.h"
+#include <algorithm>
+
#include "app/l10n_util.h"
#include "base/i18n/word_iterator.h"
#include "base/logging.h"
#include "base/scoped_vector.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "unicode/uscript.h"
namespace {
@@ -56,7 +57,7 @@ void CoalseAndSortMatchPositions(Snippet::MatchPositions* matches) {
CoalesceMatchesFrom(i, matches);
}
-} // namespace
+} // namespace
// Inheritance structure:
// Queries are represented as trees of QueryNodes.
@@ -66,23 +67,23 @@ void CoalseAndSortMatchPositions(Snippet::MatchPositions* matches) {
// A QueryNodeWord is a single word in the query.
class QueryNodeWord : public QueryNode {
public:
- explicit QueryNodeWord(const std::wstring& word)
+ explicit QueryNodeWord(const string16& word)
: word_(word), literal_(false) {}
virtual ~QueryNodeWord() {}
- virtual int AppendToSQLiteQuery(std::wstring* query) const;
+ virtual int AppendToSQLiteQuery(string16* query) const;
virtual bool IsWord() const { return true; }
- const std::wstring& word() const { return word_; }
+ const string16& word() const { return word_; }
void set_literal(bool literal) { literal_ = literal; }
virtual bool HasMatchIn(const std::vector<QueryWord>& words,
Snippet::MatchPositions* match_positions) const;
- virtual bool Matches(const std::wstring& word, bool exact) const;
- virtual void AppendWords(std::vector<std::wstring>* words) const;
+ virtual bool Matches(const string16& word, bool exact) const;
+ virtual void AppendWords(std::vector<string16>* words) const;
private:
- std::wstring word_;
+ string16 word_;
bool literal_;
};
@@ -100,18 +101,18 @@ bool QueryNodeWord::HasMatchIn(const std::vector<QueryWord>& words,
return false;
}
-bool QueryNodeWord::Matches(const std::wstring& word, bool exact) const {
+bool QueryNodeWord::Matches(const string16& word, bool exact) const {
if (exact || !QueryParser::IsWordLongEnoughForPrefixSearch(word_))
return word == word_;
return word.size() >= word_.size() &&
(word_.compare(0, word_.size(), word, 0, word_.size()) == 0);
}
-void QueryNodeWord::AppendWords(std::vector<std::wstring>* words) const {
+void QueryNodeWord::AppendWords(std::vector<string16>* words) const {
words->push_back(word_);
}
-int QueryNodeWord::AppendToSQLiteQuery(std::wstring* query) const {
+int QueryNodeWord::AppendToSQLiteQuery(string16* query) const {
query->append(word_);
// Use prefix search if we're not literal and long enough.
@@ -126,7 +127,7 @@ class QueryNodeList : public QueryNode {
public:
virtual ~QueryNodeList();
- virtual int AppendToSQLiteQuery(std::wstring* query) const {
+ virtual int AppendToSQLiteQuery(string16* query) const {
return AppendChildrenToString(query);
}
virtual bool IsWord() const { return false; }
@@ -140,7 +141,7 @@ class QueryNodeList : public QueryNode {
void RemoveEmptySubnodes();
// QueryNodeList is never used with Matches or HasMatchIn.
- virtual bool Matches(const std::wstring& word, bool exact) const {
+ virtual bool Matches(const string16& word, bool exact) const {
NOTREACHED();
return false;
}
@@ -149,10 +150,10 @@ class QueryNodeList : public QueryNode {
NOTREACHED();
return false;
}
- virtual void AppendWords(std::vector<std::wstring>* words) const;
+ virtual void AppendWords(std::vector<string16>* words) const;
protected:
- int AppendChildrenToString(std::wstring* query) const;
+ int AppendChildrenToString(string16* query) const;
QueryNodeVector children_;
};
@@ -178,12 +179,12 @@ void QueryNodeList::RemoveEmptySubnodes() {
}
}
-void QueryNodeList::AppendWords(std::vector<std::wstring>* words) const {
+void QueryNodeList::AppendWords(std::vector<string16>* words) const {
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->AppendWords(words);
}
-int QueryNodeList::AppendChildrenToString(std::wstring* query) const {
+int QueryNodeList::AppendChildrenToString(string16* query) const {
int num_words = 0;
for (QueryNodeVector::const_iterator node = children_.begin();
node != children_.end(); ++node) {
@@ -197,19 +198,19 @@ int QueryNodeList::AppendChildrenToString(std::wstring* query) const {
// A QueryNodePhrase is a phrase query ("quoted").
class QueryNodePhrase : public QueryNodeList {
public:
- virtual int AppendToSQLiteQuery(std::wstring* query) const {
+ virtual int AppendToSQLiteQuery(string16* query) const {
query->push_back(L'"');
int num_words = AppendChildrenToString(query);
query->push_back(L'"');
return num_words;
}
- virtual bool Matches(const std::wstring& word, bool exact) const;
+ virtual bool Matches(const string16& word, bool exact) const;
virtual bool HasMatchIn(const std::vector<QueryWord>& words,
Snippet::MatchPositions* match_positions) const;
};
-bool QueryNodePhrase::Matches(const std::wstring& word, bool exact) const {
+bool QueryNodePhrase::Matches(const string16& word, bool exact) const {
NOTREACHED();
return false;
}
@@ -243,7 +244,7 @@ QueryParser::QueryParser() {
}
// static
-bool QueryParser::IsWordLongEnoughForPrefixSearch(const std::wstring& word) {
+bool QueryParser::IsWordLongEnoughForPrefixSearch(const string16& word) {
DCHECK(word.size() > 0);
size_t minimum_length = 3;
// We intentionally exclude Hangul Jamos (both Conjoining and compatibility)
@@ -264,15 +265,15 @@ static bool IsQueryQuote(wchar_t ch) {
ch == 0x201e; // double low-9 quotation mark
}
-int QueryParser::ParseQuery(const std::wstring& query,
- std::wstring* sqlite_query) {
+int QueryParser::ParseQuery(const string16& query,
+ string16* sqlite_query) {
QueryNodeList root;
if (!ParseQueryImpl(query, &root))
return 0;
return root.AppendToSQLiteQuery(sqlite_query);
}
-void QueryParser::ParseQuery(const std::wstring& query,
+void QueryParser::ParseQuery(const string16& query,
std::vector<QueryNode*>* nodes) {
QueryNodeList root;
if (ParseQueryImpl(l10n_util::ToLower(query), &root))
@@ -280,22 +281,22 @@ void QueryParser::ParseQuery(const std::wstring& query,
}
-void QueryParser::ExtractQueryWords(const std::wstring& query,
- std::vector<std::wstring>* words) {
+void QueryParser::ExtractQueryWords(const string16& query,
+ std::vector<string16>* words) {
QueryNodeList root;
if (!ParseQueryImpl(query, &root))
return;
root.AppendWords(words);
}
-bool QueryParser::DoesQueryMatch(const std::wstring& text,
+bool QueryParser::DoesQueryMatch(const string16& text,
const std::vector<QueryNode*>& query_nodes,
Snippet::MatchPositions* match_positions) {
if (query_nodes.empty())
return false;
std::vector<QueryWord> query_words;
- std::wstring lower_text = l10n_util::ToLower(text);
+ string16 lower_text = l10n_util::ToLower(text);
ExtractQueryWords(lower_text, &query_words);
if (query_words.empty())
@@ -319,9 +320,9 @@ bool QueryParser::DoesQueryMatch(const std::wstring& text,
return true;
}
-bool QueryParser::ParseQueryImpl(const std::wstring& query,
+bool QueryParser::ParseQueryImpl(const string16& query,
QueryNodeList* root) {
- WordIterator iter(query, WordIterator::BREAK_WORD);
+ WordIterator iter(&query, WordIterator::BREAK_WORD);
// TODO(evanm): support a locale here
if (!iter.Init())
return false;
@@ -337,7 +338,7 @@ bool QueryParser::ParseQueryImpl(const std::wstring& query,
// is not necessarily a word, but could also be a sequence of punctuation
// or whitespace.
if (iter.IsWord()) {
- std::wstring word = iter.GetWord();
+ string16 word = iter.GetWord();
QueryNodeWord* word_node = new QueryNodeWord(word);
if (in_quotes)
@@ -351,7 +352,7 @@ bool QueryParser::ParseQueryImpl(const std::wstring& query,
query_stack.push_back(quotes_node);
in_quotes = true;
} else {
- query_stack.pop_back(); // stop adding to the quoted phrase
+ query_stack.pop_back(); // Stop adding to the quoted phrase.
in_quotes = false;
}
}
@@ -362,9 +363,9 @@ bool QueryParser::ParseQueryImpl(const std::wstring& query,
return true;
}
-void QueryParser::ExtractQueryWords(const std::wstring& text,
+void QueryParser::ExtractQueryWords(const string16& text,
std::vector<QueryWord>* words) {
- WordIterator iter(text, WordIterator::BREAK_WORD);
+ WordIterator iter(&text, WordIterator::BREAK_WORD);
// TODO(evanm): support a locale here
if (!iter.Init())
return;
@@ -374,7 +375,7 @@ void QueryParser::ExtractQueryWords(const std::wstring& text,
// is not necessarily a word, but could also be a sequence of punctuation
// or whitespace.
if (iter.IsWord()) {
- std::wstring word = iter.GetWord();
+ string16 word = iter.GetWord();
if (!word.empty()) {
words->push_back(QueryWord());
words->back().word = word;
diff --git a/chrome/browser/history/query_parser.h b/chrome/browser/history/query_parser.h
index 8f6c86d..8399abf 100644
--- a/chrome/browser/history/query_parser.h
+++ b/chrome/browser/history/query_parser.h
@@ -1,16 +1,16 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The query parser is used to parse queries entered into the history
// search into more normalized queries can be passed to the SQLite backend.
-#ifndef CHROME_BROWSER_HISTORY_QUERY_PARSER_H__
-#define CHROME_BROWSER_HISTORY_QUERY_PARSER_H__
+#ifndef CHROME_BROWSER_HISTORY_QUERY_PARSER_H_
+#define CHROME_BROWSER_HISTORY_QUERY_PARSER_H_
-#include <string>
#include <vector>
+#include "base/string16.h"
#include "chrome/browser/history/snippet.h"
class QueryNodeList;
@@ -18,7 +18,7 @@ class QueryNodeList;
// Used by HasMatchIn.
struct QueryWord {
// The work to match against.
- std::wstring word;
+ string16 word;
// The starting position of the word in the original text.
size_t position;
@@ -33,7 +33,7 @@ class QueryNode {
// Serialize ourselves out to a string that can be passed to SQLite. Returns
// the number of words in this node.
- virtual int AppendToSQLiteQuery(std::wstring* query) const = 0;
+ virtual int AppendToSQLiteQuery(string16* query) const = 0;
// Return true if this is a word node, false if it's a QueryNodeList.
virtual bool IsWord() const = 0;
@@ -41,7 +41,7 @@ class QueryNode {
// Returns true if this node matches the specified text. If exact is true,
// the string must exactly match. Otherwise, this uses a starts with
// comparison.
- virtual bool Matches(const std::wstring& word, bool exact) const = 0;
+ virtual bool Matches(const string16& word, bool exact) const = 0;
// Returns true if this node matches at least one of the words in words. If
// the node matches at least one word, an entry is added to match_positions
@@ -50,7 +50,7 @@ class QueryNode {
Snippet::MatchPositions* match_positions) const = 0;
// Appends the words that make up this node in |words|.
- virtual void AppendWords(std::vector<std::wstring>* words) const = 0;
+ virtual void AppendWords(std::vector<string16>* words) const = 0;
};
@@ -65,43 +65,43 @@ class QueryParser {
// point doing anything for them and we only adjust the minimum length
// to 2 for Korean Hangul while using 3 for others. This is a temporary
// hack until we have a segmentation support.
- static bool IsWordLongEnoughForPrefixSearch(const std::wstring& word);
+ static bool IsWordLongEnoughForPrefixSearch(const string16& word);
// Parse a query into a SQLite query. The resulting query is placed in
// sqlite_query and the number of words is returned.
- int ParseQuery(const std::wstring& query,
- std::wstring* sqlite_query);
+ int ParseQuery(const string16& query,
+ string16* sqlite_query);
// Parses the query words in query, returning the nodes that constitute the
// valid words in the query. This is intended for later usage with
// DoesQueryMatch.
// Ownership of the nodes passes to the caller.
- void ParseQuery(const std::wstring& query,
+ void ParseQuery(const string16& query,
std::vector<QueryNode*>* nodes);
// Parses a query returning the words that make up the query. Any words in
// quotes are put in |words| without the quotes. For example, the query text
// "foo bar" results in two entries being added to words, one for foo and one
// for bar.
- void ExtractQueryWords(const std::wstring& query,
- std::vector<std::wstring>* words);
+ void ExtractQueryWords(const string16& query,
+ std::vector<string16>* words);
// Returns true if the string text matches the query nodes created by a call
// to ParseQuery. If the query does match each of the matching positions in
// the text is added to |match_positions|.
- bool DoesQueryMatch(const std::wstring& text,
+ bool DoesQueryMatch(const string16& text,
const std::vector<QueryNode*>& nodes,
Snippet::MatchPositions* match_positions);
private:
// Does the work of parsing a query; creates nodes in QueryNodeList as
// appropriate. This is invoked from both of the ParseQuery methods.
- bool ParseQueryImpl(const std::wstring& query,
+ bool ParseQueryImpl(const string16& query,
QueryNodeList* root);
// Extracts the words from text, placing each word into words.
- void ExtractQueryWords(const std::wstring& text,
+ void ExtractQueryWords(const string16& text,
std::vector<QueryWord>* words);
};
-#endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H__
+#endif // CHROME_BROWSER_HISTORY_QUERY_PARSER_H_
diff --git a/chrome/browser/history/query_parser_unittest.cc b/chrome/browser/history/query_parser_unittest.cc
index 9245cc9..f8b41d9 100644
--- a/chrome/browser/history/query_parser_unittest.cc
+++ b/chrome/browser/history/query_parser_unittest.cc
@@ -1,121 +1,125 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/scoped_vector.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/history/query_parser.h"
#include "testing/gtest/include/gtest/gtest.h"
class QueryParserTest : public testing::Test {
public:
struct TestData {
- const std::wstring input;
+ const char* input;
const int expected_word_count;
};
- std::wstring QueryToString(const std::wstring& query);
+ std::string QueryToString(const std::string& query);
protected:
QueryParser query_parser_;
};
-// Test helper: Convert a user query string to a SQLite query string.
-std::wstring QueryParserTest::QueryToString(const std::wstring& query) {
- std::wstring sqlite_query;
- query_parser_.ParseQuery(query, &sqlite_query);
- return sqlite_query;
+// Test helper: Convert a user query string in 8-bit (for hardcoding
+// convenience) to a SQLite query string.
+std::string QueryParserTest::QueryToString(const std::string& query) {
+ string16 sqlite_query;
+ query_parser_.ParseQuery(UTF8ToUTF16(query), &sqlite_query);
+ return UTF16ToUTF8(sqlite_query);
}
// Basic multi-word queries, including prefix matching.
TEST_F(QueryParserTest, SimpleQueries) {
- EXPECT_EQ(L"", QueryToString(L" "));
- EXPECT_EQ(L"singleword*", QueryToString(L"singleword"));
- EXPECT_EQ(L"spacedout*", QueryToString(L" spacedout "));
- EXPECT_EQ(L"foo* bar*", QueryToString(L"foo bar"));
+ EXPECT_EQ("", QueryToString(" "));
+ EXPECT_EQ("singleword*", QueryToString("singleword"));
+ EXPECT_EQ("spacedout*", QueryToString(" spacedout "));
+ EXPECT_EQ("foo* bar*", QueryToString("foo bar"));
// Short words aren't prefix matches. For Korean Hangul
// the minimum is 2 while for other scripts, it's 3.
- EXPECT_EQ(L"f b", QueryToString(L" f b"));
+ EXPECT_EQ("f b", QueryToString(" f b"));
// KA JANG
- EXPECT_EQ(L"\xAC00 \xC7A5", QueryToString(L" \xAC00 \xC7A5"));
- EXPECT_EQ(L"foo* bar*", QueryToString(L" foo bar "));
+ EXPECT_EQ(WideToUTF8(L"\xAC00 \xC7A5"),
+ QueryToString(WideToUTF8(L" \xAC00 \xC7A5")));
+ EXPECT_EQ("foo* bar*", QueryToString(" foo bar "));
// KA-JANG BICH-GO
- EXPECT_EQ(L"\xAC00\xC7A5* \xBE5B\xACE0*",
- QueryToString(L"\xAC00\xC7A5 \xBE5B\xACE0"));
+ EXPECT_EQ(WideToUTF8(L"\xAC00\xC7A5* \xBE5B\xACE0*"),
+ QueryToString(WideToUTF8(L"\xAC00\xC7A5 \xBE5B\xACE0")));
}
// Quoted substring parsing.
TEST_F(QueryParserTest, Quoted) {
// ASCII quotes
- EXPECT_EQ(L"\"Quoted\"", QueryToString(L"\"Quoted\""));
+ EXPECT_EQ("\"Quoted\"", QueryToString("\"Quoted\""));
// Missing end quotes
- EXPECT_EQ(L"\"miss end\"", QueryToString(L"\"miss end"));
+ EXPECT_EQ("\"miss end\"", QueryToString("\"miss end"));
// Missing begin quotes
- EXPECT_EQ(L"miss* beg*", QueryToString(L"miss beg\""));
+ EXPECT_EQ("miss* beg*", QueryToString("miss beg\""));
// Weird formatting
- EXPECT_EQ(L"\"Many\" \"quotes\"", QueryToString(L"\"Many \"\"quotes"));
+ EXPECT_EQ("\"Many\" \"quotes\"", QueryToString("\"Many \"\"quotes"));
}
// Apostrophes within words should be preserved, but otherwise stripped.
TEST_F(QueryParserTest, Apostrophes) {
- EXPECT_EQ(L"foo* bar's*", QueryToString(L"foo bar's"));
- EXPECT_EQ(L"l'foo*", QueryToString(L"l'foo"));
- EXPECT_EQ(L"foo*", QueryToString(L"'foo"));
+ EXPECT_EQ("foo* bar's*", QueryToString("foo bar's"));
+ EXPECT_EQ("l'foo*", QueryToString("l'foo"));
+ EXPECT_EQ("foo*", QueryToString("'foo"));
}
// Special characters.
TEST_F(QueryParserTest, SpecialChars) {
- EXPECT_EQ(L"foo* the* bar*", QueryToString(L"!#:/*foo#$*;'* the!#:/*bar"));
+ EXPECT_EQ("foo* the* bar*", QueryToString("!#:/*foo#$*;'* the!#:/*bar"));
}
TEST_F(QueryParserTest, NumWords) {
TestData data[] = {
- { L"blah", 1 },
- { L"foo \"bar baz\"", 3 },
- { L"foo \"baz\"", 2 },
- { L"foo \"bar baz\" blah", 4 },
+ { "blah", 1 },
+ { "foo \"bar baz\"", 3 },
+ { "foo \"baz\"", 2 },
+ { "foo \"bar baz\" blah", 4 },
};
for (size_t i = 0; i < arraysize(data); ++i) {
- std::wstring query_string;
+ string16 query_string;
EXPECT_EQ(data[i].expected_word_count,
- query_parser_.ParseQuery(data[i].input, &query_string));
+ query_parser_.ParseQuery(UTF8ToUTF16(data[i].input),
+ &query_string));
}
}
TEST_F(QueryParserTest, ParseQueryNodesAndMatch) {
struct TestData2 {
- const std::wstring query;
- const std::wstring text;
+ const std::string query;
+ const std::string text;
const bool matches;
const size_t m1_start;
const size_t m1_end;
const size_t m2_start;
const size_t m2_end;
} data[] = {
- { L"foo foo", L"foo", true, 0, 3, 0, 0 },
- { L"foo fooey", L"fooey", true, 0, 5, 0, 0 },
- { L"foo fooey bar", L"bar fooey", true, 0, 3, 4, 9 },
- { L"blah", L"blah", true, 0, 4, 0, 0 },
- { L"blah", L"foo", false, 0, 0, 0, 0 },
- { L"blah", L"blahblah", true, 0, 4, 0, 0 },
- { L"blah", L"foo blah", true, 4, 8, 0, 0 },
- { L"foo blah", L"blah", false, 0, 0, 0, 0 },
- { L"foo blah", L"blahx foobar", true, 0, 4, 6, 9 },
- { L"\"foo blah\"", L"foo blah", true, 0, 8, 0, 0 },
- { L"\"foo blah\"", L"foox blahx", false, 0, 0, 0, 0 },
- { L"\"foo blah\"", L"foo blah", true, 0, 8, 0, 0 },
- { L"\"foo blah\"", L"\"foo blah\"", true, 1, 9, 0, 0 },
- { L"foo blah", L"\"foo bar blah\"", true, 1, 4, 9, 13 },
+ { "foo foo", "foo", true, 0, 3, 0, 0 },
+ { "foo fooey", "fooey", true, 0, 5, 0, 0 },
+ { "foo fooey bar", "bar fooey", true, 0, 3, 4, 9 },
+ { "blah", "blah", true, 0, 4, 0, 0 },
+ { "blah", "foo", false, 0, 0, 0, 0 },
+ { "blah", "blahblah", true, 0, 4, 0, 0 },
+ { "blah", "foo blah", true, 4, 8, 0, 0 },
+ { "foo blah", "blah", false, 0, 0, 0, 0 },
+ { "foo blah", "blahx foobar", true, 0, 4, 6, 9 },
+ { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 },
+ { "\"foo blah\"", "foox blahx", false, 0, 0, 0, 0 },
+ { "\"foo blah\"", "foo blah", true, 0, 8, 0, 0 },
+ { "\"foo blah\"", "\"foo blah\"", true, 1, 9, 0, 0 },
+ { "foo blah", "\"foo bar blah\"", true, 1, 4, 9, 13 },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
- std::vector<std::wstring> results;
QueryParser parser;
ScopedVector<QueryNode> query_nodes;
- parser.ParseQuery(data[i].query, &query_nodes.get());
+ parser.ParseQuery(UTF8ToUTF16(data[i].query), &query_nodes.get());
Snippet::MatchPositions match_positions;
ASSERT_EQ(data[i].matches,
- parser.DoesQueryMatch(data[i].text, query_nodes.get(),
+ parser.DoesQueryMatch(UTF8ToUTF16(data[i].text),
+ query_nodes.get(),
&match_positions));
size_t offset = 0;
if (data[i].m1_start != 0 || data[i].m1_end != 0) {
@@ -134,26 +138,26 @@ TEST_F(QueryParserTest, ParseQueryNodesAndMatch) {
TEST_F(QueryParserTest, ExtractQueryWords) {
struct TestData2 {
- const std::wstring text;
- const std::wstring w1;
- const std::wstring w2;
- const std::wstring w3;
+ const std::string text;
+ const std::string w1;
+ const std::string w2;
+ const std::string w3;
const size_t word_count;
} data[] = {
- { L"foo", L"foo", L"", L"", 1 },
- { L"foo bar", L"foo", L"bar", L"", 2 },
- { L"\"foo bar\"", L"foo", L"bar", L"", 2 },
- { L"\"foo bar\" a", L"foo", L"bar", L"a", 3 },
+ { "foo", "foo", "", "", 1 },
+ { "foo bar", "foo", "bar", "", 2 },
+ { "\"foo bar\"", "foo", "bar", "", 2 },
+ { "\"foo bar\" a", "foo", "bar", "a", 3 },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
- std::vector<std::wstring> results;
+ std::vector<string16> results;
QueryParser parser;
- parser.ExtractQueryWords(data[i].text, &results);
+ parser.ExtractQueryWords(UTF8ToUTF16(data[i].text), &results);
ASSERT_EQ(data[i].word_count, results.size());
- EXPECT_EQ(data[i].w1, results[0]);
+ EXPECT_EQ(data[i].w1, UTF16ToUTF8(results[0]));
if (results.size() == 2)
- EXPECT_EQ(data[i].w2, results[1]);
+ EXPECT_EQ(data[i].w2, UTF16ToUTF8(results[1]));
if (results.size() == 3)
- EXPECT_EQ(data[i].w3, results[2]);
+ EXPECT_EQ(data[i].w3, UTF16ToUTF8(results[2]));
}
}
diff --git a/chrome/browser/history/redirect_uitest.cc b/chrome/browser/history/redirect_uitest.cc
index 49a2bb9..f7a1669 100644
--- a/chrome/browser/history/redirect_uitest.cc
+++ b/chrome/browser/history/redirect_uitest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
#include "base/platform_thread.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/string16.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "net/base/net_util.h"
@@ -195,14 +196,14 @@ TEST_F(RedirectTest, ServerReference) {
// B) does not take place.
TEST_F(RedirectTest, NoHttpToFile) {
scoped_refptr<HTTPTestServer> server =
- HTTPTestServer::CreateServer(kDocRoot, NULL);
+ HTTPTestServer::CreateServer(kDocRoot, NULL);
ASSERT_TRUE(NULL != server.get());
FilePath test_file(test_data_directory_);
test_file = test_file.AppendASCII("http_to_file.html");
GURL file_url = net::FilePathToFileURL(test_file);
GURL initial_url = server->TestServerPage(
- "client-redirect?" + file_url.spec());
+ "client-redirect?" + file_url.spec());
NavigateToURL(initial_url);
// UITest will check for crashes. We make sure the title doesn't match the
@@ -211,7 +212,7 @@ TEST_F(RedirectTest, NoHttpToFile) {
ASSERT_TRUE(tab_proxy.get());
std::wstring actual_title;
ASSERT_TRUE(tab_proxy->GetTabTitle(&actual_title));
- EXPECT_NE(L"File!", actual_title);
+ EXPECT_NE("File!", WideToUTF8(actual_title));
}
// Ensures that non-user initiated location changes (within page) are
@@ -269,7 +270,7 @@ TEST_F(RedirectTest,
NavigateToURL(final_url);
std::wstring tab_title;
- std::wstring final_url_title = L"Title Of Awesomeness";
+ std::wstring final_url_title = UTF8ToWide("Title Of Awesomeness");
// Wait till the final page has been loaded.
for (int i = 0; i < 10; ++i) {
PlatformThread::Sleep(sleep_timeout_ms());
diff --git a/chrome/browser/history/snippet.cc b/chrome/browser/history/snippet.cc
index 95b66cd..cb96e16 100644
--- a/chrome/browser/history/snippet.cc
+++ b/chrome/browser/history/snippet.cc
@@ -90,8 +90,8 @@ void AddMatch(size_t start,
}
}
-// Converts an index in a utf8 string into the index in the corresponding wide
-// string and returns the wide index. This is intended to be called in a loop
+// Converts an index in a utf8 string into the index in the corresponding utf16
+// string and returns the utf16 index. This is intended to be called in a loop
// iterating through a utf8 string.
//
// utf8_string: the utf8 string.
@@ -101,19 +101,19 @@ void AddMatch(size_t start,
// matches offset.
// wide_pos: current index in the wide string. This is the same as the return
// value.
-size_t AdvanceAndReturnWidePos(const char* utf8_string,
- int32_t utf8_length,
- int32_t offset,
- int32_t* utf8_pos,
- size_t* wide_pos) {
+size_t AdvanceAndReturnUTF16Pos(const char* utf8_string,
+ int32_t utf8_length,
+ int32_t offset,
+ int32_t* utf8_pos,
+ size_t* utf16_pos) {
DCHECK(offset >= *utf8_pos && offset <= utf8_length);
UChar32 wide_char;
while (*utf8_pos < offset) {
U8_NEXT(utf8_string, *utf8_pos, utf8_length, wide_char);
- *wide_pos += (wide_char <= 0xFFFF) ? 1 : 2;
+ *utf16_pos += (wide_char <= 0xFFFF) ? 1 : 2;
}
- return *wide_pos;
+ return *utf16_pos;
}
// Given a character break iterator over a UTF-8 string, set the iterator
@@ -187,15 +187,15 @@ void Snippet::ConvertMatchPositionsToWide(
Snippet::MatchPositions* match_positions) {
DCHECK(match_positions);
int32_t utf8_pos = 0;
- size_t wide_pos = 0;
+ size_t utf16_pos = 0;
const char* utf8_cstring = utf8_string.c_str();
const int32_t utf8_length = static_cast<int32_t>(utf8_string.size());
for (Snippet::MatchPositions::iterator i = match_positions->begin();
i != match_positions->end(); ++i) {
- i->first = AdvanceAndReturnWidePos(utf8_cstring, utf8_length,
- i->first, &utf8_pos, &wide_pos);
- i->second = AdvanceAndReturnWidePos(utf8_cstring, utf8_length,
- i->second, &utf8_pos, &wide_pos);
+ i->first = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length,
+ i->first, &utf8_pos, &utf16_pos);
+ i->second = AdvanceAndReturnUTF16Pos(utf8_cstring, utf8_length,
+ i->second, &utf8_pos, &utf16_pos);
}
}
@@ -204,7 +204,7 @@ void Snippet::ComputeSnippet(const MatchPositions& match_positions,
// The length of snippets we try to produce.
// We can generate longer snippets but stop once we cross kSnippetMaxLength.
const size_t kSnippetMaxLength = 200;
- const std::wstring kEllipsis = L" ... ";
+ const string16 kEllipsis = ASCIIToUTF16(" ... ");
UText* document_utext = NULL;
UErrorCode status = U_ZERO_ERROR;
@@ -220,7 +220,7 @@ void Snippet::ComputeSnippet(const MatchPositions& match_positions,
// We build the snippet by iterating through the matches and then grabbing
// context around each match. If matches are near enough each other (within
// kSnippetContext), we skip the "..." between them.
- std::wstring snippet;
+ string16 snippet;
size_t start = 0;
for (size_t i = 0; i < match_positions.size(); ++i) {
// Some shorter names for the current match.
@@ -240,12 +240,12 @@ void Snippet::ComputeSnippet(const MatchPositions& match_positions,
snippet += kEllipsis;
// Switch to DCHECK after debugging http://crbug.com/15261.
CHECK(start < document.size());
- snippet += UTF8ToWide(document.substr(start, match_start - start));
+ snippet += UTF8ToUTF16(document.substr(start, match_start - start));
}
// Add the match.
const size_t first = snippet.size();
- snippet += UTF8ToWide(document.substr(match_start,
+ snippet += UTF8ToUTF16(document.substr(match_start,
match_end - match_start));
matches_.push_back(std::make_pair(first, snippet.size()));
@@ -261,7 +261,7 @@ void Snippet::ComputeSnippet(const MatchPositions& match_positions,
// Switch to DCHECK after debugging http://crbug.com/15261.
CHECK(end >= match_end);
CHECK(end <= document.size());
- snippet += UTF8ToWide(document.substr(match_end, end - match_end));
+ snippet += UTF8ToUTF16(document.substr(match_end, end - match_end));
} else {
// No, there's either no next match or the next match is too far away.
end = match_end;
@@ -269,7 +269,7 @@ void Snippet::ComputeSnippet(const MatchPositions& match_positions,
// Switch to DCHECK after debugging http://crbug.com/15261.
CHECK(end >= match_end);
CHECK(end <= document.size());
- snippet += UTF8ToWide(document.substr(match_end, end - match_end));
+ snippet += UTF8ToUTF16(document.substr(match_end, end - match_end));
if (end < document.size())
snippet += kEllipsis;
}
diff --git a/chrome/browser/history/snippet.h b/chrome/browser/history/snippet.h
index 2c911ba..9e92893 100644
--- a/chrome/browser/history/snippet.h
+++ b/chrome/browser/history/snippet.h
@@ -8,9 +8,10 @@
#ifndef CHROME_BROWSER_HISTORY_SNIPPET_H__
#define CHROME_BROWSER_HISTORY_SNIPPET_H__
-#include <string>
#include <vector>
+#include "base/string16.h"
+
class Snippet {
public:
// Each MatchPosition is the [begin, end) positions of a match within a
@@ -48,7 +49,7 @@ class Snippet {
void ComputeSnippet(const MatchPositions& matches,
const std::string& document);
- const std::wstring& text() const { return text_; }
+ const string16& text() const { return text_; }
const MatchPositions& matches() const { return matches_; }
// Efficiently swaps the contents of this snippet with the other.
@@ -59,7 +60,7 @@ class Snippet {
private:
// The text of the snippet.
- std::wstring text_;
+ string16 text_;
// The matches within text_.
MatchPositions matches_;
diff --git a/chrome/browser/history/snippet_unittest.cc b/chrome/browser/history/snippet_unittest.cc
index 517e2c0..5bc8a3b 100644
--- a/chrome/browser/history/snippet_unittest.cc
+++ b/chrome/browser/history/snippet_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -86,8 +86,8 @@ bool ComparePair1st(const Snippet::MatchPosition& a,
// For testing, we'll compute the match positions manually instead of using
// sqlite's FTS matching. BuildSnippet returns the snippet for matching
// |query| against |document|. Matches are surrounded by "**".
-std::wstring BuildSnippet(const std::string& document,
- const std::string& query) {
+string16 BuildSnippet(const std::string& document,
+ const std::string& query) {
// This function assumes that |document| does not contain
// any character for which lowercasing changes its length. Further,
// it's assumed that lowercasing only the ASCII-portion works for
@@ -119,16 +119,16 @@ std::wstring BuildSnippet(const std::string& document,
snippet.ComputeSnippet(match_positions, document);
// Now "highlight" all matches in the snippet with **.
- std::wstring star_snippet;
+ string16 star_snippet;
Snippet::MatchPositions::const_iterator match;
size_t pos = 0;
for (match = snippet.matches().begin();
match != snippet.matches().end(); ++match) {
star_snippet += snippet.text().substr(pos, match->first - pos);
- star_snippet += L"**";
+ star_snippet += UTF8ToUTF16("**");
star_snippet += snippet.text().substr(match->first,
match->second - match->first);
- star_snippet += L"**";
+ star_snippet += UTF8ToUTF16("**");
pos = match->second;
}
star_snippet += snippet.text().substr(pos);
@@ -137,20 +137,20 @@ std::wstring BuildSnippet(const std::string& document,
}
TEST(Snippets, SimpleQuery) {
- ASSERT_EQ(L" ... eferred to collectively as the \"Services\" in this "
- L"**document** and excluding any services provided to you by "
- L"Goo ... ... way, Mountain View, CA 94043, United States. This "
- L"**document** explains how the agreement is made up, and sets "
- L"o ... ",
- BuildSnippet(kSampleDocument, "document"));
+ ASSERT_EQ(" ... eferred to collectively as the \"Services\" in this "
+ "**document** and excluding any services provided to you by "
+ "Goo ... ... way, Mountain View, CA 94043, United States. This "
+ "**document** explains how the agreement is made up, and sets "
+ "o ... ",
+ UTF16ToUTF8(BuildSnippet(kSampleDocument, "document")));
}
// Test that two words that are near each other don't produce two elided bits.
TEST(Snippets, NearbyWords) {
- ASSERT_EQ(L" ... lace of business is at 1600 Amphitheatre Parkway, "
- L"**Mountain** **View**, CA 94043, United States. This "
- L"document explains ... ",
- BuildSnippet(kSampleDocument, "mountain view"));
+ ASSERT_EQ(" ... lace of business is at 1600 Amphitheatre Parkway, "
+ "**Mountain** **View**, CA 94043, United States. This "
+ "document explains ... ",
+ UTF16ToUTF8(BuildSnippet(kSampleDocument, "mountain view")));
}
// The above tests already test that we get byte offsets correct, but here's
@@ -159,7 +159,7 @@ TEST(Snippets, UTF8) {
ASSERT_EQ(" ... ogle\xe2\x84\xa2 Terms of Service Welcome to Google! "
"1. Your **relationship** with Google 1.1 Your use of Google's "
"products, so ... ",
- WideToUTF8(BuildSnippet(kSampleDocument, "relationship")));
+ UTF16ToUTF8(BuildSnippet(kSampleDocument, "relationship")));
}
// Bug: 1274923
@@ -221,8 +221,8 @@ TEST(Snippets, FAILS_ThaiUTF8) {
"\xE0\xB8\x9A\xE0\xB9\x81\xE0\xB8\x95\xE0\xB9\x88\xE0\xB8\x87"
"\xE0\xB9\x80\xE0\xB8\x99\xE0\xB8\xB7\xE0\xB9\x89\xE0\xB8\xAD"
"\xE0\xB8\xAB\xE0\xB8\xB2",
- WideToUTF8(BuildSnippet(kThaiSample,
- "\xE0\xB9\x83\xE0\xB8\xAB\xE0\xB9\x89")));
+ UTF16ToUTF8(BuildSnippet(kThaiSample,
+ "\xE0\xB9\x83\xE0\xB8\xAB\xE0\xB9\x89")));
}
TEST(Snippets, ExtractMatchPositions) {
diff --git a/chrome/browser/history/starred_url_database.cc b/chrome/browser/history/starred_url_database.cc
index 23692eb..cf2a306 100644
--- a/chrome/browser/history/starred_url_database.cc
+++ b/chrome/browser/history/starred_url_database.cc
@@ -71,7 +71,7 @@ void FillInStarredEntry(const sql::Statement& s, StarredEntry* entry) {
NOTREACHED();
break;
}
- entry->title = UTF8ToWide(s.ColumnString(2));
+ entry->title = s.ColumnString16(2);
entry->date_added = base::Time::FromInternalValue(s.ColumnInt64(3));
entry->visual_order = s.ColumnInt(4);
entry->parent_group_id = s.ColumnInt64(5);
@@ -150,7 +150,7 @@ bool StarredURLDatabase::EnsureStarredIntegrity() {
}
bool StarredURLDatabase::UpdateStarredEntryRow(StarID star_id,
- const std::wstring& title,
+ const string16& title,
UIStarID parent_group_id,
int visual_order,
base::Time date_modified) {
@@ -161,7 +161,7 @@ bool StarredURLDatabase::UpdateStarredEntryRow(StarID star_id,
if (!statement)
return 0;
- statement.BindString(0, WideToUTF8(title));
+ statement.BindString16(0, title);
statement.BindInt64(1, parent_group_id);
statement.BindInt(2, visual_order);
statement.BindInt64(3, date_modified.ToInternalValue());
@@ -188,7 +188,7 @@ bool StarredURLDatabase::AdjustStarredVisualOrder(UIStarID parent_group_id,
StarID StarredURLDatabase::CreateStarredEntryRow(URLID url_id,
UIStarID group_id,
UIStarID parent_group_id,
- const std::wstring& title,
+ const string16& title,
const base::Time& date_added,
int visual_order,
StarredEntry::Type type) {
@@ -219,7 +219,7 @@ StarID StarredURLDatabase::CreateStarredEntryRow(URLID url_id,
}
statement.BindInt64(1, url_id);
statement.BindInt64(2, group_id);
- statement.BindString(3, WideToUTF8(title));
+ statement.BindString16(3, title);
statement.BindInt64(4, date_added.ToInternalValue());
statement.BindInt(5, visual_order);
statement.BindInt64(6, parent_group_id);
@@ -447,7 +447,7 @@ bool StarredURLDatabase::EnsureStarredIntegrityImpl(
return false;
}
entry.id = CreateStarredEntryRow(
- 0, entry.group_id, 0, L"other", base::Time::Now(), 0,
+ 0, entry.group_id, 0, UTF8ToUTF16("other"), base::Time::Now(), 0,
history::StarredEntry::OTHER);
if (!entry.id) {
NOTREACHED() << "Unable to create other bookmarks folder";
diff --git a/chrome/browser/history/starred_url_database.h b/chrome/browser/history/starred_url_database.h
index c11db84..8d327d8 100644
--- a/chrome/browser/history/starred_url_database.h
+++ b/chrome/browser/history/starred_url_database.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include "app/tree_node_model.h"
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
+#include "base/string16.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/url_database.h"
@@ -69,7 +70,7 @@ class StarredURLDatabase : public URLDatabase {
//
// WARNING: Does not update the visual order.
bool UpdateStarredEntryRow(StarID star_id,
- const std::wstring& title,
+ const string16& title,
UIStarID parent_group_id,
int visual_order,
base::Time date_modified);
@@ -89,7 +90,7 @@ class StarredURLDatabase : public URLDatabase {
StarID CreateStarredEntryRow(URLID url_id,
UIStarID group_id,
UIStarID parent_group_id,
- const std::wstring& title,
+ const string16& title,
const base::Time& date_added,
int visual_order,
StarredEntry::Type type);
diff --git a/chrome/browser/history/starred_url_database_unittest.cc b/chrome/browser/history/starred_url_database_unittest.cc
index 961b240..02c6a64 100644
--- a/chrome/browser/history/starred_url_database_unittest.cc
+++ b/chrome/browser/history/starred_url_database_unittest.cc
@@ -267,7 +267,7 @@ TEST_F(StarredURLDatabaseTest, RemoveStarredEntriesWithEmptyURL) {
StarredEntry entry;
entry.url = GURL("http://google.com");
- entry.title = L"FOO";
+ entry.title = UTF8ToUTF16("FOO");
entry.parent_group_id = HistoryService::kBookmarkBarID;
ASSERT_NE(0, CreateStarredEntry(&entry));
diff --git a/chrome/browser/history/text_database.cc b/chrome/browser/history/text_database.cc
index dc8ff8b..f44207a 100644
--- a/chrome/browser/history/text_database.cc
+++ b/chrome/browser/history/text_database.cc
@@ -337,7 +337,7 @@ void TextDatabase::GetTextMatches(const std::string& query,
Match& match = results->at(results->size() - 1);
match.url.Swap(&url);
- match.title = UTF8ToWide(statement.ColumnString(1));
+ match.title = statement.ColumnString16(1);
match.time = base::Time::FromInternalValue(statement.ColumnInt64(2));
// Extract any matches in the title.
diff --git a/chrome/browser/history/text_database.h b/chrome/browser/history/text_database.h
index d1cb843..e34c071 100644
--- a/chrome/browser/history/text_database.h
+++ b/chrome/browser/history/text_database.h
@@ -12,6 +12,7 @@
#include "app/sql/meta_table.h"
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/string16.h"
#include "chrome/browser/history/history_types.h"
#include "googleurl/src/gurl.h"
@@ -32,7 +33,7 @@ class TextDatabase {
// The title is returned because the title in the text database and the URL
// database may differ. This happens because we capture the title when the
// body is captured, and don't update it later.
- std::wstring title;
+ string16 title;
// Time the page that was returned was visited.
base::Time time;
diff --git a/chrome/browser/history/text_database_manager.cc b/chrome/browser/history/text_database_manager.cc
index 13d681e..ff1ae38 100644
--- a/chrome/browser/history/text_database_manager.cc
+++ b/chrome/browser/history/text_database_manager.cc
@@ -4,8 +4,6 @@
#include "chrome/browser/history/text_database_manager.h"
-#include <string>
-
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/histogram.h"
@@ -28,17 +26,10 @@ namespace {
// The number of database files we will be attached to at once.
const int kCacheDBSize = 5;
-std::string ConvertStringForIndexer(const std::wstring& input) {
- // TODO(evanm): other transformations here?
- return WideToUTF8(CollapseWhitespace(input, false));
-}
-
-#if !defined(OS_WIN) // string16 == wstring on Windows.
std::string ConvertStringForIndexer(const string16& input) {
// TODO(evanm): other transformations here?
return UTF16ToUTF8(CollapseWhitespace(input, false));
}
-#endif
// Data older than this will be committed to the full text index even if we
// haven't gotten a title and/or body.
@@ -57,9 +48,9 @@ TextDatabaseManager::PageInfo::PageInfo(URLID url_id,
added_time_ = TimeTicks::Now();
}
-void TextDatabaseManager::PageInfo::set_title(const std::wstring& ttl) {
+void TextDatabaseManager::PageInfo::set_title(const string16& ttl) {
if (ttl.empty()) // Make the title nonempty when we set it for EverybodySet.
- title_ = L" ";
+ title_ = ASCIIToUTF16(" ");
else
title_ = ttl;
}
@@ -184,7 +175,7 @@ void TextDatabaseManager::AddPageURL(const GURL& url,
}
void TextDatabaseManager::AddPageTitle(const GURL& url,
- const std::wstring& title) {
+ const string16& title) {
RecentChangeList::iterator found = recent_changes_.Peek(url);
if (found == recent_changes_.end()) {
// This page is not in our cache of recent pages. This is very much an edge
@@ -271,7 +262,7 @@ bool TextDatabaseManager::AddPageData(const GURL& url,
URLID url_id,
VisitID visit_id,
Time visit_time,
- const std::wstring& title,
+ const string16& title,
const string16& body) {
TextDatabase* db = GetDBForTime(visit_time, true);
if (!db)
@@ -411,7 +402,7 @@ void TextDatabaseManager::OptimizeChangedDatabases(
}
void TextDatabaseManager::GetTextMatches(
- const std::wstring& query,
+ const string16& query,
const QueryOptions& options,
std::vector<TextDatabase::Match>* results,
Time* first_time_searched) {
@@ -425,9 +416,9 @@ void TextDatabaseManager::GetTextMatches(
}
// Get the query into the proper format for the individual DBs.
- std::wstring fts_query_wide;
- query_parser_.ParseQuery(query, &fts_query_wide);
- std::string fts_query = WideToUTF8(fts_query_wide);
+ string16 fts_query16;
+ query_parser_.ParseQuery(query, &fts_query16);
+ std::string fts_query = UTF16ToUTF8(fts_query16);
// Need a copy of the options so we can modify the max count for each call
// to the individual databases.
diff --git a/chrome/browser/history/text_database_manager.h b/chrome/browser/history/text_database_manager.h
index c84d423..7f25bf7 100644
--- a/chrome/browser/history/text_database_manager.h
+++ b/chrome/browser/history/text_database_manager.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
+#include "base/string16.h"
#include "base/task.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/text_database.h"
@@ -103,7 +104,7 @@ class TextDatabaseManager {
// should be the time corresponding to that visit in the database.
void AddPageURL(const GURL& url, URLID url_id, VisitID visit_id,
base::Time visit_time);
- void AddPageTitle(const GURL& url, const std::wstring& title);
+ void AddPageTitle(const GURL& url, const string16& title);
void AddPageContents(const GURL& url, const string16& body);
// Adds the given data to the appropriate database file, returning true on
@@ -114,7 +115,7 @@ class TextDatabaseManager {
URLID url_id,
VisitID visit_id,
base::Time visit_time,
- const std::wstring& title,
+ const string16& title,
const string16& body);
// Deletes the instance of indexed data identified by the given time and URL.
@@ -152,7 +153,7 @@ class TextDatabaseManager {
//
// This function will return more than one match per URL if there is more than
// one entry for that URL in the database.
- void GetTextMatches(const std::wstring& query,
+ void GetTextMatches(const string16& query,
const QueryOptions& options,
std::vector<TextDatabase::Match>* results,
base::Time* first_time_searched);
@@ -176,11 +177,11 @@ class TextDatabaseManager {
URLID url_id() const { return url_id_; }
VisitID visit_id() const { return visit_id_; }
base::Time visit_time() const { return visit_time_; }
- const std::wstring& title() const { return title_; }
+ const string16& title() const { return title_; }
const string16& body() const { return body_; }
// Setters, we can only update the title and body.
- void set_title(const std::wstring& ttl);
+ void set_title(const string16& ttl);
void set_body(const string16& bdy);
// Returns true if both the title or body of the entry has been set. Since
@@ -207,7 +208,7 @@ class TextDatabaseManager {
base::TimeTicks added_time_;
// Will be the string " " when they are set to distinguish set and unset.
- std::wstring title_;
+ string16 title_;
string16 body_;
};
diff --git a/chrome/browser/history/text_database_manager_unittest.cc b/chrome/browser/history/text_database_manager_unittest.cc
index aa33af3..8e7f27e 100644
--- a/chrome/browser/history/text_database_manager_unittest.cc
+++ b/chrome/browser/history/text_database_manager_unittest.cc
@@ -20,23 +20,23 @@ namespace history {
namespace {
const char* kURL1 = "http://www.google.com/asdf";
-const wchar_t* kTitle1 = L"Google A";
+const char* kTitle1 = "Google A";
const char* kBody1 = "FOO page one.";
const char* kURL2 = "http://www.google.com/qwer";
-const wchar_t* kTitle2 = L"Google B";
+const char* kTitle2 = "Google B";
const char* kBody2 = "FOO two.";
const char* kURL3 = "http://www.google.com/zxcv";
-const wchar_t* kTitle3 = L"Google C";
+const char* kTitle3 = "Google C";
const char* kBody3 = "FOO drei";
const char* kURL4 = "http://www.google.com/hjkl";
-const wchar_t* kTitle4 = L"Google D";
+const char* kTitle4 = "Google D";
const char* kBody4 = "FOO lalala four.";
const char* kURL5 = "http://www.google.com/uiop";
-const wchar_t* kTitle5 = L"Google cinq";
+const char* kTitle5 = "Google cinq";
const char* kBody5 = "FOO page one.";
// This provides a simple implementation of a URL+VisitDatabase using an
@@ -83,7 +83,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle1, UTF8ToUTF16(kBody1));
+ visit_row.visit_time, UTF8ToUTF16(kTitle1),
+ UTF8ToUTF16(kBody1));
exploded.day_of_month++;
visit_row.url_id = 2;
@@ -91,7 +92,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
visit_id = visit_db->AddVisit(&visit_row);
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL2), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle2, UTF8ToUTF16(kBody2));
+ visit_row.visit_time, UTF8ToUTF16(kTitle2),
+ UTF8ToUTF16(kBody2));
exploded.day_of_month++;
visit_row.url_id = 2;
@@ -99,7 +101,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
visit_id = visit_db->AddVisit(&visit_row);
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL3), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle3, UTF8ToUTF16(kBody3));
+ visit_row.visit_time, UTF8ToUTF16(kTitle3),
+ UTF8ToUTF16(kBody3));
// Put the next ones in the next month.
exploded.month++;
@@ -108,7 +111,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
visit_id = visit_db->AddVisit(&visit_row);
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL4), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle4, UTF8ToUTF16(kBody4));
+ visit_row.visit_time, UTF8ToUTF16(kTitle4),
+ UTF8ToUTF16(kBody4));
exploded.day_of_month++;
visit_row.url_id = 2;
@@ -116,7 +120,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
visit_id = visit_db->AddVisit(&visit_row);
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL5), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle5, UTF8ToUTF16(kBody5));
+ visit_row.visit_time, UTF8ToUTF16(kTitle5),
+ UTF8ToUTF16(kBody5));
// Put the first one in again in the second month.
exploded.day_of_month++;
@@ -125,7 +130,8 @@ void AddAllPages(TextDatabaseManager& manager, VisitDatabase* visit_db,
visit_id = visit_db->AddVisit(&visit_row);
times->push_back(visit_row.visit_time);
manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id,
- visit_row.visit_time, kTitle1, UTF8ToUTF16(kBody1));
+ visit_row.visit_time, UTF8ToUTF16(kTitle1),
+ UTF8ToUTF16(kBody1));
}
bool ResultsHaveURL(const std::vector<TextDatabase::Match>& results,
@@ -177,7 +183,8 @@ TEST_F(TextDatabaseManagerTest, InsertQuery) {
options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100);
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
// We should have matched every page.
EXPECT_EQ(6U, results.size());
@@ -204,7 +211,7 @@ TEST_F(TextDatabaseManagerTest, InsertCompleteNoVisit) {
// First add one without a visit.
const GURL url(kURL1);
manager.AddPageURL(url, 0, 0, Time::Now());
- manager.AddPageTitle(url, kTitle1);
+ manager.AddPageTitle(url, UTF8ToUTF16(kTitle1));
manager.AddPageContents(url, UTF8ToUTF16(kBody1));
// Check that the page got added.
@@ -212,9 +219,10 @@ TEST_F(TextDatabaseManagerTest, InsertCompleteNoVisit) {
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
ASSERT_EQ(1U, results.size());
- EXPECT_EQ(kTitle1, results[0].title);
+ EXPECT_EQ(kTitle1, UTF16ToUTF8(results[0].title));
}
// Like InsertCompleteNoVisit but specifies a visit to update. We check that the
@@ -240,16 +248,17 @@ TEST_F(TextDatabaseManagerTest, InsertCompleteVisit) {
const GURL url(kURL2);
manager.AddPageURL(url, visit.url_id, visit.visit_id, visit.visit_time);
manager.AddPageContents(url, UTF8ToUTF16(kBody2));
- manager.AddPageTitle(url, kTitle2);
+ manager.AddPageTitle(url, UTF8ToUTF16(kTitle2));
// Check that the page got added.
QueryOptions options;
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
ASSERT_EQ(1U, results.size());
- EXPECT_EQ(kTitle2, results[0].title);
+ EXPECT_EQ(kTitle2, UTF16ToUTF8(results[0].title));
// Check that the visit got updated for its new indexed state.
VisitRow out_visit;
@@ -271,7 +280,7 @@ TEST_F(TextDatabaseManagerTest, InsertPartial) {
// Now add a second one with a URL and title.
GURL url2(kURL2);
manager.AddPageURL(url2, 0, 0, Time::Now());
- manager.AddPageTitle(url2, kTitle2);
+ manager.AddPageTitle(url2, UTF8ToUTF16(kTitle2));
// The third one has a URL and body.
GURL url3(kURL3);
@@ -288,7 +297,8 @@ TEST_F(TextDatabaseManagerTest, InsertPartial) {
QueryOptions options;
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"google", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("google"), options,
+ &results, &first_time_searched);
ASSERT_EQ(0U, results.size());
// Compute a time threshold that will cause everything to be flushed, and
@@ -297,7 +307,8 @@ TEST_F(TextDatabaseManagerTest, InsertPartial) {
manager.FlushOldChangesForTime(expire_time);
// Now we should have all 3 URLs added.
- manager.GetTextMatches(L"google", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("google"), options,
+ &results, &first_time_searched);
ASSERT_EQ(3U, results.size());
EXPECT_TRUE(ResultsHaveURL(results, kURL1));
EXPECT_TRUE(ResultsHaveURL(results, kURL2));
@@ -318,7 +329,7 @@ TEST_F(TextDatabaseManagerTest, PartialComplete) {
// We have to have the URL in the URL and visit databases for this test to
// work.
URLRow url_row(url);
- url_row.set_title(L"chocolate");
+ url_row.set_title(UTF8ToUTF16("chocolate"));
URLID url_id = visit_db.AddURL(url_row);
ASSERT_TRUE(url_id);
VisitRow visit_row;
@@ -333,25 +344,27 @@ TEST_F(TextDatabaseManagerTest, PartialComplete) {
// Add the title. We should be able to query based on that. The title in the
// URL row we set above should not come into the picture.
- manager.AddPageTitle(url, L"Some unique title");
+ manager.AddPageTitle(url, UTF8ToUTF16("Some unique title"));
Time first_time_searched;
QueryOptions options;
std::vector<TextDatabase::Match> results;
- manager.GetTextMatches(L"unique", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("unique"), options,
+ &results, &first_time_searched);
EXPECT_EQ(1U, results.size());
- manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("chocolate"), options,
+ &results, &first_time_searched);
EXPECT_EQ(0U, results.size());
// Now add the body, which should be queryable.
manager.AddPageContents(url, UTF8ToUTF16("Very awesome body"));
- manager.GetTextMatches(L"awesome", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("awesome"), options, &results, &first_time_searched);
EXPECT_EQ(1U, results.size());
// Adding the body will actually copy the title from the URL table rather
// than the previously indexed row (we made them not match above). This isn't
// necessarily what we want, but it's how it's implemented, and we don't want
// to regress it.
- manager.GetTextMatches(L"chocolate", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("chocolate"), options, &results, &first_time_searched);
EXPECT_EQ(1U, results.size());
}
@@ -374,7 +387,7 @@ TEST_F(TextDatabaseManagerTest, Writing) {
AddAllPages(manager, &visit_db, &times);
// We should have matched every page.
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options, &results, &first_time_searched);
EXPECT_EQ(6U, results.size());
}
results.clear();
@@ -385,7 +398,8 @@ TEST_F(TextDatabaseManagerTest, Writing) {
ASSERT_TRUE(manager.Init(NULL));
// We should have matched every page again.
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
EXPECT_EQ(6U, results.size());
}
}
@@ -412,7 +426,8 @@ TEST_F(TextDatabaseManagerTest, WritingTransaction) {
// "Forget" to commit, it should be autocommittedd for us.
// We should have matched every page.
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
EXPECT_EQ(6U, results.size());
}
results.clear();
@@ -423,7 +438,8 @@ TEST_F(TextDatabaseManagerTest, WritingTransaction) {
ASSERT_TRUE(manager.Init(NULL));
// We should have matched every page again.
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(UTF8ToUTF16("FOO"), options,
+ &results, &first_time_searched);
EXPECT_EQ(6U, results.size());
}
}
@@ -438,13 +454,15 @@ TEST_F(TextDatabaseManagerTest, QueryMax) {
std::vector<Time> times;
AddAllPages(manager, &visit_db, &times);
+ string16 foo = UTF8ToUTF16("FOO");
+
QueryOptions options;
options.begin_time = times[0] - TimeDelta::FromDays(100);
options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100);
options.max_count = 2;
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
// We should have gotten the last two pages as results (the first page is
// also the last).
@@ -455,7 +473,7 @@ TEST_F(TextDatabaseManagerTest, QueryMax) {
// Asking for 4 pages, the first one should be in another DB.
options.max_count = 4;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
EXPECT_EQ(4U, results.size());
EXPECT_TRUE(first_time_searched <= times[4]);
@@ -475,6 +493,8 @@ TEST_F(TextDatabaseManagerTest, QueryBackwards) {
std::vector<Time> times;
AddAllPages(manager, &visit_db, &times);
+ string16 foo = UTF8ToUTF16("FOO");
+
// First do a query for all time, but with a max of 2. This will give us the
// last two results and will tell us where to start searching when we want
// to go back in time.
@@ -484,7 +504,7 @@ TEST_F(TextDatabaseManagerTest, QueryBackwards) {
options.max_count = 2;
std::vector<TextDatabase::Match> results;
Time first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
// Check that we got the last two results.
EXPECT_EQ(2U, results.size());
@@ -494,7 +514,7 @@ TEST_F(TextDatabaseManagerTest, QueryBackwards) {
// Query the previous two URLs and make sure we got the correct ones.
options.end_time = first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
EXPECT_EQ(2U, results.size());
EXPECT_TRUE(first_time_searched <= times[2]);
EXPECT_TRUE(ResultsHaveURL(results, kURL3));
@@ -502,7 +522,7 @@ TEST_F(TextDatabaseManagerTest, QueryBackwards) {
// Query the previous two URLs...
options.end_time = first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
EXPECT_EQ(2U, results.size());
EXPECT_TRUE(first_time_searched <= times[0]);
EXPECT_TRUE(ResultsHaveURL(results, kURL2));
@@ -510,7 +530,7 @@ TEST_F(TextDatabaseManagerTest, QueryBackwards) {
// Try to query some more, there should be no results.
options.end_time = first_time_searched;
- manager.GetTextMatches(L"FOO", options, &results, &first_time_searched);
+ manager.GetTextMatches(foo, options, &results, &first_time_searched);
EXPECT_EQ(0U, results.size());
}
diff --git a/chrome/browser/history/text_database_unittest.cc b/chrome/browser/history/text_database_unittest.cc
index c94de8a..f604301 100644
--- a/chrome/browser/history/text_database_unittest.cc
+++ b/chrome/browser/history/text_database_unittest.cc
@@ -223,9 +223,9 @@ TEST_F(TextDatabaseTest, Query) {
EXPECT_TRUE(Time::FromInternalValue(kTime2) == results[1].time);
EXPECT_TRUE(Time::FromInternalValue(kTime3) == results[0].time);
- EXPECT_EQ(UTF8ToWide(std::string(kTitle1)), results[2].title);
- EXPECT_EQ(UTF8ToWide(std::string(kTitle2)), results[1].title);
- EXPECT_EQ(UTF8ToWide(std::string(kTitle3)), results[0].title);
+ EXPECT_EQ(std::string(kTitle1), UTF16ToUTF8(results[2].title));
+ EXPECT_EQ(std::string(kTitle2), UTF16ToUTF8(results[1].title));
+ EXPECT_EQ(std::string(kTitle3), UTF16ToUTF8(results[0].title));
// Should have no matches in the title.
EXPECT_EQ(0U, results[0].title_match_positions.size());
@@ -235,11 +235,11 @@ TEST_F(TextDatabaseTest, Query) {
// We don't want to be dependent on the exact snippet algorithm, but we know
// since we searched for "COUNTTAG" which occurs at the beginning of each
// document, that each snippet should start with that.
- EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[0].snippet.text()),
+ EXPECT_TRUE(StartsWithASCII(UTF16ToUTF8(results[0].snippet.text()),
"COUNTTAG", false));
- EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[1].snippet.text()),
+ EXPECT_TRUE(StartsWithASCII(UTF16ToUTF8(results[1].snippet.text()),
"COUNTTAG", false));
- EXPECT_TRUE(StartsWithASCII(WideToUTF8(results[2].snippet.text()),
+ EXPECT_TRUE(StartsWithASCII(UTF16ToUTF8(results[2].snippet.text()),
"COUNTTAG", false));
}
diff --git a/chrome/browser/history/url_database.cc b/chrome/browser/history/url_database.cc
index e1c8106..07f8881 100644
--- a/chrome/browser/history/url_database.cc
+++ b/chrome/browser/history/url_database.cc
@@ -53,7 +53,7 @@ void URLDatabase::FillURLRow(sql::Statement& s, history::URLRow* i) {
DCHECK(i);
i->id_ = s.ColumnInt64(0);
i->url_ = GURL(s.ColumnString(1));
- i->title_ = UTF8ToWide(s.ColumnString(2));
+ i->title_ = s.ColumnString16(2);
i->visit_count_ = s.ColumnInt(3);
i->typed_count_ = s.ColumnInt(4);
i->last_visit_ = base::Time::FromInternalValue(s.ColumnInt64(5));
@@ -118,7 +118,7 @@ bool URLDatabase::UpdateURLRow(URLID url_id,
if (!statement)
return false;
- statement.BindString(0, WideToUTF8(info.title()));
+ statement.BindString16(0, info.title());
statement.BindInt(1, info.visit_count());
statement.BindInt(2, info.typed_count());
statement.BindInt64(3, info.last_visit().ToInternalValue());
@@ -157,7 +157,7 @@ URLID URLDatabase::AddURLInternal(const history::URLRow& info,
}
statement.BindString(0, GURLToDatabaseURL(info.url()));
- statement.BindString(1, WideToUTF8(info.title()));
+ statement.BindString16(1, info.title());
statement.BindInt(2, info.visit_count());
statement.BindInt(3, info.typed_count());
statement.BindInt64(4, info.last_visit().ToInternalValue());
@@ -246,7 +246,7 @@ bool URLDatabase::IsFavIconUsed(FavIconID favicon_id) {
return statement.Step();
}
-void URLDatabase::AutocompleteForPrefix(const std::wstring& prefix,
+void URLDatabase::AutocompleteForPrefix(const string16& prefix,
size_t max_results,
std::vector<history::URLRow>* results) {
// NOTE: this query originally sorted by starred as the second parameter. But
@@ -265,7 +265,7 @@ void URLDatabase::AutocompleteForPrefix(const std::wstring& prefix,
// followed by the maximum character size. Use 8-bit strings for everything
// so we can be sure sqlite is comparing everything in 8-bit mode. Otherwise,
// it will have to convert strings either to UTF-8 or UTF-16 for comparison.
- std::string prefix_utf8(WideToUTF8(prefix));
+ std::string prefix_utf8(UTF16ToUTF8(prefix));
std::string end_query(prefix_utf8);
end_query.push_back(std::numeric_limits<unsigned char>::max());
@@ -347,7 +347,7 @@ bool URLDatabase::DropKeywordSearchTermsTable() {
bool URLDatabase::SetKeywordSearchTermsForURL(URLID url_id,
TemplateURL::IDType keyword_id,
- const std::wstring& term) {
+ const string16& term) {
DCHECK(url_id && keyword_id && !term.empty());
sql::Statement exist_statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
@@ -368,8 +368,8 @@ bool URLDatabase::SetKeywordSearchTermsForURL(URLID url_id,
statement.BindInt64(0, keyword_id);
statement.BindInt64(1, url_id);
- statement.BindString(2, UTF16ToUTF8(l10n_util::ToLower(WideToUTF16(term))));
- statement.BindString(3, WideToUTF8(term));
+ statement.BindString16(2, l10n_util::ToLower(term));
+ statement.BindString16(3, term);
return statement.Run();
}
@@ -387,7 +387,7 @@ void URLDatabase::DeleteAllSearchTermsForKeyword(
void URLDatabase::GetMostRecentKeywordSearchTerms(
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count,
std::vector<KeywordSearchTermVisit>* matches) {
// NOTE: the keyword_id can be zero if on first run the user does a query
@@ -407,19 +407,19 @@ void URLDatabase::GetMostRecentKeywordSearchTerms(
return;
// NOTE: Keep this ToLower() call in sync with search_provider.cc.
- string16 lower_prefix = l10n_util::ToLower(WideToUTF16(prefix));
+ string16 lower_prefix = l10n_util::ToLower(prefix);
// This magic gives us a prefix search.
string16 next_prefix = lower_prefix;
next_prefix[next_prefix.size() - 1] =
next_prefix[next_prefix.size() - 1] + 1;
statement.BindInt64(0, keyword_id);
- statement.BindString(1, UTF16ToUTF8(lower_prefix));
- statement.BindString(2, UTF16ToUTF8(next_prefix));
+ statement.BindString16(1, lower_prefix);
+ statement.BindString16(2, next_prefix);
statement.BindInt(3, max_count);
KeywordSearchTermVisit visit;
while (statement.Step()) {
- visit.term = UTF8ToWide(statement.ColumnString(0));
+ visit.term = statement.ColumnString16(0);
visit.time = base::Time::FromInternalValue(statement.ColumnInt64(1));
matches->push_back(visit);
}
diff --git a/chrome/browser/history/url_database.h b/chrome/browser/history/url_database.h
index 9fb67b4..84c8dde 100644
--- a/chrome/browser/history/url_database.h
+++ b/chrome/browser/history/url_database.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -139,7 +139,7 @@ class URLDatabase {
// Fills the given array with URLs matching the given prefix. They will be
// sorted by typed count, then by visit count, then by visit date (most
// recent first) up to the given maximum number. Called by HistoryURLProvider.
- void AutocompleteForPrefix(const std::wstring& prefix,
+ void AutocompleteForPrefix(const string16& prefix,
size_t max_results,
std::vector<URLRow>* results);
@@ -160,7 +160,7 @@ class URLDatabase {
// Sets the search terms for the specified url/keyword pair.
bool SetKeywordSearchTermsForURL(URLID url_id,
TemplateURL::IDType keyword_id,
- const std::wstring& term);
+ const string16& term);
// Deletes all search terms for the specified keyword that have been added by
// way of SetKeywordSearchTermsForURL.
@@ -170,7 +170,7 @@ class URLDatabase {
// keyword.
void GetMostRecentKeywordSearchTerms(
TemplateURL::IDType keyword_id,
- const std::wstring& prefix,
+ const string16& prefix,
int max_count,
std::vector<KeywordSearchTermVisit>* matches);
diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc
index d6dc43f..32ded0c 100644
--- a/chrome/browser/history/url_database_unittest.cc
+++ b/chrome/browser/history/url_database_unittest.cc
@@ -7,6 +7,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "chrome/browser/history/url_database.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -71,7 +72,7 @@ TEST_F(URLDatabaseTest, AddURL) {
// first, add two URLs
const GURL url1("http://www.google.com/");
URLRow url_info1(url1);
- url_info1.set_title(L"Google");
+ url_info1.set_title(UTF8ToUTF16("Google"));
url_info1.set_visit_count(4);
url_info1.set_typed_count(2);
url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
@@ -80,7 +81,7 @@ TEST_F(URLDatabaseTest, AddURL) {
const GURL url2("http://mail.google.com/");
URLRow url_info2(url2);
- url_info2.set_title(L"Google Mail");
+ url_info2.set_title(UTF8ToUTF16("Google Mail"));
url_info2.set_visit_count(3);
url_info2.set_typed_count(0);
url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2));
@@ -96,7 +97,7 @@ TEST_F(URLDatabaseTest, AddURL) {
EXPECT_TRUE(IsURLRowEqual(url_info2, info));
// update the second
- url_info2.set_title(L"Google Mail Too");
+ url_info2.set_title(UTF8ToUTF16("Google Mail Too"));
url_info2.set_visit_count(4);
url_info2.set_typed_count(1);
url_info2.set_typed_count(91011);
@@ -125,7 +126,7 @@ TEST_F(URLDatabaseTest, AddURL) {
TEST_F(URLDatabaseTest, KeywordSearchTermVisit) {
const GURL url1("http://www.google.com/");
URLRow url_info1(url1);
- url_info1.set_title(L"Google");
+ url_info1.set_title(UTF8ToUTF16("Google"));
url_info1.set_visit_count(4);
url_info1.set_typed_count(2);
url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
@@ -134,20 +135,20 @@ TEST_F(URLDatabaseTest, KeywordSearchTermVisit) {
ASSERT_TRUE(url_id != 0);
// Add a keyword visit.
- ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit"));
+ ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit")));
// Make sure we get it back.
std::vector<KeywordSearchTermVisit> matches;
- GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches);
+ GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches);
ASSERT_EQ(1U, matches.size());
- ASSERT_EQ(L"visit", matches[0].term);
+ ASSERT_EQ(UTF8ToUTF16("visit"), matches[0].term);
// Delete the keyword visit.
DeleteAllSearchTermsForKeyword(1);
// Make sure we don't get it back when querying.
matches.clear();
- GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches);
+ GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches);
ASSERT_EQ(0U, matches.size());
}
@@ -155,7 +156,7 @@ TEST_F(URLDatabaseTest, KeywordSearchTermVisit) {
TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) {
const GURL url1("http://www.google.com/");
URLRow url_info1(url1);
- url_info1.set_title(L"Google");
+ url_info1.set_title(UTF8ToUTF16("Google"));
url_info1.set_visit_count(4);
url_info1.set_typed_count(2);
url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1));
@@ -164,14 +165,14 @@ TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) {
ASSERT_TRUE(url_id != 0);
// Add a keyword visit.
- ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit"));
+ ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit")));
// Delete the url.
ASSERT_TRUE(DeleteURLRow(url_id));
// Make sure the keyword visit was deleted.
std::vector<KeywordSearchTermVisit> matches;
- GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches);
+ GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches);
ASSERT_EQ(0U, matches.size());
}