summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 19:10:18 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 19:10:18 +0000
commit2011cae921b2d88be4b8e4f31197dd8bdd2c56b3 (patch)
tree8fa84ba0161024c9c23116144f353541184f0ce5 /chrome
parent9866440c2a379bab6fa7e1947405df00958ca3b9 (diff)
downloadchromium_src-2011cae921b2d88be4b8e4f31197dd8bdd2c56b3.zip
chromium_src-2011cae921b2d88be4b8e4f31197dd8bdd2c56b3.tar.gz
chromium_src-2011cae921b2d88be4b8e4f31197dd8bdd2c56b3.tar.bz2
browser porting, part 2 - importer
Review URL: http://codereview.chromium.org/12688 Patch from Pawel Hajdan jr. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.vcproj4
-rw-r--r--chrome/browser/importer/firefox2_importer.cc11
-rw-r--r--chrome/browser/importer/firefox_importer_unittest.cc17
-rw-r--r--chrome/browser/importer/firefox_importer_utils.h5
-rw-r--r--chrome/browser/importer/firefox_profile_lock.cc34
-rw-r--r--chrome/browser/importer/firefox_profile_lock.h18
-rw-r--r--chrome/browser/importer/firefox_profile_lock_posix.cc79
-rw-r--r--chrome/browser/importer/firefox_profile_lock_win.cc77
-rw-r--r--chrome/browser/importer/ie_importer.cc2
-rw-r--r--chrome/browser/importer/importer.cc1
-rw-r--r--chrome/browser/importer/importer.h11
-rw-r--r--chrome/browser/importer/importer_unittest.cc1
-rw-r--r--chrome/browser/importer/mork_reader.cc4
13 files changed, 217 insertions, 47 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 7d79e5d..00ba48d 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -1562,6 +1562,10 @@
>
</File>
<File
+ RelativePath=".\importer\firefox_profile_lock_win.cc"
+ >
+ </File>
+ <File
RelativePath=".\importer\ie_importer.cc"
>
</File>
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index aef2ba2..9aee0ca 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -4,9 +4,9 @@
#include "chrome/browser/importer/firefox2_importer.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
-#include "base/registry.h"
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/browser/importer/firefox_importer_utils.h"
@@ -69,16 +69,19 @@ void Firefox2Importer::StartImport(ProfileInfo profile_info,
// static
void Firefox2Importer::LoadDefaultBookmarks(const std::wstring& app_path,
std::set<GURL> *urls) {
+ // TODO(port): Code below is correct only on Windows.
// Firefox keeps its default bookmarks in a bookmarks.html file that
// lives at: <Firefox install dir>\defaults\profile\bookmarks.html
- std::wstring file = app_path;
- file_util::AppendToPath(&file, L"defaults\\profile\\bookmarks.html");
+ FilePath file = FilePath::FromWStringHack(app_path);
+ file.Append(FILE_PATH_LITERAL("defaults"));
+ file.Append(FILE_PATH_LITERAL("profile"));
+ file.Append(FILE_PATH_LITERAL("bookmarks.html"));
urls->clear();
// Read the whole file.
std::string content;
- file_util::ReadFileToString(file, &content);
+ file_util::ReadFileToString(file.ToWStringHack(), &content);
std::vector<std::string> lines;
SplitString(content, '\n', &lines);
diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/firefox_importer_unittest.cc
index 742a806..2ff34b3 100644
--- a/chrome/browser/importer/firefox_importer_unittest.cc
+++ b/chrome/browser/importer/firefox_importer_unittest.cc
@@ -4,6 +4,7 @@
#include "testing/gtest/include/gtest/gtest.h"
+#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "chrome/browser/importer/firefox2_importer.h"
@@ -146,8 +147,8 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
TEST(FirefoxImporterTest, ProfileLock) {
std::wstring test_path;
file_util::CreateNewTempDirectory(L"firefox_profile", &test_path);
- std::wstring lock_file_path = test_path;
- file_util::AppendToPath(&lock_file_path, FirefoxProfileLock::kLockFileName);
+ FilePath lock_file_path = FilePath::FromWStringHack(test_path);
+ lock_file_path.Append(FirefoxProfileLock::kLockFileName);
scoped_ptr<FirefoxProfileLock> lock;
EXPECT_EQ(static_cast<FirefoxProfileLock*>(NULL), lock.get());
@@ -173,15 +174,13 @@ TEST(FirefoxImporterTest, ProfileLock) {
TEST(FirefoxImporterTest, ProfileLockOrphaned) {
std::wstring test_path;
file_util::CreateNewTempDirectory(L"firefox_profile", &test_path);
- std::wstring lock_file_path = test_path;
- file_util::AppendToPath(&lock_file_path, FirefoxProfileLock::kLockFileName);
+ FilePath lock_file_path = FilePath::FromWStringHack(test_path);
+ lock_file_path.Append(FirefoxProfileLock::kLockFileName);
// Create the orphaned lock file.
- HANDLE lock_file = CreateFile(lock_file_path.c_str(),
- GENERIC_READ | GENERIC_WRITE,
- 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
- NULL);
- CloseHandle(lock_file);
+ FILE* lock_file = file_util::OpenFile(lock_file_path, "w");
+ ASSERT_TRUE(lock_file);
+ file_util::CloseFile(lock_file);
EXPECT_TRUE(file_util::PathExists(lock_file_path));
scoped_ptr<FirefoxProfileLock> lock;
diff --git a/chrome/browser/importer/firefox_importer_utils.h b/chrome/browser/importer/firefox_importer_utils.h
index 165ce2d..4bf287c 100644
--- a/chrome/browser/importer/firefox_importer_utils.h
+++ b/chrome/browser/importer/firefox_importer_utils.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_
#include "base/values.h"
+#include "build/build_config.h"
#include "webkit/glue/password_form.h"
class GURL;
@@ -198,14 +199,16 @@ class NSSDecryptor {
static const wchar_t kPLDS4Library[];
static const wchar_t kNSPR4Library[];
+#if defined(OS_WIN)
// NSS3 module handles.
HMODULE nss3_dll_;
HMODULE softokn3_dll_;
+#endif
// True if NSS_Init() has been called
bool is_nss_initialized_;
- DISALLOW_EVIL_CONSTRUCTORS(NSSDecryptor);
+ DISALLOW_COPY_AND_ASSIGN(NSSDecryptor);
};
#endif // CHROME_BROWSER_IMPORTER_FIREFOX_IMPORTER_UTILS_H_
diff --git a/chrome/browser/importer/firefox_profile_lock.cc b/chrome/browser/importer/firefox_profile_lock.cc
index aaab891..777723c 100644
--- a/chrome/browser/importer/firefox_profile_lock.cc
+++ b/chrome/browser/importer/firefox_profile_lock.cc
@@ -4,7 +4,7 @@
#include "chrome/browser/importer/firefox_profile_lock.h"
-#include "base/file_util.h"
+#include "base/file_path.h"
// This class is based on Firefox code in:
// profile/dirserviceprovider/src/nsProfileLock.cpp
@@ -52,36 +52,16 @@
* ***** END LICENSE BLOCK ***** */
// static
-wchar_t FirefoxProfileLock::kLockFileName[] = L"parent.lock";
+const FilePath::CharType* FirefoxProfileLock::kLockFileName =
+ FILE_PATH_LITERAL("parent.local");
-FirefoxProfileLock::FirefoxProfileLock(const std::wstring& path)
- : lock_handle_(INVALID_HANDLE_VALUE) {
- lock_file_ = path;
- file_util::AppendToPath(&lock_file_, kLockFileName);
+FirefoxProfileLock::FirefoxProfileLock(const std::wstring& path) {
+ Init();
+ lock_file_ = FilePath::FromWStringHack(path);
+ lock_file_.Append(kLockFileName);
Lock();
}
FirefoxProfileLock::~FirefoxProfileLock() {
Unlock();
}
-
-void FirefoxProfileLock::Lock() {
- if (HasAcquired())
- return;
- lock_handle_ = CreateFile(lock_file_.c_str(), GENERIC_READ | GENERIC_WRITE,
- 0, NULL, OPEN_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE,
- NULL);
-}
-
-void FirefoxProfileLock::Unlock() {
- if (!HasAcquired())
- return;
- CloseHandle(lock_handle_);
- lock_handle_ = INVALID_HANDLE_VALUE;
-}
-
-bool FirefoxProfileLock::HasAcquired() {
- return (lock_handle_ != INVALID_HANDLE_VALUE);
-}
-
-
diff --git a/chrome/browser/importer/firefox_profile_lock.h b/chrome/browser/importer/firefox_profile_lock.h
index c32d592..8b402cf 100644
--- a/chrome/browser/importer/firefox_profile_lock.h
+++ b/chrome/browser/importer/firefox_profile_lock.h
@@ -5,11 +5,16 @@
#ifndef CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__
#define CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
#include <windows.h>
+#endif
#include <string>
#include "base/basictypes.h"
+#include "base/file_path.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
// Firefox is designed to allow only one application to access its
@@ -78,16 +83,21 @@ class FirefoxProfileLock {
FRIEND_TEST(FirefoxImporterTest, ProfileLock);
FRIEND_TEST(FirefoxImporterTest, ProfileLockOrphaned);
- // The name of the lock file.
- static wchar_t kLockFileName[];
+ static const FilePath::CharType* kLockFileName;
+
+ void Init();
// Full path of the lock file in the profile folder.
- std::wstring lock_file_;
+ FilePath lock_file_;
// The handle of the lock file.
+#if defined(OS_WIN)
HANDLE lock_handle_;
+#elif defined(OS_POSIX)
+ int lock_fd_;
+#endif
- DISALLOW_EVIL_CONSTRUCTORS(FirefoxProfileLock);
+ DISALLOW_COPY_AND_ASSIGN(FirefoxProfileLock);
};
#endif // CHROME_BROWSER_IMPORTER_FIREFOX_PROFILE_LOCK_H__
diff --git a/chrome/browser/importer/firefox_profile_lock_posix.cc b/chrome/browser/importer/firefox_profile_lock_posix.cc
new file mode 100644
index 0000000..0058bb2
--- /dev/null
+++ b/chrome/browser/importer/firefox_profile_lock_posix.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2008 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 "chrome/browser/importer/firefox_profile_lock.h"
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "base/file_util.h"
+
+// This class is based on Firefox code in:
+// profile/dirserviceprovider/src/nsProfileLock.cpp
+// The license block is:
+
+/* ***** BEGIN LICENSE BLOCK *****
+* Version: MPL 1.1/GPL 2.0/LGPL 2.1
+*
+* The contents of this file are subject to the Mozilla Public License Version
+* 1.1 (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+* for the specific language governing rights and limitations under the
+* License.
+*
+* The Original Code is mozilla.org code.
+*
+* The Initial Developer of the Original Code is
+* Netscape Communications Corporation.
+* Portions created by the Initial Developer are Copyright (C) 2002
+* the Initial Developer. All Rights Reserved.
+*
+* Contributor(s):
+* Conrad Carlen <ccarlen@netscape.com>
+* Brendan Eich <brendan@mozilla.org>
+* Colin Blake <colin@theblakes.com>
+* Javier Pedemonte <pedemont@us.ibm.com>
+* Mats Palmgren <mats.palmgren@bredband.net>
+*
+* Alternatively, the contents of this file may be used under the terms of
+* either the GNU General Public License Version 2 or later (the "GPL"), or
+* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+* in which case the provisions of the GPL or the LGPL are applicable instead
+* of those above. If you wish to allow use of your version of this file only
+* under the terms of either the GPL or the LGPL, and not to allow others to
+* use your version of this file under the terms of the MPL, indicate your
+* decision by deleting the provisions above and replace them with the notice
+* and other provisions required by the GPL or the LGPL. If you do not delete
+* the provisions above, a recipient may use your version of this file under
+* the terms of any one of the MPL, the GPL or the LGPL.
+*
+* ***** END LICENSE BLOCK ***** */
+
+void FirefoxProfileLock::Init() {
+ lock_fd_ = -1;
+}
+
+void FirefoxProfileLock::Lock() {
+ if (HasAcquired())
+ return;
+ lock_fd_ = open(lock_file_.value().c_str(), O_CREAT | O_EXCL);
+}
+
+void FirefoxProfileLock::Unlock() {
+ if (!HasAcquired())
+ return;
+ close(lock_fd_);
+ lock_fd_ = -1;
+}
+
+bool FirefoxProfileLock::HasAcquired() {
+ return (lock_fd_ >= 0);
+}
+
+
diff --git a/chrome/browser/importer/firefox_profile_lock_win.cc b/chrome/browser/importer/firefox_profile_lock_win.cc
new file mode 100644
index 0000000..a9063c6
--- /dev/null
+++ b/chrome/browser/importer/firefox_profile_lock_win.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2008 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 "chrome/browser/importer/firefox_profile_lock.h"
+
+#include <windows.h>
+
+// This class is based on Firefox code in:
+// profile/dirserviceprovider/src/nsProfileLock.cpp
+// The license block is:
+
+/* ***** BEGIN LICENSE BLOCK *****
+* Version: MPL 1.1/GPL 2.0/LGPL 2.1
+*
+* The contents of this file are subject to the Mozilla Public License Version
+* 1.1 (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+* for the specific language governing rights and limitations under the
+* License.
+*
+* The Original Code is mozilla.org code.
+*
+* The Initial Developer of the Original Code is
+* Netscape Communications Corporation.
+* Portions created by the Initial Developer are Copyright (C) 2002
+* the Initial Developer. All Rights Reserved.
+*
+* Contributor(s):
+* Conrad Carlen <ccarlen@netscape.com>
+* Brendan Eich <brendan@mozilla.org>
+* Colin Blake <colin@theblakes.com>
+* Javier Pedemonte <pedemont@us.ibm.com>
+* Mats Palmgren <mats.palmgren@bredband.net>
+*
+* Alternatively, the contents of this file may be used under the terms of
+* either the GNU General Public License Version 2 or later (the "GPL"), or
+* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+* in which case the provisions of the GPL or the LGPL are applicable instead
+* of those above. If you wish to allow use of your version of this file only
+* under the terms of either the GPL or the LGPL, and not to allow others to
+* use your version of this file under the terms of the MPL, indicate your
+* decision by deleting the provisions above and replace them with the notice
+* and other provisions required by the GPL or the LGPL. If you do not delete
+* the provisions above, a recipient may use your version of this file under
+* the terms of any one of the MPL, the GPL or the LGPL.
+*
+* ***** END LICENSE BLOCK ***** */
+
+void FirefoxProfileLock::Init() {
+ lock_handle_ = INVALID_HANDLE_VALUE;
+}
+
+void FirefoxProfileLock::Lock() {
+ if (HasAcquired())
+ return;
+ lock_handle_ = CreateFile(lock_file_.value().c_str(),
+ GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS,
+ FILE_FLAG_DELETE_ON_CLOSE, NULL);
+}
+
+void FirefoxProfileLock::Unlock() {
+ if (!HasAcquired())
+ return;
+ CloseHandle(lock_handle_);
+ lock_handle_ = INVALID_HANDLE_VALUE;
+}
+
+bool FirefoxProfileLock::HasAcquired() {
+ return (lock_handle_ != INVALID_HANDLE_VALUE);
+}
+
+
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc
index 2e5d919..5c247eb 100644
--- a/chrome/browser/importer/ie_importer.cc
+++ b/chrome/browser/importer/ie_importer.cc
@@ -4,10 +4,12 @@
#include "chrome/browser/importer/ie_importer.h"
+#include <atlbase.h>
#include <intshcut.h>
#include <pstore.h>
#include <shlobj.h>
#include <urlhist.h>
+
#include <algorithm>
#include "base/file_util.h"
diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc
index 3ce8996..0ca7b82 100644
--- a/chrome/browser/importer/importer.cc
+++ b/chrome/browser/importer/importer.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/importer/toolbar_importer.h"
#include "chrome/browser/template_url_model.h"
#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/views/importer_lock_view.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/common/gfx/favicon_size.h"
#include "chrome/common/l10n_util.h"
diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h
index 4e57b64..f7190e9 100644
--- a/chrome/browser/importer/importer.h
+++ b/chrome/browser/importer/importer.h
@@ -8,15 +8,18 @@
#include <set>
#include <vector>
+#include "build/build_config.h"
+
#include "base/basictypes.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/history/history_types.h"
+#if defined(OS_WIN)
#include "chrome/browser/ie7_password.h"
+#endif
#include "chrome/browser/profile.h"
#include "chrome/browser/template_url.h"
-#include "chrome/browser/views/importer_lock_view.h"
#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/password_form.h"
@@ -97,7 +100,9 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> {
// Helper methods for adding data to local stores.
virtual void AddPasswordForm(const PasswordForm& form);
+#if defined(OS_WIN)
virtual void AddIE7PasswordInfo(const IE7PasswordInfo& info);
+#endif
virtual void AddHistoryPage(const std::vector<history::URLRow>& page);
virtual void AddHomepage(const GURL& homepage);
// Adds the bookmarks to the BookmarkModel.
@@ -407,6 +412,9 @@ class ImportObserver {
};
+#if defined(OS_WIN)
+// TODO(port): Make StartImportingWithUI portable.
+
// Shows a UI for importing and begins importing the specified items from
// source_profile to target_profile. observer is notified when the process is
// complete, can be NULL. parent is the window to parent the UI to, can be NULL
@@ -419,5 +427,6 @@ void StartImportingWithUI(HWND parent_window,
Profile* target_profile,
ImportObserver* observer,
bool first_run);
+#endif
#endif // CHROME_BROWSER_IMPORTER_IMPORTER_H_
diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc
index 2f9d8e1..abd93c5 100644
--- a/chrome/browser/importer/importer_unittest.cc
+++ b/chrome/browser/importer/importer_unittest.cc
@@ -4,6 +4,7 @@
#include "testing/gtest/include/gtest/gtest.h"
+#include <atlbase.h>
#include <windows.h>
#include <unknwn.h>
#include <intshcut.h>
diff --git a/chrome/browser/importer/mork_reader.cc b/chrome/browser/importer/mork_reader.cc
index 4a9c1b2..7f5e5c6 100644
--- a/chrome/browser/importer/mork_reader.cc
+++ b/chrome/browser/importer/mork_reader.cc
@@ -44,6 +44,7 @@
#include <algorithm>
+#include "base/file_path.h"
#include "base/logging.h"
#include "base/string_util.h"
#include "chrome/browser/history/history_types.h"
@@ -111,7 +112,8 @@ MorkReader::~MorkReader() {
}
bool MorkReader::Read(const std::wstring& filename) {
- stream_.open(filename.c_str());
+ FilePath path = FilePath::FromWStringHack(filename);
+ stream_.open(path.value().c_str());
if (!stream_.is_open())
return false;