diff options
author | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
---|---|---|
committer | Iain Merrick <husky@google.com> | 2010-10-19 14:37:37 +0100 |
commit | 3345a6884c488ff3a535c2c9acdd33d74b37e311 (patch) | |
tree | 7784b988ef1698cb6967ea1bdf07616237716c6c /chrome/browser/importer | |
parent | efc8475837ec58186051f23bb03542620424f6ce (diff) | |
download | external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.zip external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.gz external_chromium-3345a6884c488ff3a535c2c9acdd33d74b37e311.tar.bz2 |
Merge Chromium at 7.0.540.0 : Initial merge by git
Not including third_party/icu as it contains huge data files that break Gerrit, and aren't actually used.
Change-Id: I428a386e70f3b58cacd28677b8cfda282e891e15
Diffstat (limited to 'chrome/browser/importer')
42 files changed, 336 insertions, 229 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index d551105..d7932b8 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -13,6 +13,9 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/stl_util-inl.h" +#include "base/string_split.h" +#include "base/string_util.h" +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/history/history_types.h" @@ -482,7 +485,8 @@ bool Firefox2Importer::ParseBookmarkFromLine(const std::string& line, // Add date if (GetAttribute(attribute_list, kAddDateAttribute, &value)) { - int64 time = StringToInt64(value); + int64 time; + base::StringToInt64(value, &time); // Upper bound it at 32 bits. if (0 < time && time < (1LL << 32)) *add_date = Time::FromTimeT(time); diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h index c320e38..07a5567 100644 --- a/chrome/browser/importer/firefox2_importer.h +++ b/chrome/browser/importer/firefox2_importer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX2_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX2_IMPORTER_H_ +#pragma once #include <set> diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 2b95cc3..110f2b6 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -11,6 +11,8 @@ #include "base/scoped_ptr.h" #include "base/stl_util-inl.h" #include "base/string_util.h" +#include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox_importer_utils.h" @@ -33,14 +35,26 @@ using importer::ProfileInfo; using importer::SEARCH_ENGINES; using webkit_glue::PasswordForm; +Firefox3Importer::Firefox3Importer() { +#if defined(OS_LINUX) + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + locale_ = g_browser_process->GetApplicationLocale(); +#endif +} + +Firefox3Importer::~Firefox3Importer() { +} + void Firefox3Importer::StartImport(importer::ProfileInfo profile_info, uint16 items, ImporterBridge* bridge) { +#if defined(OS_LINUX) + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); +#endif bridge_ = bridge; source_path_ = profile_info.source_path; app_path_ = profile_info.app_path; - // The order here is important! bridge_->NotifyStarted(); if ((items & importer::HOME_PAGE) && !cancelled()) @@ -118,7 +132,7 @@ void Firefox3Importer::ImportHistory() { rows.push_back(row); } if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + bridge_->SetHistoryItems(rows, history::SOURCE_FIREFOX_IMPORTED); } } @@ -174,6 +188,7 @@ void Firefox3Importer::ImportBookmarks() { post_keyword_ids.insert(s.column_int(0)); } else { NOTREACHED(); + return; } std::wstring firefox_folder = @@ -349,9 +364,9 @@ void Firefox3Importer::GetSearchEnginesXMLFiles( FilePath app_path = app_path_.AppendASCII("searchplugins"); FilePath profile_path = source_path_.AppendASCII("searchplugins"); - // Firefox doesn't store a search engine in its sqlite database unless - // the user has changed the default definition of engine. So we get search - // engines from sqlite db as well as from file system. + // Firefox doesn't store a search engine in its sqlite database unless the + // user has added a engine. So we get search engines from sqlite db as well + // as from the file system. if (s.step() == SQLITE_ROW) { const std::wstring kAppPrefix = L"[app]/"; const std::wstring kProfilePrefix = L"[profile]/"; @@ -380,6 +395,20 @@ void Firefox3Importer::GetSearchEnginesXMLFiles( } while (s.step() == SQLITE_ROW && !cancelled()); } +#if defined(OS_LINUX) + // Ubuntu-flavored Firefox3 supports locale-specific search engines via + // locale-named subdirectories. They fall back to en-US. + // See http://crbug.com/53899 + // TODO(jshin): we need to make sure our locale code matches that of + // Firefox. + FilePath locale_app_path = app_path.AppendASCII(locale_); + FilePath default_locale_app_path = app_path.AppendASCII("en-US"); + if (file_util::DirectoryExists(locale_app_path)) + app_path = locale_app_path; + else if (file_util::DirectoryExists(default_locale_app_path)) + app_path = default_locale_app_path; +#endif + // Get search engine definition from file system. file_util::FileEnumerator engines(app_path, false, file_util::FileEnumerator::FILES); diff --git a/chrome/browser/importer/firefox3_importer.h b/chrome/browser/importer/firefox3_importer.h index f8bfa2f..592d4da 100644 --- a/chrome/browser/importer/firefox3_importer.h +++ b/chrome/browser/importer/firefox3_importer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX3_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX3_IMPORTER_H_ +#pragma once #include <map> #include <set> @@ -18,12 +19,12 @@ struct sqlite3; -// Importer for Mozilla Firefox 3. +// Importer for Mozilla Firefox 3 and later. // Firefox 3 stores its persistent information in a new system called places. // http://wiki.mozilla.org/Places class Firefox3Importer : public Importer { public: - Firefox3Importer() { } + Firefox3Importer(); // Importer methods. virtual void StartImport(importer::ProfileInfo profile_info, @@ -33,7 +34,7 @@ class Firefox3Importer : public Importer { private: typedef std::map<int64, std::set<GURL> > FaviconMap; - virtual ~Firefox3Importer() { } + virtual ~Firefox3Importer(); void ImportBookmarks(); void ImportPasswords(); @@ -81,6 +82,12 @@ class Firefox3Importer : public Importer { FilePath source_path_; FilePath app_path_; +#if defined(OS_LINUX) + // Stored because we can only access it from the UI thread. Not usable + // in Mac because no access from out-of-process import. + std::string locale_; +#endif + DISALLOW_COPY_AND_ASSIGN(Firefox3Importer); }; diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/firefox_importer_unittest.cc index 42c23ac..060015d 100644 --- a/chrome/browser/importer/firefox_importer_unittest.cc +++ b/chrome/browser/importer/firefox_importer_unittest.cc @@ -7,6 +7,7 @@ #include "base/file_path.h" #include "base/file_util.h" #include "base/path_service.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox_importer_unittest_utils.h" diff --git a/chrome/browser/importer/firefox_importer_unittest_utils.h b/chrome/browser/importer/firefox_importer_unittest_utils.h index 3eb12d6..9a1df8d 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils.h +++ b/chrome/browser/importer/firefox_importer_unittest_utils.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UNITTEST_UTILS_H_ +#pragma once #include "base/basictypes.h" #include "base/process_util.h" diff --git a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc index 03dddc7..f9958fb 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc +++ b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc @@ -4,6 +4,7 @@ #include "chrome/browser/importer/firefox_importer_unittest_utils.h" +#include "base/base_switches.h" #include "base/command_line.h" #include "base/debug_on_start.h" #include "base/file_path.h" @@ -16,11 +17,16 @@ #include "ipc/ipc_switches.h" #include "testing/multiprocess_func_list.h" -// Definition of IPC Messages used for this test. +// Declaration of IPC Messages used for this test. #define MESSAGES_INTERNAL_FILE \ "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" #include "ipc/ipc_message_macros.h" +// Definition of IPC Messages used for this test. +#define MESSAGES_INTERNAL_IMPL_FILE \ + "chrome/browser/importer/firefox_importer_unittest_messages_internal.h" +#include "ipc/ipc_message_impl_macros.h" + namespace { // Name of IPC Channel to use for Server<-> Child Communications. @@ -34,7 +40,7 @@ const char kTestChannelID[] = "T1"; bool LaunchNSSDecrypterChildProcess(const std::wstring& nss_path, const IPC::Channel& channel, base::ProcessHandle* handle) { CommandLine cl(*CommandLine::ForCurrentProcess()); - cl.AppendSwitchWithValue("client", "NSSDecrypterChildProcess"); + cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); FilePath ff_dylib_dir = FilePath::FromWStringHack(nss_path); // Set env variable needed for FF encryption libs to load. diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index b9a7a74..6ff1798 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -10,7 +10,9 @@ #include "base/file_util.h" #include "base/logging.h" +#include "base/string_split.h" #include "base/string_util.h" +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/search_engines/template_url.h" @@ -51,7 +53,7 @@ FilePath GetFirefoxProfilePath() { FilePath source_path; for (int i = 0; ; ++i) { std::string current_profile = StringPrintf("Profile%d", i); - if (!root.HasKeyASCII(current_profile)) { + if (!root.HasKey(current_profile)) { // Profiles are continuously numbered. So we exit when we can't // find the i-th one. break; @@ -132,35 +134,35 @@ void ParseProfileINI(const FilePath& file, DictionaryValue* root) { // Parses the file. root->Clear(); - std::wstring current_section; + std::string current_section; for (size_t i = 0; i < lines.size(); ++i) { - std::wstring line = UTF8ToWide(lines[i]); + std::string line = lines[i]; if (line.empty()) { // Skips the empty line. continue; } - if (line[0] == L'#' || line[0] == L';') { + if (line[0] == '#' || line[0] == ';') { // This line is a comment. continue; } - if (line[0] == L'[') { + if (line[0] == '[') { // It is a section header. current_section = line.substr(1); - size_t end = current_section.rfind(L']'); - if (end != std::wstring::npos) + size_t end = current_section.rfind(']'); + if (end != std::string::npos) current_section.erase(end); } else { - std::wstring key, value; - size_t equal = line.find(L'='); - if (equal != std::wstring::npos) { + std::string key, value; + size_t equal = line.find('='); + if (equal != std::string::npos) { key = line.substr(0, equal); value = line.substr(equal + 1); // Checks whether the section and key contain a '.' character. // Those sections and keys break DictionaryValue's path format, // so we discard them. - if (current_section.find(L'.') == std::wstring::npos && - key.find(L'.') == std::wstring::npos) - root->SetString(current_section + L"." + key, value); + if (current_section.find('.') == std::string::npos && + key.find('.') == std::string::npos) + root->SetString(current_section + "." + key, value); } } } @@ -242,8 +244,7 @@ bool ReadPrefFile(const FilePath& path, std::string* content) { file_util::ReadFileToString(path, content); if (content->empty()) { - NOTREACHED() << "Firefox preference file " << path.value() - << " is empty."; + LOG(WARNING) << "Firefox preference file " << path.value() << " is empty."; return false; } @@ -268,7 +269,7 @@ std::string ReadBrowserConfigProp(const FilePath& app_path, if (start == std::string::npos || stop == std::string::npos || (start == stop)) { - NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; + LOG(WARNING) << "Firefox property " << pref_key << " could not be parsed."; return ""; } @@ -281,30 +282,7 @@ std::string ReadPrefsJsValue(const FilePath& profile_path, if (!ReadPrefFile(profile_path.AppendASCII("prefs.js"), &content)) return ""; - // This file has the syntax: user_pref("key", value); - std::string search_for = std::string("user_pref(\"") + pref_key + - std::string("\", "); - size_t prop_index = content.find(search_for); - if (prop_index == std::string::npos) - return ""; - - size_t start = prop_index + search_for.length(); - size_t stop = std::string::npos; - if (start != std::string::npos) - stop = content.find(")", start + 1); - - if (start == std::string::npos || stop == std::string::npos) { - NOTREACHED() << "Firefox property " << pref_key << " could not be parsed."; - return ""; - } - - // String values have double quotes we don't need to return to the caller. - if (content[start] == '\"' && content[stop - 1] == '\"') { - ++start; - --stop; - } - - return content.substr(start, stop - start); + return GetPrefsJsValue(content, pref_key); } int GetFirefoxDefaultSearchEngineIndex( @@ -316,8 +294,8 @@ int GetFirefoxDefaultSearchEngineIndex( if (search_engines.empty()) return -1; - std::wstring default_se_name = UTF8ToWide( - ReadPrefsJsValue(profile_path, "browser.search.selectedEngine")); + std::string default_se_name = + ReadPrefsJsValue(profile_path, "browser.search.selectedEngine"); if (default_se_name.empty()) { // browser.search.selectedEngine does not exist if the user has not changed @@ -330,13 +308,13 @@ int GetFirefoxDefaultSearchEngineIndex( int default_se_index = -1; for (std::vector<TemplateURL*>::const_iterator iter = search_engines.begin(); iter != search_engines.end(); ++iter) { - if (default_se_name == (*iter)->short_name()) { + if (default_se_name == WideToUTF8((*iter)->short_name())) { default_se_index = static_cast<int>(iter - search_engines.begin()); break; } } if (default_se_index == -1) { - NOTREACHED() << + LOG(WARNING) << "Firefox default search engine not found in search engine list"; } @@ -419,7 +397,7 @@ bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs) { // Value could be a boolean. bool is_value_true = LowerCaseEqualsASCII(value, "true"); if (is_value_true || LowerCaseEqualsASCII(value, "false")) { - prefs->SetBoolean(ASCIIToWide(key), is_value_true); + prefs->SetBoolean(key, is_value_true); continue; } @@ -430,7 +408,7 @@ bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs) { // ValueString only accept valid UTF-8. Simply ignore that entry if it is // not UTF-8. if (IsStringUTF8(value)) - prefs->SetString(ASCIIToWide(key), value); + prefs->SetString(key, value); else LOG(INFO) << "Non UTF8 value for key " << key << ", ignored."; continue; @@ -438,8 +416,8 @@ bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs) { // Or value could be an integer. int int_value = 0; - if (StringToInt(value, &int_value)) { - prefs->SetInteger(ASCIIToWide(key), int_value); + if (base::StringToInt(value, &int_value)) { + prefs->SetInteger(key, int_value); continue; } @@ -448,3 +426,35 @@ bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs) { } return true; } + +std::string GetPrefsJsValue(const std::string& content, + const std::string& pref_key) { + // This file has the syntax: user_pref("key", value); + std::string search_for = std::string("user_pref(\"") + pref_key + + std::string("\", "); + size_t prop_index = content.find(search_for); + if (prop_index == std::string::npos) + return ""; + + size_t start = prop_index + search_for.length(); + size_t stop = std::string::npos; + if (start != std::string::npos) { + // Stop at the last ')' on this line. + stop = content.find("\n", start + 1); + stop = content.rfind(")", stop); + } + + if (start == std::string::npos || stop == std::string::npos || + stop < start) { + LOG(WARNING) << "Firefox property " << pref_key << " could not be parsed."; + return ""; + } + + // String values have double quotes we don't need to return to the caller. + if (content[start] == '\"' && content[stop - 1] == '\"') { + ++start; + --stop; + } + + return content.substr(start, stop - start); +} diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h index 1ad7ddb..b5c4d6d 100644 --- a/chrome/browser/importer/firefox_importer_utils.h +++ b/chrome/browser/importer/firefox_importer_utils.h @@ -1,17 +1,19 @@ -// 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. #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ +#pragma once +#include <string> #include <vector> #include "base/basictypes.h" -#include "base/file_path.h" #include "build/build_config.h" class DictionaryValue; +class FilePath; class GURL; class TemplateURL; @@ -94,4 +96,9 @@ bool IsDefaultHomepage(const GURL& homepage, const FilePath& app_path); // key/pair is not valid UTF-8, it is ignored and will not appear in |prefs|. bool ParsePrefFile(const FilePath& pref_file, DictionaryValue* prefs); +// Parses the value of a particular firefox preference from a string that is +// the contents of the prefs file. +std::string GetPrefsJsValue(const std::string& prefs, + const std::string& pref_key); + #endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_ diff --git a/chrome/browser/importer/firefox_importer_utils_win.cc b/chrome/browser/importer/firefox_importer_utils_win.cc index 77e3fcb..3200eb1 100644 --- a/chrome/browser/importer/firefox_importer_utils_win.cc +++ b/chrome/browser/importer/firefox_importer_utils_win.cc @@ -29,7 +29,7 @@ int GetCurrentFirefoxMajorVersionFromRegistry() { // HKCU\Mozilla. for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { RegKey reg_key(kFireFoxRegistryPaths[i], - L"Software\\Mozilla\\Mozilla Firefox"); + L"Software\\Mozilla\\Mozilla Firefox", KEY_READ); bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, &ver_buffer_length, NULL); @@ -43,16 +43,16 @@ int GetCurrentFirefoxMajorVersionFromRegistry() { std::wstring GetFirefoxInstallPathFromRegistry() { // Detects the path that Firefox is installed in. std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; - TCHAR buffer[MAX_PATH]; + wchar_t buffer[MAX_PATH]; DWORD buffer_length = sizeof(buffer); - RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str()); + RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); bool result = reg_key.ReadValue(L"CurrentVersion", buffer, &buffer_length, NULL); if (!result) return std::wstring(); registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; buffer_length = sizeof(buffer); - RegKey reg_key_directory = RegKey(HKEY_LOCAL_MACHINE, registry_path.c_str()); + RegKey reg_key_directory(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); result = reg_key_directory.ReadValue(L"Install Directory", buffer, &buffer_length, NULL); if (!result) diff --git a/chrome/browser/importer/firefox_profile_lock.h b/chrome/browser/importer/firefox_profile_lock.h index 20b9065..9c6b687 100644 --- a/chrome/browser/importer/firefox_profile_lock.h +++ b/chrome/browser/importer/firefox_profile_lock.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ #define CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__ +#pragma once #include "build/build_config.h" @@ -11,8 +12,6 @@ #include <windows.h> #endif -#include <string> - #include "base/basictypes.h" #include "base/file_path.h" #include "base/gtest_prod_util.h" diff --git a/chrome/browser/importer/firefox_proxy_settings.cc b/chrome/browser/importer/firefox_proxy_settings.cc index 0f8ff39..1771b1c 100644 --- a/chrome/browser/importer/firefox_proxy_settings.cc +++ b/chrome/browser/importer/firefox_proxy_settings.cc @@ -4,6 +4,7 @@ #include "chrome/browser/importer/firefox_proxy_settings.h" +#include "base/file_path.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/values.h" @@ -12,18 +13,18 @@ namespace { -const wchar_t* const kNetworkProxyTypeKey = L"network.proxy.type"; +const char* const kNetworkProxyTypeKey = "network.proxy.type"; const char* const kHTTPProxyKey = "network.proxy.http"; -const wchar_t* const kHTTPProxyPortKey = L"network.proxy.http_port"; +const char* const kHTTPProxyPortKey = "network.proxy.http_port"; const char* const kSSLProxyKey = "network.proxy.ssl"; -const wchar_t* const kSSLProxyPortKey = L"network.proxy.ssl_port"; +const char* const kSSLProxyPortKey = "network.proxy.ssl_port"; const char* const kFTPProxyKey = "network.proxy.ftp"; -const wchar_t* const kFTPProxyPortKey = L"network.proxy.ftp_port"; +const char* const kFTPProxyPortKey = "network.proxy.ftp_port"; const char* const kGopherProxyKey = "network.proxy.gopher"; -const wchar_t* const kGopherProxyPortKey = L"network.proxy.gopher_port"; +const char* const kGopherProxyPortKey = "network.proxy.gopher_port"; const char* const kSOCKSHostKey = "network.proxy.socks"; -const wchar_t* const kSOCKSHostPortKey = L"network.proxy.socks_port"; -const wchar_t* const kSOCKSVersionKey = L"network.proxy.socks_version"; +const char* const kSOCKSHostPortKey = "network.proxy.socks_port"; +const char* const kSOCKSVersionKey = "network.proxy.socks_version"; const char* const kAutoconfigURL = "network.proxy.autoconfig_url"; const char* const kNoProxyListKey = "network.proxy.no_proxies_on"; const char* const kPrefFileName = "prefs.js"; @@ -127,32 +128,28 @@ bool FirefoxProxySettings::ToProxyConfig(net::ProxyConfig* config) { if (!http_proxy().empty()) { config->proxy_rules().proxy_for_http = net::ProxyServer( net::ProxyServer::SCHEME_HTTP, - http_proxy(), - http_proxy_port()); + net::HostPortPair(http_proxy(), http_proxy_port())); } if (!ftp_proxy().empty()) { config->proxy_rules().proxy_for_ftp = net::ProxyServer( net::ProxyServer::SCHEME_HTTP, - ftp_proxy(), - ftp_proxy_port()); + net::HostPortPair(ftp_proxy(), ftp_proxy_port())); } if (!ssl_proxy().empty()) { config->proxy_rules().proxy_for_https = net::ProxyServer( net::ProxyServer::SCHEME_HTTP, - ssl_proxy(), - ssl_proxy_port()); + net::HostPortPair(ssl_proxy(), ssl_proxy_port())); } if (!socks_host().empty()) { net::ProxyServer::Scheme proxy_scheme = V5 == socks_version() ? net::ProxyServer::SCHEME_SOCKS5 : net::ProxyServer::SCHEME_SOCKS4; - config->proxy_rules().socks_proxy = net::ProxyServer( + config->proxy_rules().fallback_proxy = net::ProxyServer( proxy_scheme, - socks_host(), - socks_port()); + net::HostPortPair(socks_host(), socks_port())); } config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( diff --git a/chrome/browser/importer/firefox_proxy_settings.h b/chrome/browser/importer/firefox_proxy_settings.h index 80e1e24..6ad3249 100644 --- a/chrome/browser/importer/firefox_proxy_settings.h +++ b/chrome/browser/importer/firefox_proxy_settings.h @@ -4,11 +4,12 @@ #ifndef CHROME_BROWSER_IMPORTER_FIREFOX_PROXY_SETTINGS_H_ #define CHROME_BROWSER_IMPORTER_FIREFOX_PROXY_SETTINGS_H_ +#pragma once #include <string> #include <vector> -#include "base/logging.h" +#include "base/basictypes.h" class FilePath; diff --git a/chrome/browser/importer/firefox_proxy_settings_unittest.cc b/chrome/browser/importer/firefox_proxy_settings_unittest.cc index ed2a66c..3781741 100644 --- a/chrome/browser/importer/firefox_proxy_settings_unittest.cc +++ b/chrome/browser/importer/firefox_proxy_settings_unittest.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <sstream> - #include "testing/gtest/include/gtest/gtest.h" #include "base/file_path.h" @@ -56,26 +54,15 @@ TEST_F(FirefoxProxySettingsTest, TestParse) { net::ProxyConfig config; EXPECT_TRUE(settings.ToProxyConfig(&config)); - // Pretty-print |config| to a string (easy way to define the expectations). - std::ostringstream stream; - stream << config; - std::string pretty_printed_config = stream.str(); - - EXPECT_EQ( - "Automatic settings:\n" - " Auto-detect: No\n" - " Custom PAC script: [None]\n" - "Manual settings:\n" - " Proxy server: \n" - " HTTP: http_proxy:1111\n" - " HTTPS: ssl_proxy:2222\n" - " FTP: ftp_proxy:3333\n" - " SOCKS: socks4://socks_host:5555\n" - " Bypass list: \n" - " *localhost\n" - " 127.0.0.1\n" - " *noproxy.com", - pretty_printed_config); + { + net::ProxyConfig expected_config; + expected_config.proxy_rules().ParseFromString("http=http_proxy:1111; " + "https=ssl_proxy:2222; " + "ftp=ftp_proxy:3333; " + "socks=socks_host:5555"); + expected_config.proxy_rules().bypass_rules.ParseFromString( + "*localhost, 127.0.0.1, *noproxy.com"); + } } TEST_F(FirefoxProxySettingsTest, TestParseAutoConfigUrl) { @@ -108,17 +95,6 @@ TEST_F(FirefoxProxySettingsTest, TestParseAutoConfigUrl) { net::ProxyConfig config; EXPECT_TRUE(settings.ToProxyConfig(&config)); - // Pretty-print |config| to a string (easy way to define the expectations). - std::ostringstream stream; - stream << config; - std::string pretty_printed_config = stream.str(); - - EXPECT_EQ( - "Automatic settings:\n" - " Auto-detect: No\n" - " Custom PAC script: http://custom-pac-url/\n" - "Manual settings:\n" - " Proxy server: [None]\n" - " Bypass list: [None]", - pretty_printed_config); + EXPECT_TRUE(config.Equals(net::ProxyConfig::CreateFromCustomPacURL( + GURL("http://custom-pac-url/")))); } diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 2824b40..cbea511 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -21,13 +21,17 @@ #include "base/file_util.h" #include "base/registry.h" #include "base/scoped_comptr_win.h" +#include "base/string_split.h" #include "base/string_util.h" #include "base/time.h" +#include "base/values.h" +#include "base/utf_string_conversions.h" #include "base/win_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/password_manager/ie7_password.h" +#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/time_format.h" #include "chrome/common/url_constants.h" @@ -258,11 +262,13 @@ void IEImporter::ImportPasswordsIE7() { while (reg_iterator.Valid() && !cancelled()) { // Get the size of the encrypted data. DWORD value_len = 0; - if (key.ReadValue(reg_iterator.Name(), NULL, &value_len) && value_len) { + if (key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL) && + value_len) { // Query the encrypted data. std::vector<unsigned char> value; value.resize(value_len); - if (key.ReadValue(reg_iterator.Name(), &value.front(), &value_len)) { + if (key.ReadValue(reg_iterator.Name(), &value.front(), &value_len, + NULL)) { IE7PasswordInfo password_info; password_info.url_hash = reg_iterator.Name(); password_info.encrypted_data = value; @@ -329,7 +335,7 @@ void IEImporter::ImportHistory() { } if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + bridge_->SetHistoryItems(rows, history::SOURCE_IE_IMPORTED); } } } @@ -461,7 +467,8 @@ bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { // The Link folder name is stored in the registry. DWORD buffer_length = sizeof(buffer); RegKey reg_key(HKEY_CURRENT_USER, - L"Software\\Microsoft\\Internet Explorer\\Toolbar"); + L"Software\\Microsoft\\Internet Explorer\\Toolbar", + KEY_READ); if (!reg_key.ReadValue(L"LinksFolderName", buffer, &buffer_length, NULL)) return false; info->links_folder = buffer; @@ -570,7 +577,7 @@ int IEImporter::CurrentIEVersion() const { wchar_t buffer[128]; DWORD buffer_length = sizeof(buffer); RegKey reg_key(HKEY_LOCAL_MACHINE, - L"Software\\Microsoft\\Internet Explorer"); + L"Software\\Microsoft\\Internet Explorer", KEY_READ); bool result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); version = (result ? _wtoi(buffer) : 0); } diff --git a/chrome/browser/importer/ie_importer.h b/chrome/browser/importer/ie_importer.h index d93405c..1acd27b 100644 --- a/chrome/browser/importer/ie_importer.h +++ b/chrome/browser/importer/ie_importer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IE_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_IE_IMPORTER_H_ +#pragma once #include "base/gtest_prod_util.h" #include "chrome/browser/importer/importer.h" diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 62376c3..2ca7425 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -6,14 +6,18 @@ #include "app/l10n_util.h" #include "base/thread.h" +#include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/browsing_instance.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/importer/firefox_profile_lock.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/renderer_host/site_instance.h" +#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/notification_service.h" #include "gfx/codec/png_codec.h" @@ -100,9 +104,7 @@ void ImporterHost::Loaded(BookmarkModel* model) { waiting_for_bookmarkbar_model_ = false; installed_bookmark_observer_ = false; - std::vector<GURL> starred_urls; - model->GetBookmarks(&starred_urls); - importer_->set_import_to_bookmark_bar(starred_urls.size() == 0); + importer_->set_import_to_bookmark_bar(!model->HasBookmarks()); InvokeTaskIfDone(); } @@ -123,7 +125,7 @@ void ImporterHost::ShowWarningDialog() { OnLockViewEnd(false); } else { #if defined(OS_WIN) - views::Window::CreateChromeWindow(GetActiveWindow(), gfx::Rect(), + views::Window::CreateChromeWindow(NULL, gfx::Rect(), new ImporterLockView(this))->Show(); #elif defined(TOOLKIT_USES_GTK) ImportLockDialogGtk::Show(parent_window_, this); @@ -202,7 +204,8 @@ void ImporterHost::StartImportSettings( SiteInstance* site = instance->GetSiteInstanceForURL(url); Browser* browser = BrowserList::GetLastActive(); browser->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, - TabStripModel::ADD_SELECTED, site, std::string()); + TabStripModel::ADD_SELECTED, site, std::string(), + NULL); MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( this, &ImporterHost::OnLockViewEnd, false)); @@ -258,9 +261,7 @@ void ImporterHost::ImportEnded() { bool ImporterHost::ShouldImportToBookmarkBar(bool first_run) { bool import_to_bookmark_bar = first_run; if (profile_ && profile_->GetBookmarkModel()->IsLoaded()) { - std::vector<GURL> starred_urls; - profile_->GetBookmarkModel()->GetBookmarks(&starred_urls); - import_to_bookmark_bar = (starred_urls.size() == 0); + import_to_bookmark_bar = (!profile_->GetBookmarkModel()->HasBookmarks()); } return import_to_bookmark_bar; } @@ -275,8 +276,7 @@ void ImporterHost::CheckForFirefoxLock( // If fail to acquire the lock, we set the source unreadable and // show a warning dialog, unless running without UI. is_source_readable_ = false; - if (!this->headless_) - ShowWarningDialog(); + ShowWarningDialog(); } } } @@ -304,7 +304,9 @@ void ImporterHost::CheckForLoadedModels(uint16 items) { } ExternalProcessImporterHost::ExternalProcessImporterHost() - : cancelled_(false), + : items_(0), + import_to_bookmark_bar_(false), + cancelled_(false), import_process_launched_(false) { } @@ -314,12 +316,10 @@ void ExternalProcessImporterHost::Loaded(BookmarkModel* model) { waiting_for_bookmarkbar_model_ = false; installed_bookmark_observer_ = false; - std::vector<GURL> starred_urls; - model->GetBookmarks(&starred_urls); // Because the import process is running externally, the decision whether // to import to the bookmark bar must be stored here so that it can be // passed to the importer when the import task is invoked. - import_to_bookmark_bar_ = (starred_urls.size() == 0); + import_to_bookmark_bar_ = (!model->HasBookmarks()); InvokeTaskIfDone(); } @@ -375,7 +375,12 @@ ExternalProcessImporterClient::ExternalProcessImporterClient( int items, InProcessImporterBridge* bridge, bool import_to_bookmark_bar) - : process_importer_host_(importer_host), + : bookmarks_options_(0), + total_bookmarks_count_(0), + total_history_rows_count_(0), + total_fav_icons_count_(0), + process_importer_host_(importer_host), + profile_import_process_host_(NULL), profile_info_(profile_info), items_(items), import_to_bookmark_bar_(import_to_bookmark_bar), @@ -496,14 +501,16 @@ void ExternalProcessImporterClient::OnHistoryImportStart( } void ExternalProcessImporterClient::OnHistoryImportGroup( - const std::vector<history::URLRow> &history_rows_group) { + const std::vector<history::URLRow>& history_rows_group, + int visit_source) { if (cancelled_) return; history_rows_.insert(history_rows_.end(), history_rows_group.begin(), history_rows_group.end()); if (history_rows_.size() == total_history_rows_count_) - bridge_->SetHistoryItems(history_rows_); + bridge_->SetHistoryItems(history_rows_, + static_cast<history::VisitSource>(visit_source)); } void ExternalProcessImporterClient::OnHomePageImportReady( diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index eec498b..14be8c2 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_IMPORTER_H_ +#pragma once #include <string> #include <vector> @@ -13,16 +14,14 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/time.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/importer/importer_list.h" #include "chrome/browser/importer/profile_writer.h" #include "chrome/browser/profile_import_process_host.h" +#include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "gfx/native_widget_types.h" -#include "googleurl/src/gurl.h" using importer::ImportItem; using importer::ProfileInfo; @@ -30,6 +29,7 @@ using importer::ProfileInfo; class ExternalProcessImporterClient; class ImporterBridge; class InProcessImporterBridge; +class GURL; class Profile; class Task; class TemplateURL; @@ -345,8 +345,10 @@ class ExternalProcessImporterClient virtual void OnHistoryImportStart(size_t total_history_rows_count); // Called when a group of URLRows has been received. + // The source is passed with history::VisitSource type. virtual void OnHistoryImportGroup( - const std::vector<history::URLRow> &history_rows_group); + const std::vector<history::URLRow> &history_rows_group, + int visit_source); // Called when the home page has been received. virtual void OnHomePageImportReady(const GURL& home_page); diff --git a/chrome/browser/importer/importer_bridge.cc b/chrome/browser/importer/importer_bridge.cc index 72a73a6..079ebe3 100644 --- a/chrome/browser/importer/importer_bridge.cc +++ b/chrome/browser/importer/importer_bridge.cc @@ -6,6 +6,9 @@ #include "app/l10n_util.h" #include "base/scoped_ptr.h" +#include "base/string_number_conversions.h" +#include "base/string16.h" +#include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/history/history_types.h" @@ -58,10 +61,12 @@ void InProcessImporterBridge::SetFavIcons( } void InProcessImporterBridge::SetHistoryItems( - const std::vector<history::URLRow> &rows) { + const std::vector<history::URLRow> &rows, + history::VisitSource visit_source) { ChromeThread::PostTask( ChromeThread::UI, FROM_HERE, - NewRunnableMethod(writer_, &ProfileWriter::AddHistoryPage, rows)); + NewRunnableMethod(writer_, &ProfileWriter::AddHistoryPage, + rows, visit_source)); } void InProcessImporterBridge::SetKeywords( @@ -147,8 +152,9 @@ void ExternalProcessImporterBridge::SetFavIcons( } void ExternalProcessImporterBridge::SetHistoryItems( - const std::vector<history::URLRow> &rows) { - profile_import_thread_->NotifyHistoryImportReady(rows); + const std::vector<history::URLRow> &rows, + history::VisitSource visit_source) { + profile_import_thread_->NotifyHistoryImportReady(rows, visit_source); } void ExternalProcessImporterBridge::SetKeywords( @@ -181,10 +187,10 @@ void ExternalProcessImporterBridge::NotifyEnded() { // The internal process detects import end when all items have been received. } +// TODO(viettrungluu): convert to string16. std::wstring ExternalProcessImporterBridge::GetLocalizedString( int message_id) { - std::wstring message; - localized_strings_->GetString(IntToWString(message_id), &message); - return message; + string16 message; + localized_strings_->GetString(base::IntToString(message_id), &message); + return UTF16ToWideHack(message); } - diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h index 993ec54..8b57ab0 100644 --- a/chrome/browser/importer/importer_bridge.h +++ b/chrome/browser/importer/importer_bridge.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ #define CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ +#pragma once #include "build/build_config.h" @@ -12,7 +13,6 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/string16.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/importer/importer_data_types.h" // TODO: remove this, see friend declaration in ImporterBridge. @@ -38,7 +38,8 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { virtual void SetFavIcons( const std::vector<history::ImportedFavIconUsage>& fav_icons) = 0; - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows) = 0; + virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, + history::VisitSource visit_source) = 0; virtual void SetKeywords(const std::vector<TemplateURL*> &template_urls, int default_keyword_index, bool unique_on_host_and_path) = 0; @@ -95,7 +96,8 @@ class InProcessImporterBridge : public ImporterBridge { virtual void SetFavIcons( const std::vector<history::ImportedFavIconUsage>& fav_icons); - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows); + virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, + history::VisitSource visit_source); virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, int default_keyword_index, bool unique_on_host_and_path); @@ -140,7 +142,8 @@ class ExternalProcessImporterBridge : public ImporterBridge { virtual void SetFavIcons( const std::vector<history::ImportedFavIconUsage>& fav_icons); - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows); + virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, + history::VisitSource visit_source); virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, int default_keyword_index, bool unique_on_host_and_path); diff --git a/chrome/browser/importer/importer_data_types.h b/chrome/browser/importer/importer_data_types.h index 444cc45..e4af8fb 100644 --- a/chrome/browser/importer/importer_data_types.h +++ b/chrome/browser/importer/importer_data_types.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_DATA_TYPES_H_ #define CHROME_BROWSER_IMPORTER_IMPORTER_DATA_TYPES_H_ +#pragma once #include <string> @@ -34,7 +35,7 @@ enum ProfileType { MS_IE = 0, #endif FIREFOX2 = 1, - FIREFOX3 = 2, + FIREFOX3 = 2, // Firefox 3 and later. #if defined(OS_MACOSX) SAFARI = 3, #endif diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc index 0919489..ba2bf83 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -9,7 +9,7 @@ #include "base/stl_util-inl.h" #include "base/values.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/first_run.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/importer/firefox2_importer.h" #include "chrome/browser/importer/firefox3_importer.h" #include "chrome/browser/importer/firefox_importer_utils.h" @@ -19,7 +19,6 @@ #include "grit/generated_resources.h" #if defined(OS_WIN) -#include "app/win_util.h" #include "chrome/browser/importer/ie_importer.h" #include "chrome/browser/password_manager/ie7_password.h" #endif @@ -130,12 +129,12 @@ void ImporterList::DetectFirefoxProfiles() { #if defined(OS_WIN) version = GetCurrentFirefoxMajorVersionFromRegistry(); #endif - if (version != 2 && version != 3) + if (version < 2) GetFirefoxVersionAndPathFromProfile(profile_path, &version, &app_path); if (version == 2) { firefox_type = importer::FIREFOX2; - } else if (version == 3) { + } else if (version >= 3) { firefox_type = importer::FIREFOX3; } else { // Ignores other versions of firefox. diff --git a/chrome/browser/importer/importer_list.h b/chrome/browser/importer/importer_list.h index c76aab3..6f98046 100644 --- a/chrome/browser/importer/importer_list.h +++ b/chrome/browser/importer/importer_list.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ #define CHROME_BROWSER_IMPORTER_IMPORTER_LIST_H_ +#pragma once #include <string> #include <vector> diff --git a/chrome/browser/importer/importer_messages.h b/chrome/browser/importer/importer_messages.h index 4bbba62..fd7b1dc 100644 --- a/chrome/browser/importer/importer_messages.h +++ b/chrome/browser/importer/importer_messages.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_IMPORTER_MESSAGES_H_ #define CHROME_BROWSER_IMPORTER_IMPORTER_MESSAGES_H_ +#pragma once #include <string> #include <vector> @@ -49,18 +50,18 @@ struct ParamTraits<importer::ProfileInfo> { return true; } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"("); + static void Log(const param_type& p, std::string* l) { + l->append("("); LogParam(p.description, l); - l->append(L", "); + l->append(", "); LogParam(static_cast<int>(p.browser_type), l); - l->append(L", "); + l->append(", "); LogParam(p.source_path, l); - l->append(L", "); + l->append(", "); LogParam(p.app_path, l); - l->append(L", "); + l->append(", "); LogParam(static_cast<int>(p.services_supported), l); - l->append(L")"); + l->append(")"); } }; // ParamTraits<importer::ProfileInfo> @@ -104,24 +105,24 @@ struct ParamTraits<history::URLRow> { p->set_favicon_id(favicon_id); return true; } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"("); + static void Log(const param_type& p, std::string* l) { + l->append("("); LogParam(p.id(), l); - l->append(L", "); + l->append(", "); LogParam(p.url(), l); - l->append(L", "); + l->append(", "); LogParam(p.title(), l); - l->append(L", "); + l->append(", "); LogParam(p.visit_count(), l); - l->append(L", "); + l->append(", "); LogParam(p.typed_count(), l); - l->append(L", "); + l->append(", "); LogParam(p.last_visit(), l); - l->append(L", "); + l->append(", "); LogParam(p.hidden(), l); - l->append(L", "); + l->append(", "); LogParam(p.favicon_id(), l); - l->append(L")"); + l->append(")"); } }; // ParamTraits<history::URLRow> @@ -144,18 +145,18 @@ struct ParamTraits<ProfileWriter::BookmarkEntry> { (ReadParam(m, iter, &p->title)) && (ReadParam(m, iter, &p->creation_time)); } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"("); + static void Log(const param_type& p, std::string* l) { + l->append("("); LogParam(p.in_toolbar, l); - l->append(L", "); + l->append(", "); LogParam(p.url, l); - l->append(L", "); + l->append(", "); LogParam(p.path, l); - l->append(L", "); + l->append(", "); LogParam(p.title, l); - l->append(L", "); + l->append(", "); LogParam(p.creation_time, l); - l->append(L")"); + l->append(")"); } }; // ParamTraits<ProfileWriter::BookmarkEntry> @@ -174,14 +175,14 @@ struct ParamTraits<history::ImportedFavIconUsage> { ReadParam(m, iter, &p->png_data) && ReadParam(m, iter, &p->urls); } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"("); + static void Log(const param_type& p, std::string* l) { + l->append("("); LogParam(p.favicon_url, l); - l->append(L", "); + l->append(", "); LogParam(p.png_data, l); - l->append(L", "); + l->append(", "); LogParam(p.urls, l); - l->append(L")"); + l->append(")"); } }; // ParamTraits<history::ImportedFavIconUsage @@ -205,8 +206,8 @@ struct ParamTraits<TemplateURLRef> { *p = TemplateURLRef(url, index_offset, page_offset); return true; } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<TemplateURLRef>"); + static void Log(const param_type& p, std::string* l) { + l->append("<TemplateURLRef>"); } }; @@ -233,8 +234,8 @@ struct ParamTraits<TemplateURL::ImageRef> { *p = TemplateURL::ImageRef(type, width, height, url); // here in return true; } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<TemplateURL::ImageRef>"); + static void Log(const param_type& p, std::string* l) { + l->append("<TemplateURL::ImageRef>"); } }; @@ -355,8 +356,8 @@ struct ParamTraits<TemplateURL> { p->set_prepopulate_id(prepopulate_id); return true; } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<TemplateURL>"); + static void Log(const param_type& p, std::string* l) { + l->append("<TemplateURL>"); } }; diff --git a/chrome/browser/importer/importer_messages_internal.h b/chrome/browser/importer/importer_messages_internal.h index b247237..980e397 100644 --- a/chrome/browser/importer/importer_messages_internal.h +++ b/chrome/browser/importer/importer_messages_internal.h @@ -49,8 +49,10 @@ IPC_BEGIN_MESSAGES(ProfileImportProcessHost) IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHistoryImportStart, int /* total number of history::URLRow items */) - IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHistoryImportGroup, - std::vector<history::URLRow>) + IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyHistoryImportGroup, + std::vector<history::URLRow>, + int /* the source of URLs as in history::VisitSource.*/ + /* To simplify IPC call, pass as an integer */) IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyHomePageImportReady, GURL /* GURL of home page */) diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 1dce41e..879d7cb 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -21,7 +21,9 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/stl_util-inl.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/browser/chrome_thread.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/importer/importer.h" @@ -257,12 +259,15 @@ class TestObserver : public ProfileWriter, ++password_count_; } - virtual void AddHistoryPage(const std::vector<history::URLRow>& page) { + virtual void AddHistoryPage(const std::vector<history::URLRow>& page, + history::VisitSource visit_source) { // Importer should read the specified URL. - for (size_t i = 0; i < page.size(); ++i) + for (size_t i = 0; i < page.size(); ++i) { if (page[i].title() == kIEIdentifyTitle && page[i].url() == GURL(kIEIdentifyUrl)) ++history_count_; + } + EXPECT_EQ(history::SOURCE_IE_IMPORTED, visit_source); } virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark, @@ -608,10 +613,12 @@ class FirefoxObserver : public ProfileWriter, ++password_count_; } - virtual void AddHistoryPage(const std::vector<history::URLRow>& page) { + virtual void AddHistoryPage(const std::vector<history::URLRow>& page, + history::VisitSource visit_source) { ASSERT_EQ(1U, page.size()); EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); + EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); ++history_count_; } @@ -804,7 +811,8 @@ class Firefox3Observer : public ProfileWriter, ++password_count_; } - virtual void AddHistoryPage(const std::vector<history::URLRow>& page) { + virtual void AddHistoryPage(const std::vector<history::URLRow>& page, + history::VisitSource visit_source) { ASSERT_EQ(3U, page.size()); EXPECT_EQ("http://www.google.com/", page[0].url().spec()); EXPECT_EQ(ASCIIToUTF16("Google"), page[0].title()); @@ -813,6 +821,7 @@ class Firefox3Observer : public ProfileWriter, EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/form1-POST.html", page[2].url().spec()); EXPECT_EQ(ASCIIToUTF16("example form (POST)"), page[2].title()); + EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); ++history_count_; } diff --git a/chrome/browser/importer/mork_reader.cc b/chrome/browser/importer/mork_reader.cc index 49dadb0..ce1ffe8 100644 --- a/chrome/browser/importer/mork_reader.cc +++ b/chrome/browser/importer/mork_reader.cc @@ -48,7 +48,9 @@ #include "base/i18n/icu_string_conversions.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" +#include "base/values.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/importer/firefox_importer_utils.h" #include "chrome/browser/importer/importer.h" @@ -530,9 +532,10 @@ void AddToHistory(MorkReader::ColumnDataList* column_values, count = 1; row.set_visit_count(count); - time_t date = StringToInt64(values[kLastVisitColumn]); + int64 date; + base::StringToInt64(values[kLastVisitColumn], &date); if (date != 0) - row.set_last_visit(Time::FromTimeT(date/1000000)); + row.set_last_visit(Time::FromTimeT(date / 1000000)); bool is_typed = (values[kTypedColumn] == "1"); if (is_typed) @@ -581,5 +584,5 @@ void ImportHistoryFromFirefox2(const FilePath& file, ImporterBridge* bridge) { for (MorkReader::iterator i = reader.begin(); i != reader.end(); ++i) AddToHistory(i->second, data, &rows); if (!rows.empty()) - bridge->SetHistoryItems(rows); + bridge->SetHistoryItems(rows, history::SOURCE_FIREFOX_IMPORTED); } diff --git a/chrome/browser/importer/mork_reader.h b/chrome/browser/importer/mork_reader.h index cb61be5..6f7f8ca 100644 --- a/chrome/browser/importer/mork_reader.h +++ b/chrome/browser/importer/mork_reader.h @@ -41,6 +41,7 @@ #ifndef CHROME_BROWSER_IMPORTER_MORK_READER_H__ #define CHROME_BROWSER_IMPORTER_MORK_READER_H__ +#pragma once #include <iosfwd> #include <fstream> diff --git a/chrome/browser/importer/nss_decryptor.cc b/chrome/browser/importer/nss_decryptor.cc index 91149e2..98522c6 100644 --- a/chrome/browser/importer/nss_decryptor.cc +++ b/chrome/browser/importer/nss_decryptor.cc @@ -17,6 +17,7 @@ #endif // defined(USE_NSS) #include "base/base64.h" +#include "base/string_split.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "webkit/glue/password_form.h" diff --git a/chrome/browser/importer/nss_decryptor.h b/chrome/browser/importer/nss_decryptor.h index c133665..8361d17 100644 --- a/chrome/browser/importer/nss_decryptor.h +++ b/chrome/browser/importer/nss_decryptor.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_H_ #define CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_H_ +#pragma once #include "build/build_config.h" diff --git a/chrome/browser/importer/nss_decryptor_mac.h b/chrome/browser/importer/nss_decryptor_mac.h index af1b004..5e0eeff 100644 --- a/chrome/browser/importer/nss_decryptor_mac.h +++ b/chrome/browser/importer/nss_decryptor_mac.h @@ -1,16 +1,18 @@ -// 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. #ifndef CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_MAC_H_ #define CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_MAC_H_ +#pragma once #include <string> #include <vector> #include "base/basictypes.h" -#include "base/file_path.h" -#include "base/logging.h" +#include "base/string16.h" + +class FilePath; // The following declarations of functions and types are from Firefox // NSS library. diff --git a/chrome/browser/importer/nss_decryptor_mac.mm b/chrome/browser/importer/nss_decryptor_mac.mm index e319c74..988ab56 100644 --- a/chrome/browser/importer/nss_decryptor_mac.mm +++ b/chrome/browser/importer/nss_decryptor_mac.mm @@ -6,13 +6,13 @@ #include <dlfcn.h> +#include "base/file_path.h" +#include "base/logging.h" #include "base/sys_string_conversions.h" #include "chrome/browser/importer/nss_decryptor_mac.h" #include "chrome/browser/importer/firefox_importer_utils.h" -#include "base/logging.h" - // static const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; diff --git a/chrome/browser/importer/nss_decryptor_system_nss.h b/chrome/browser/importer/nss_decryptor_system_nss.h index 7071428..c08496d 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.h +++ b/chrome/browser/importer/nss_decryptor_system_nss.h @@ -1,16 +1,19 @@ -// 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. #ifndef CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_SYSTEM_NSS_H_ #define CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_SYSTEM_NSS_H_ +#pragma once #include <secmodt.h> #include <string> #include <vector> #include "base/basictypes.h" -#include "base/file_path.h" +#include "base/string16.h" + +class FilePath; namespace webkit_glue { struct PasswordForm; diff --git a/chrome/browser/importer/nss_decryptor_win.h b/chrome/browser/importer/nss_decryptor_win.h index f0b2345..0436323 100644 --- a/chrome/browser/importer/nss_decryptor_win.h +++ b/chrome/browser/importer/nss_decryptor_win.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_WIN_H_ #define CHROME_BROWSER_IMPORTER_NSS_DECRYPTOR_WIN_H_ +#pragma once #include <string> #include <vector> diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index 0061efc..93d6248 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -6,11 +6,13 @@ #include "base/string_util.h" #include "base/thread.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/pref_service.h" +#include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profile.h" +#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" @@ -35,9 +37,10 @@ void ProfileWriter::AddIE7PasswordInfo(const IE7PasswordInfo& info) { } #endif -void ProfileWriter::AddHistoryPage(const std::vector<history::URLRow>& page) { +void ProfileWriter::AddHistoryPage(const std::vector<history::URLRow>& page, + history::VisitSource visit_source) { profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)-> - AddPagesWithDetails(page); + AddPagesWithDetails(page, visit_source); } void ProfileWriter::AddHomepage(const GURL& home_page) { @@ -99,18 +102,19 @@ void ProfileWriter::AddBookmarkEntry( const BookmarkNode* node = parent->GetChild(index); if ((node->type() == BookmarkNode::BOOKMARK_BAR || node->type() == BookmarkNode::FOLDER) && - node->GetTitle() == folder_name) { + node->GetTitle() == WideToUTF16Hack(folder_name)) { child = node; break; } } if (child == NULL) - child = model->AddGroup(parent, parent->GetChildCount(), folder_name); + child = model->AddGroup(parent, parent->GetChildCount(), + WideToUTF16Hack(folder_name)); parent = child; } groups_added_to.insert(parent); model->AddURLWithCreationTime(parent, parent->GetChildCount(), - it->title, it->url, it->creation_time); + WideToUTF16Hack(it->title), it->url, it->creation_time); // If some items are put into toolbar, it looks like the user was using // it in their last browser. We turn on the bookmarks toolbar. @@ -283,7 +287,7 @@ std::wstring ProfileWriter::GenerateUniqueFolderName( for (int i = 0, child_count = other->GetChildCount(); i < child_count; ++i) { const BookmarkNode* node = other->GetChild(i); if (node->is_folder()) - other_folder_names.insert(node->GetTitle()); + other_folder_names.insert(UTF16ToWideHack(node->GetTitle())); } if (other_folder_names.find(folder_name) == other_folder_names.end()) @@ -311,7 +315,7 @@ bool ProfileWriter::DoesBookmarkExist( for (size_t i = 0; i < nodes_with_same_url.size(); ++i) { const BookmarkNode* node = nodes_with_same_url[i]; - if (entry.title != node->GetTitle()) + if (WideToUTF16Hack(entry.title) != node->GetTitle()) continue; // Does the path match? diff --git a/chrome/browser/importer/profile_writer.h b/chrome/browser/importer/profile_writer.h index 38e04d8..a8571cb 100644 --- a/chrome/browser/importer/profile_writer.h +++ b/chrome/browser/importer/profile_writer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ #define CHROME_BROWSER_IMPORTER_PROFILE_WRITER_H_ +#pragma once #include <string> #include <vector> @@ -11,6 +12,7 @@ #include "base/ref_counted.h" #include "base/time.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" +#include "chrome/browser/history/history_types.h" #include "googleurl/src/gurl.h" class Profile; @@ -71,7 +73,8 @@ class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> { #if defined(OS_WIN) virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info); #endif - virtual void AddHistoryPage(const std::vector<history::URLRow>& page); + virtual void AddHistoryPage(const std::vector<history::URLRow>& page, + history::VisitSource visit_source); virtual void AddHomepage(const GURL& homepage); // Adds the bookmarks to the BookmarkModel. // |options| is a bitmask of BookmarkOptions and dictates how and diff --git a/chrome/browser/importer/safari_importer.h b/chrome/browser/importer/safari_importer.h index 6b686e9..e723146 100644 --- a/chrome/browser/importer/safari_importer.h +++ b/chrome/browser/importer/safari_importer.h @@ -4,6 +4,7 @@ #ifndef CHROME_BROWSER_IMPORTER_SAFARI_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_SAFARI_IMPORTER_H_ +#pragma once #include "chrome/browser/importer/importer.h" diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm index 9a30073..3ff4676 100644 --- a/chrome/browser/importer/safari_importer.mm +++ b/chrome/browser/importer/safari_importer.mm @@ -15,6 +15,7 @@ #include "base/string16.h" #include "base/sys_string_conversions.h" #include "base/time.h" +#include "base/values.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" @@ -316,7 +317,7 @@ void SafariImporter::ImportHistory() { ParseHistoryItems(&rows); if (!rows.empty() && !cancelled()) { - bridge_->SetHistoryItems(rows); + bridge_->SetHistoryItems(rows, history::SOURCE_SAFARI_IMPORTED); } } diff --git a/chrome/browser/importer/safari_importer_unittest.mm b/chrome/browser/importer/safari_importer_unittest.mm index 081c26e..36f233a 100644 --- a/chrome/browser/importer/safari_importer_unittest.mm +++ b/chrome/browser/importer/safari_importer_unittest.mm @@ -10,6 +10,7 @@ #include "base/path_service.h" #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/browser/history/history_types.h" #include "chrome/common/chrome_paths.h" #include "chrome/test/file_test_utils.h" diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc index 5b0a93c..ad9ad61 100644 --- a/chrome/browser/importer/toolbar_importer.cc +++ b/chrome/browser/importer/toolbar_importer.cc @@ -7,9 +7,13 @@ #include <limits> #include "base/rand_util.h" +#include "base/string_split.h" +#include "base/string_util.h" +#include "base/string_number_conversions.h" #include "base/utf_string_conversions.h" +#include "base/values.h" #include "chrome/browser/chrome_thread.h" -#include "chrome/browser/first_run.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/importer/importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" #include "chrome/browser/profile.h" @@ -231,7 +235,7 @@ void Toolbar5Importer::GetAuthenticationFromServer() { // Random number construction. int random = base::RandInt(0, std::numeric_limits<int>::max()); - std::string random_string = UintToString(random); + std::string random_string = base::UintToString(random); // Retrieve authorization token from the network. std::string url_string(kT5AuthorizationTokenUrl); @@ -264,7 +268,7 @@ void Toolbar5Importer::GetBookmarkDataFromServer(const std::string& response) { // the xml blob. We must tag the connection string with a random number. std::string conn_string = kT5FrontEndUrlTemplate; int random = base::RandInt(0, std::numeric_limits<int>::max()); - std::string random_string = UintToString(random); + std::string random_string = base::UintToString(random); conn_string.replace(conn_string.find(kRandomNumberToken), arraysize(kRandomNumberToken) - 1, random_string); @@ -520,7 +524,7 @@ bool Toolbar5Importer::ExtractTimeFromXmlReader( return false; } int64 timestamp; - if (!StringToInt64(buffer, ×tamp)) { + if (!base::StringToInt64(buffer, ×tamp)) { return false; } entry->creation_time = base::Time::FromTimeT(timestamp); diff --git a/chrome/browser/importer/toolbar_importer.h b/chrome/browser/importer/toolbar_importer.h index 0f31832..1def25d 100644 --- a/chrome/browser/importer/toolbar_importer.h +++ b/chrome/browser/importer/toolbar_importer.h @@ -7,6 +7,7 @@ #ifndef CHROME_BROWSER_IMPORTER_TOOLBAR_IMPORTER_H_ #define CHROME_BROWSER_IMPORTER_TOOLBAR_IMPORTER_H_ +#pragma once #include <string> #include <vector> diff --git a/chrome/browser/importer/toolbar_importer_unittest.cc b/chrome/browser/importer/toolbar_importer_unittest.cc index 0bc6ab5..6b042de 100644 --- a/chrome/browser/importer/toolbar_importer_unittest.cc +++ b/chrome/browser/importer/toolbar_importer_unittest.cc @@ -8,7 +8,9 @@ #include <vector> #include "base/string16.h" -#include "chrome/browser/first_run.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/first_run/first_run.h" #include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/toolbar_importer.h" #include "chrome/common/libxml_utils.h" @@ -318,7 +320,7 @@ static const char* kBadBookmarkNoLabels = // Test doesn't work if the importer thinks this is the first run of Chromium. // Mark this as a subsequent run of the browser. - FirstRun::CreateSentinel(); + FirstRun::first_run_ = FirstRun::FIRST_RUN_FALSE; // Test case 1 is parsing a basic bookmark with a single label. bookmark_xml = kGoodBookmark; |