diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 23:14:46 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-25 23:14:46 +0000 |
commit | 42eb6b07c2791d8d13ec48ea3c92725eee4d94a2 (patch) | |
tree | 9c72c5052409725827617584d7891f1fcd5b5c9e | |
parent | 60aac62ddf3cc40741a824cae25ab190005513be (diff) | |
download | chromium_src-42eb6b07c2791d8d13ec48ea3c92725eee4d94a2.zip chromium_src-42eb6b07c2791d8d13ec48ea3c92725eee4d94a2.tar.gz chromium_src-42eb6b07c2791d8d13ec48ea3c92725eee4d94a2.tar.bz2 |
Port some files in chrome/browser/ - part 1.
Review URL: http://codereview.chromium.org/11402
Patch from Pawel Hajdan Jr.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6007 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec.cc | 3 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_html_writer.cc | 21 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 10 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_storage.cc | 11 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_storage.h | 1 | ||||
-rw-r--r-- | chrome/browser/cancelable_request.h | 28 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 10 | ||||
-rw-r--r-- | chrome/browser/history/download_database.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/starred_url_database.cc | 7 |
9 files changed, 60 insertions, 35 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index 70aa410..6d6274a 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -134,7 +134,6 @@ bool BookmarkCodec::DecodeNode(BookmarkModel* model, const DictionaryValue& value, BookmarkNode* parent, BookmarkNode* node) { - bool created_node = (node == NULL); std::wstring title; if (!value.GetString(kNameKey, &title)) return false; @@ -158,7 +157,7 @@ bool BookmarkCodec::DecodeNode(BookmarkModel* model, return false; // TODO(sky): this should ignore the node if not a valid URL. if (!node) - node = new BookmarkNode(model, GURL(url_string)); + node = new BookmarkNode(model, GURL(WideToUTF8(url_string))); if (parent) parent->Add(parent->GetChildCount(), node); node->type_ = history::StarredEntry::URL; diff --git a/chrome/browser/bookmarks/bookmark_html_writer.cc b/chrome/browser/bookmarks/bookmark_html_writer.cc index b6c26ef..cb5cf87 100644 --- a/chrome/browser/bookmarks/bookmark_html_writer.cc +++ b/chrome/browser/bookmarks/bookmark_html_writer.cc @@ -4,8 +4,9 @@ #include "chrome/browser/bookmarks/bookmark_html_writer.h" +#include "base/file_util.h" #include "base/message_loop.h" -#include "base/scoped_handle.h" +#include "base/platform_file.h" #include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/time.h" @@ -14,6 +15,8 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history_types.h" #include "net/base/escape.h" +#include "net/base/file_stream.h" +#include "net/base/net_errors.h" namespace bookmark_html_writer { @@ -129,12 +132,8 @@ class Writer : public Task { // Opens the file, returning true on success. bool OpenFile() { - handle_.Set( - CreateFile(path_.c_str(), GENERIC_WRITE, 0, NULL, - CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)); - if (!handle_.IsValid()) - return false; - return true; + int flags = base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE; + return (file_stream_.Open(path_, flags) == net::OK); } // Increments the indent. @@ -151,10 +150,8 @@ class Writer : public Task { // Writes raw text out returning true on success. This does not escape // the text in anyway. bool Write(const std::string& text) { - DWORD wrote; - bool result = - (WriteFile(handle_, text.c_str(), text.length(), &wrote, NULL) && - wrote == text.length()); + size_t wrote = file_stream_.Write(text.c_str(), text.length(), NULL); + bool result = (wrote == text.length()); DCHECK(result); return result; } @@ -306,7 +303,7 @@ class Writer : public Task { std::wstring path_; // File we're writing to. - ScopedHandle handle_; + net::FileStream file_stream_; // How much we indent when writing a bookmark/folder. This is modified // via IncrementIndent and DecrementIndent. diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 1262a9e..182d3cc 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -5,9 +5,13 @@ #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_BAR_MODEL_H_ +#include "build/build_config.h" + #include "base/lock.h" #include "base/observer_list.h" +#if defined(OS_WIN) #include "base/scoped_handle.h" +#endif // defined(OS_WIN) #include "chrome/browser/bookmarks/bookmark_service.h" #include "chrome/browser/bookmarks/bookmark_storage.h" #include "chrome/browser/cancelable_request.h" @@ -436,7 +440,7 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { Lock url_lock_; // Used for loading favicons and the empty history request. - CancelableRequestConsumerT<BookmarkNode*, NULL> load_consumer_; + CancelableRequestConsumerTSimple<BookmarkNode*> load_consumer_; // Reads/writes bookmarks to disk. scoped_refptr<BookmarkStorage> store_; @@ -446,8 +450,12 @@ class BookmarkModel : public NotificationObserver, public BookmarkService { // doesn't exist and the history service hasn't finished loading. bool waiting_for_history_load_; +#if defined(OS_WIN) + // TODO(port): Implement for other platforms. + // Handle to event signaled when loading is done. ScopedHandle loaded_signal_; +#endif DISALLOW_COPY_AND_ASSIGN(BookmarkModel); }; diff --git a/chrome/browser/bookmarks/bookmark_storage.cc b/chrome/browser/bookmarks/bookmark_storage.cc index eb9bbe4..591f190 100644 --- a/chrome/browser/bookmarks/bookmark_storage.cc +++ b/chrome/browser/bookmarks/bookmark_storage.cc @@ -4,6 +4,7 @@ #include "chrome/browser/bookmarks/bookmark_storage.h" +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/json_writer.h" #include "base/message_loop.h" @@ -31,8 +32,7 @@ const int kSaveDelayMS = 2500; BookmarkStorage::BookmarkStorage(Profile* profile, BookmarkModel* model) : model_(model), -#pragma warning(suppress: 4355) // Okay to pass "this" here. - save_factory_(this), + ALLOW_THIS_IN_INITIALIZER_LIST(save_factory_(this)), backend_thread_(g_browser_process->file_thread()) { std::wstring path = profile->GetPath(); file_util::AppendToPath(&path, chrome::kBookmarksFileName); @@ -139,13 +139,10 @@ void BookmarkStorageBackend::Write(Value* value) { int bytes_written = file_util::WriteFile(tmp_file, content.c_str(), static_cast<int>(content.length())); if (bytes_written != -1) { - if (!MoveFileEx(tmp_file.c_str(), path_.c_str(), - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING)) { + if (!file_util::Move(tmp_file, path_)) { // Rename failed. Try again on the off chance someone has locked either // file and hope we're successful the second time through. - BOOL move_result = - MoveFileEx(tmp_file.c_str(), path_.c_str(), - MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING); + bool move_result = file_util::Move(tmp_file, path_); DCHECK(move_result); if (!move_result) LOG(WARNING) << " writing bookmarks failed, result=" << move_result; diff --git a/chrome/browser/bookmarks/bookmark_storage.h b/chrome/browser/bookmarks/bookmark_storage.h index c645a7f..c6416d4 100644 --- a/chrome/browser/bookmarks/bookmark_storage.h +++ b/chrome/browser/bookmarks/bookmark_storage.h @@ -10,6 +10,7 @@ #include "chrome/browser/browser_process.h" class BookmarkModel; +class BookmarkStorageBackend; class Profile; class Value; diff --git a/chrome/browser/cancelable_request.h b/chrome/browser/cancelable_request.h index 8513bcb..30e1a39 100644 --- a/chrome/browser/cancelable_request.h +++ b/chrome/browser/cancelable_request.h @@ -186,20 +186,20 @@ class CancelableRequestConsumerBase { }; // Template for clients to use. It allows them to associate random "client -// data" with a specific requst. The default value for this type is given in -// |initial_t|. The type T should be small and easily copyable (like a pointer +// data" with a specific request. The default value for this type is NULL. +// The type T should be small and easily copyable (like a pointer // or an integer). -template<class T, T initial_t> -class CancelableRequestConsumerT : public CancelableRequestConsumerBase { +template<class T> +class CancelableRequestConsumerTSimple : public CancelableRequestConsumerBase { public: - CancelableRequestConsumerT() { + CancelableRequestConsumerTSimple() { } // Cancel any outstanding requests so that we do not get called back after we // are destroyed. As these requests are removed, the providers will call us // back on OnRequestRemoved, which will then update the list. To iterate // successfully while the list is changing out from under us, we make a copy. - virtual ~CancelableRequestConsumerT() { + virtual ~CancelableRequestConsumerTSimple() { CancelAllRequests(); } @@ -273,11 +273,15 @@ class CancelableRequestConsumerT : public CancelableRequestConsumerBase { }; typedef std::map<PendingRequest, T> PendingRequestList; + virtual T get_initial_t() const { + return NULL; + } + virtual void OnRequestAdded(CancelableRequestProvider* provider, CancelableRequestProvider::Handle handle) { DCHECK(pending_requests_.find(PendingRequest(provider, handle)) == pending_requests_.end()); - pending_requests_[PendingRequest(provider, handle)] = initial_t; + pending_requests_[PendingRequest(provider, handle)] = get_initial_t(); } virtual void OnRequestRemoved(CancelableRequestProvider* provider, @@ -296,6 +300,16 @@ class CancelableRequestConsumerT : public CancelableRequestConsumerBase { PendingRequestList pending_requests_; }; +// See CancelableRequestConsumerTSimple. The default value for T +// is given in |initial_t|. +template<class T, T initial_t> +class CancelableRequestConsumerT : public CancelableRequestConsumerTSimple<T> { + protected: + virtual T get_initial_t() const { + return initial_t; + } +}; + // Some clients may not want to store data. Rather than do some complicated // thing with virtual functions to allow some consumers to store extra data and // some not to, we just define a default one that stores some dummy data. diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 63e1e4c..d840957 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -35,6 +35,8 @@ #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ +#include "build/build_config.h" + #include <string> #include <map> #include <set> @@ -47,11 +49,13 @@ #include "chrome/browser/cancelable_request.h" #include "chrome/browser/history/download_types.h" #include "chrome/browser/history/history.h" +#if defined(OS_WIN) +// TODO(port): Port this header and remove #ifdef. #include "chrome/browser/shell_dialogs.h" +#endif #include "chrome/common/pref_member.h" class DownloadFileManager; -class DownloadItem; class DownloadItemView; class DownloadManager; class GURL; @@ -272,6 +276,9 @@ class DownloadItem { // DownloadManager ------------------------------------------------------------- +#if defined(OS_WIN) +// TODO(port): Port this part of the header and remove the #ifdef. + // Browser's download manager: manages all downloads and destination view. class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, public SelectFileDialog::Listener { @@ -563,5 +570,6 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, DISALLOW_EVIL_CONSTRUCTORS(DownloadManager); }; +#endif // defined(OS_WIN) #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H__ diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc index 0be6c10..f1dcbce 100644 --- a/chrome/browser/history/download_database.cc +++ b/chrome/browser/history/download_database.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/history/download_database.h" + #include <limits> #include <vector> -#include "chrome/browser/history/download_database.h" - #include "chrome/browser/download/download_manager.h" #include "chrome/browser/history/download_types.h" #include "chrome/common/sqlite_utils.h" diff --git a/chrome/browser/history/starred_url_database.cc b/chrome/browser/history/starred_url_database.cc index 9514b04..c4fabbc0 100644 --- a/chrome/browser/history/starred_url_database.cc +++ b/chrome/browser/history/starred_url_database.cc @@ -7,6 +7,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/json_writer.h" +#include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_codec.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/history/history.h" @@ -57,7 +58,7 @@ void FillInStarredEntry(SQLStatement* s, StarredEntry* entry) { switch (s->column_int(1)) { case 0: entry->type = history::StarredEntry::URL; - entry->url = GURL(s->column_string16(6)); + entry->url = GURL(WideToUTF8(s->column_string16(6))); break; case 1: entry->type = history::StarredEntry::BOOKMARK_BAR; @@ -487,7 +488,7 @@ bool StarredURLDatabase::EnsureStarredIntegrityImpl( LOG(WARNING) << "Bookmark not in a bookmark folder found"; if (!Move(*i, bookmark_node)) return false; - i = unparented_urls->erase(i); + unparented_urls->erase(i++); } } @@ -511,7 +512,7 @@ bool StarredURLDatabase::EnsureStarredIntegrityImpl( LOG(WARNING) << "Bookmark folder not on bookmark bar found"; if (!Move(*i, bookmark_node)) return false; - i = roots->erase(i); + roots->erase(i++); } else { ++i; } |