diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-14 17:48:40 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-14 17:48:40 +0000 |
commit | 405ed122f92ca9248de2a65103edba9b02471a9f (patch) | |
tree | 9d8cb957ff47ba6790107feec65acdfa592d9747 /chrome | |
parent | 296d61e24b5a5311f120a767a59ac006176f6f9a (diff) | |
download | chromium_src-405ed122f92ca9248de2a65103edba9b02471a9f.zip chromium_src-405ed122f92ca9248de2a65103edba9b02471a9f.tar.gz chromium_src-405ed122f92ca9248de2a65103edba9b02471a9f.tar.bz2 |
Port some files in chrome/browser/
#ifdef out windows-specific portion of chrome/common/l10n_util.h,
which allows me to port some other files.
I also extracted parts of chrome/views/tree_view.h to tree_model.h,
so that ATL/WTL-specific parts stay in tree_view.h, but tree_model.h
is platform-independent and can be included in files using it as base class.
Review URL: http://codereview.chromium.org/8618
Patch from Paweł Hajdan jr.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.h | 6 | ||||
-rw-r--r-- | chrome/browser/autocomplete/history_url_provider.h | 3 | ||||
-rw-r--r-- | chrome/browser/browser.scons | 10 | ||||
-rw-r--r-- | chrome/browser/history/expire_history_backend.cc | 19 | ||||
-rw-r--r-- | chrome/browser/history/expire_history_backend.h | 2 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 33 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.h | 3 | ||||
-rw-r--r-- | chrome/browser/template_url_parser.cc | 28 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_editor_view.h | 1 | ||||
-rw-r--r-- | chrome/common/l10n_util.h | 6 | ||||
-rw-r--r-- | chrome/views/tree_model.h | 86 | ||||
-rw-r--r-- | chrome/views/tree_node_model.h | 19 | ||||
-rw-r--r-- | chrome/views/tree_view.h | 69 | ||||
-rw-r--r-- | chrome/views/views.vcproj | 4 |
14 files changed, 149 insertions, 140 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h index 71da6ef..d60167a 100644 --- a/chrome/browser/autocomplete/autocomplete.h +++ b/chrome/browser/autocomplete/autocomplete.h @@ -439,9 +439,9 @@ class AutocompleteProvider AutocompleteProvider(ACProviderListener* listener, Profile* profile, - char* name) - : listener_(listener), - profile_(profile), + const char* name) + : profile_(profile), + listener_(listener), done_(true), name_(name) { } diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h index 6261a47..e8d1838 100644 --- a/chrome/browser/autocomplete/history_url_provider.h +++ b/chrome/browser/autocomplete/history_url_provider.h @@ -39,7 +39,8 @@ class HistoryBackend; // -> DoAutocomplete (for inline autocomplete) // -> URLDatabase::AutocompleteForPrefix (on in-memory DB) // -> HistoryService::ScheduleAutocomplete -// (return to controller) \ +// (return to controller) ---- +// / // HistoryBackend::ScheduleAutocomplete // -> HistoryURLProvider::ExecuteWithDB // -> DoAutocomplete diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 8336af8..60f19ae 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -64,6 +64,9 @@ if env['PLATFORM'] in ('posix', 'win32'): 'google_url_tracker.cc', 'google_util.cc', 'history/archived_database.cc', + 'history/expire_history_backend.cc', + 'history/history_backend.cc', + 'history/history_database.cc', 'history/history_types.cc', 'history/in_memory_database.cc', 'history/in_memory_history_backend.cc', @@ -72,6 +75,7 @@ if env['PLATFORM'] in ('posix', 'win32'): 'history/text_database.cc', 'history/text_database_manager.cc', 'history/thumbnail_database.cc', + 'history/query_parser.cc', 'history/visit_database.cc', 'history/visit_tracker.cc', 'history/visitsegment_database.cc', @@ -93,6 +97,7 @@ if env['PLATFORM'] in ('posix', 'win32'): 'safe_browsing/safe_browsing_service.cc', 'safe_browsing/safe_browsing_util.cc', 'session_startup_pref.cc', + 'template_url_parser.cc', 'url_fetcher_protect.cc', 'user_metrics.cc', ]) @@ -175,12 +180,8 @@ if env['PLATFORM'] == 'win32': 'hang_monitor/hung_plugin_action.cc', 'hang_monitor/hung_window_detector.cc', 'history/download_database.cc', - 'history/expire_history_backend.cc', 'history/history.cc', - 'history/history_backend.cc', - 'history/history_database.cc', 'history/history_publisher.cc', - 'history/query_parser.cc', 'history/starred_url_database.cc', 'history/url_database.cc', 'history_model.cc', @@ -275,7 +276,6 @@ if env['PLATFORM'] == 'win32': 'template_url.cc', 'template_url_fetcher.cc', 'template_url_model.cc', - 'template_url_parser.cc', 'template_url_prepopulate_data.cc', 'toolbar_model.cc', 'url_fetcher.cc', diff --git a/chrome/browser/history/expire_history_backend.cc b/chrome/browser/history/expire_history_backend.cc index 0944b87..955b837 100644 --- a/chrome/browser/history/expire_history_backend.cc +++ b/chrome/browser/history/expire_history_backend.cc @@ -7,6 +7,7 @@ #include <algorithm> #include <limits> +#include "base/compiler_specific.h" #include "base/file_util.h" #include "chrome/browser/bookmarks/bookmark_service.h" #include "chrome/browser/history/archived_database.h" @@ -74,8 +75,7 @@ ExpireHistoryBackend::ExpireHistoryBackend( archived_db_(NULL), thumb_db_(NULL), text_db_(NULL), -#pragma warning(suppress: 4355) // Okay to pass "this" here. - factory_(this), + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), bookmark_service_(bookmark_service) { } @@ -297,16 +297,21 @@ URLID ExpireHistoryBackend::ArchiveOneURL(const URLRow& url_row) { return archived_db_->AddURL(url_row); } +namespace { + +struct ChangedURL { + ChangedURL() : visit_count(0), typed_count(0) {} + int visit_count; + int typed_count; +}; + +} // namespace + void ExpireHistoryBackend::ExpireURLsForVisits( const VisitVector& visits, DeleteDependencies* dependencies) { // First find all unique URLs and the number of visits we're deleting for // each one. - struct ChangedURL { - ChangedURL() : visit_count(0), typed_count(0) {} - int visit_count; - int typed_count; - }; std::map<URLID, ChangedURL> changed_urls; for (size_t i = 0; i < visits.size(); i++) { ChangedURL& cur = changed_urls[visits[i].url_id]; diff --git a/chrome/browser/history/expire_history_backend.h b/chrome/browser/history/expire_history_backend.h index 55c72c3..5d26ddc 100644 --- a/chrome/browser/history/expire_history_backend.h +++ b/chrome/browser/history/expire_history_backend.h @@ -13,11 +13,11 @@ #include "base/time.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/text_database_manager.h" +#include "chrome/common/notification_types.h" #include "testing/gtest/include/gtest/gtest_prod.h" class BookmarkService; class GURL; -enum NotificationType; namespace history { diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index d904148..fd7d465 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -6,6 +6,7 @@ #include <set> +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/histogram.h" #include "base/message_loop.h" @@ -78,32 +79,6 @@ static const int kMaxRedirectCount = 32; // and is archived. static const int kArchiveDaysThreshold = 90; -// Comparison used when inserting entries into visits vector. -static bool VisitOccursAfter(const PageVisit& elem1, - const PageVisit& elem2) { - return elem1.visit_time > elem2.visit_time; -} - -static bool IsMatchingHost(const URLRow& row, - const std::string& host_name) { - const GURL& url = row.url(); - if (!url.is_valid() || !url.IsStandard()) - return false; - - const std::string& spec = url.spec(); - url_parse::Parsed parsed = url.parsed_for_possibly_invalid_spec(); - if (!parsed.host.is_nonempty()) - return false; // Empty host. - - if (parsed.host.len != host_name.size()) - return false; // Hosts are different lengths, can not match. - - // TODO(brettw) we may want to also match hosts ending with a period, since - // these will typically be the same. - return strncmp(&spec[parsed.host.begin], host_name.c_str(), - host_name.size()) == 0; -} - // This task is run on a timer so that commits happen at regular intervals // so they are batched together. The important thing about this class is that // it supports canceling of the task so the reference to the backend will be @@ -195,10 +170,9 @@ HistoryBackend::HistoryBackend(const std::wstring& history_dir, BookmarkService* bookmark_service) : delegate_(delegate), history_dir_(history_dir), -#pragma warning(suppress: 4355) // OK to pass "this" here. - expirer_(this, bookmark_service), - backend_destroy_message_loop_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(expirer_(this, bookmark_service)), recent_redirects_(kMaxRedirectCount), + backend_destroy_message_loop_(NULL), backend_destroy_task_(NULL), segment_queried_(false), bookmark_service_(bookmark_service) { @@ -620,7 +594,6 @@ std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( // Update of an existing row. if (PageTransition::StripQualifier(transition) != PageTransition::RELOAD) url_info.set_visit_count(url_info.visit_count() + 1); - int old_typed_count = url_info.typed_count(); if (typed_increment) url_info.set_typed_count(url_info.typed_count() + typed_increment); url_info.set_last_visit(time); diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index a7c9310..8918742 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -262,9 +262,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, FRIEND_TEST(HistoryBackendTest, URLsNoLongerBookmarked); friend class TestingProfile; - // For invoking methods that circumvent requests. - friend class HistoryTest; - // Computes the name of the specified database on disk. std::wstring GetThumbnailFileName() const; std::wstring GetArchivedFileName() const; diff --git a/chrome/browser/template_url_parser.cc b/chrome/browser/template_url_parser.cc index 8c4f8be..93f9f79 100644 --- a/chrome/browser/template_url_parser.cc +++ b/chrome/browser/template_url_parser.cc @@ -93,12 +93,12 @@ class ParsingContext { ParsingContext(TemplateURLParser::ParameterFilter* parameter_filter, TemplateURL* url) - : parameter_filter_(parameter_filter), - url_(url), - is_suggest_url_(false), - derive_image_from_url_(false), + : url_(url), + parameter_filter_(parameter_filter), method_(GET), - suggestion_method_(GET) { + suggestion_method_(GET), + is_suggest_url_(false), + derive_image_from_url_(false) { if (kElementNameToElementTypeMap == NULL) InitMapping(); } @@ -145,7 +145,7 @@ class ParsingContext { void SetImageURL(const std::wstring& url) { if (current_image_.get()) { - current_image_->url = GURL(url); + current_image_->url = GURL(WideToUTF8(url)); url_->add_image_ref(*current_image_); current_image_.reset(); } @@ -197,7 +197,7 @@ class ParsingContext { void DeriveImageFromURL() { if (derive_image_from_url_ && url_->GetFavIconURL().is_empty() && url_->url()) { - GURL url(url_->url()->url()); // More url's please... + GURL url(WideToUTF8(url_->url()->url())); // More url's please... url_->SetFavIconURL(TemplateURL::GenerateFaviconURL(url)); } } @@ -310,9 +310,9 @@ void ParseURL(const xmlChar** atts, ParsingContext* context) { } else if (name == kURLTemplateAttribute) { template_url = XMLCharToWide(value); } else if (name == kURLIndexOffsetAttribute) { - index_offset = std::max(1, _wtoi(XMLCharToWide(value).c_str())); + index_offset = std::max(1, StringToInt(XMLCharToWide(value))); } else if (name == kURLPageOffsetAttribute) { - page_offset = std::max(1, _wtoi(XMLCharToWide(value).c_str())); + page_offset = std::max(1, StringToInt(XMLCharToWide(value))); } else if (name == kParamMethodAttribute) { is_post = LowerCaseEqualsASCII(XMLCharToString(value), "post"); } @@ -345,9 +345,9 @@ void ParseImage(const xmlChar** atts, ParsingContext* context) { if (name == kImageTypeAttribute) { type = XMLCharToWide(value); } else if (name == kImageWidthAttribute) { - width = _wtoi(XMLCharToWide(value).c_str()); + width = StringToInt(XMLCharToWide(value)); } else if (name == kImageHeightAttribute) { - height = _wtoi(XMLCharToWide(value).c_str()); + height = StringToInt(XMLCharToWide(value)); } attributes += 2; } @@ -401,7 +401,7 @@ void ProcessURLParams(ParsingContext* context) { if (!context->parameter_filter() && context->extra_params().empty()) return; - GURL url(t_url_ref->url()); + GURL url(WideToUTF8(t_url_ref->url())); // If there is a parameter filter, parse the existing URL and remove any // unwanted parameter. TemplateURLParser::ParameterFilter* filter = context->parameter_filter(); @@ -481,7 +481,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { context->template_url()->set_description(context->GetString()); break; case ParsingContext::IMAGE: { - GURL image_url(context->GetString()); + GURL image_url(WideToUTF8(context->GetString())); if (image_url.SchemeIs("data")) { // TODO (jcampan): bug 1169256: when dealing with data URL, we need to // decode the data URL in the renderer. For now, we'll just point to the @@ -522,7 +522,7 @@ void CharactersImpl(void *ctx, const xmlChar *ch, int len) { bool IsHTTPRef(const TemplateURLRef* ref) { if (ref == NULL) return true; - GURL url(ref->url()); + GURL url(WideToUTF8(ref->url())); return (url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https"))); } diff --git a/chrome/browser/views/bookmark_editor_view.h b/chrome/browser/views/bookmark_editor_view.h index 2cd4b01..629e6ab 100644 --- a/chrome/browser/views/bookmark_editor_view.h +++ b/chrome/browser/views/bookmark_editor_view.h @@ -14,6 +14,7 @@ #include "chrome/views/native_button.h" #include "chrome/views/text_field.h" #include "chrome/views/tree_node_model.h" +#include "chrome/views/tree_view.h" namespace views { class Window; diff --git a/chrome/common/l10n_util.h b/chrome/common/l10n_util.h index 68d1f32..7631a1f 100644 --- a/chrome/common/l10n_util.h +++ b/chrome/common/l10n_util.h @@ -8,7 +8,11 @@ #ifndef CHROME_COMMON_L10N_UTIL_H_ #define CHROME_COMMON_L10N_UTIL_H_ +#include "build/build_config.h" + +#if defined(OS_WIN) #include <windows.h> +#endif #include <string> #include <vector> @@ -154,11 +158,13 @@ int GetExtendedTooltipStyles(); // ChromeCanvas::TEXT_ALIGN_RIGHT. int DefaultCanvasTextAlignment(); +#if defined(OS_WIN) // Give an HWND, this function sets the WS_EX_LAYOUTRTL extended style for the // underlying window. When this style is set, the UI for the window is going to // be mirrored. This is generally done for the UI of right-to-left languages // such as Hebrew. void HWNDSetRTLLayout(HWND hwnd); +#endif // In place sorting of strings using collation rules for |locale|. void SortStrings(const std::wstring& locale, diff --git a/chrome/views/tree_model.h b/chrome/views/tree_model.h new file mode 100644 index 0000000..68a3ff7 --- /dev/null +++ b/chrome/views/tree_model.h @@ -0,0 +1,86 @@ +// 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. + +#ifndef CHROME_VIEWS_TREE_MODEL_H_ +#define CHROME_VIEWS_TREE_MODEL_H_ + +#include <string> + +#include "base/logging.h" + +class SkBitmap; + +namespace views { + +class TreeModel; + +// TreeModelNode -------------------------------------------------------------- + +// Type of class returned from the model. +class TreeModelNode { + public: + // Returns the title for the node. + virtual std::wstring GetTitle() = 0; +}; + +// Observer for the TreeModel. Notified of significant events to the model. +class TreeModelObserver { + public: + // Notification that nodes were added to the specified parent. + virtual void TreeNodesAdded(TreeModel* model, + TreeModelNode* parent, + int start, + int count) = 0; + + // Notification that nodes were removed from the specified parent. + virtual void TreeNodesRemoved(TreeModel* model, + TreeModelNode* parent, + int start, + int count) = 0; + + // Notification that the contents of a node has changed. + virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) = 0; +}; + +// TreeModel ------------------------------------------------------------------ + +// The model for TreeView. +class TreeModel { + public: + // Returns the root of the tree. This may or may not be shown in the tree, + // see SetRootShown for details. + virtual TreeModelNode* GetRoot() = 0; + + // Returns the number of children in the specified node. + virtual int GetChildCount(TreeModelNode* parent) = 0; + + // Returns the child node at the specified index. + virtual TreeModelNode* GetChild(TreeModelNode* parent, int index) = 0; + + // Returns the parent of a node, or NULL if node is the root. + virtual TreeModelNode* GetParent(TreeModelNode* node) = 0; + + // Sets the observer of the model. + virtual void SetObserver(TreeModelObserver* observer) = 0; + + // Sets the title of the specified node. + // This is only invoked if the node is editable and the user edits a node. + virtual void SetTitle(TreeModelNode* node, + const std::wstring& title) { + NOTREACHED(); + } + + // Returns the set of icons for the nodes in the tree. You only need override + // this if you don't want to use the default folder icons. + virtual void GetIcons(std::vector<SkBitmap>* icons) {} + + // Returns the index of the icon to use for |node|. Return -1 to use the + // default icon. The index is relative to the list of icons returned from + // GetIcons. + virtual int GetIconIndex(TreeModelNode* node) { return -1; } +}; + +} // namespace views + +#endif // CHROME_VIEWS_TREE_MODEL_H_ diff --git a/chrome/views/tree_node_model.h b/chrome/views/tree_node_model.h index 2d9040e..0d33fff 100644 --- a/chrome/views/tree_node_model.h +++ b/chrome/views/tree_node_model.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "chrome/common/scoped_vector.h" -#include "chrome/views/tree_view.h" +#include "chrome/views/tree_model.h" namespace views { @@ -115,7 +115,7 @@ class TreeNode : public TreeModelNode { // Returns the index of the specified child, or -1 if node is a not a child. int IndexOfChild(const NodeType* node) { DCHECK(node); - std::vector<NodeType*>::iterator i = + typename std::vector<NodeType*>::iterator i = find(children_->begin(), children_->end(), node); if (i != children_->end()) return static_cast<int>(i - children_->begin()); @@ -154,26 +154,29 @@ class TreeNode : public TreeModelNode { // Children. ScopedVector<NodeType> children_; - DISALLOW_EVIL_CONSTRUCTORS(TreeNode); + DISALLOW_COPY_AND_ASSIGN(TreeNode); }; // TreeNodeWithValue ---------------------------------------------------------- template <class ValueType> -class TreeNodeWithValue : public TreeNode<TreeNodeWithValue<ValueType>> { +class TreeNodeWithValue : public TreeNode< TreeNodeWithValue<ValueType> > { + private: + typedef TreeNode< TreeNodeWithValue<ValueType> > ParentType; + public: TreeNodeWithValue() { } TreeNodeWithValue(const ValueType& value) - : TreeNode(std::wstring()), value(value) { } + : ParentType(std::wstring()), value(value) { } TreeNodeWithValue(const std::wstring& title, const ValueType& value) - : TreeNode(title), value(value) { } + : ParentType(title), value(value) { } ValueType value; private: - DISALLOW_EVIL_CONSTRUCTORS(TreeNodeWithValue); + DISALLOW_COPY_AND_ASSIGN(TreeNodeWithValue); }; // TreeNodeModel -------------------------------------------------------------- @@ -264,7 +267,7 @@ class TreeNodeModel : public TreeModel { // The observer. TreeModelObserver* observer_; - DISALLOW_EVIL_CONSTRUCTORS(TreeNodeModel); + DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); }; } // namespace views diff --git a/chrome/views/tree_view.h b/chrome/views/tree_view.h index c2fe4d3..582de9f 100644 --- a/chrome/views/tree_view.h +++ b/chrome/views/tree_view.h @@ -10,79 +10,12 @@ #include "base/basictypes.h" #include "base/logging.h" #include "chrome/views/native_control.h" +#include "chrome/views/tree_model.h" namespace views { -class TreeModel; -class TreeModelNode; class TreeView; -// Observer for the TreeModel. Notified of significant events to the model. -class TreeModelObserver { - public: - // Notification that nodes were added to the specified parent. - virtual void TreeNodesAdded(TreeModel* model, - TreeModelNode* parent, - int start, - int count) = 0; - - // Notification that nodes were removed from the specified parent. - virtual void TreeNodesRemoved(TreeModel* model, - TreeModelNode* parent, - int start, - int count) = 0; - - // Notification that the contents of a node has changed. - virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) = 0; -}; - -// TreeModelNode -------------------------------------------------------------- - -// Type of class returned from the model. -class TreeModelNode { - public: - // Returns the title for the node. - virtual std::wstring GetTitle() = 0; -}; - -// TreeModel ------------------------------------------------------------------ - -// The model for TreeView. -class TreeModel { - public: - // Returns the root of the tree. This may or may not be shown in the tree, - // see SetRootShown for details. - virtual TreeModelNode* GetRoot() = 0; - - // Returns the number of children in the specified node. - virtual int GetChildCount(TreeModelNode* parent) = 0; - - // Returns the child node at the specified index. - virtual TreeModelNode* GetChild(TreeModelNode* parent, int index) = 0; - - // Returns the parent of a node, or NULL if node is the root. - virtual TreeModelNode* GetParent(TreeModelNode* node) = 0; - - // Sets the observer of the model. - virtual void SetObserver(TreeModelObserver* observer) = 0; - - // Sets the title of the specified node. - // This is only invoked if the node is editable and the user edits a node. - virtual void SetTitle(TreeModelNode* node, - const std::wstring& title) { - NOTREACHED(); - } - - // Returns the set of icons for the nodes in the tree. You only need override - // this if you don't want to use the default folder icons. - virtual void GetIcons(std::vector<SkBitmap>* icons) {} - - // Returns the index of the icon to use for |node|. Return -1 to use the - // default icon. The index is relative to the list of icons returned from - // GetIcons. - virtual int GetIconIndex(TreeModelNode* node) { return -1; } -}; - // TreeViewController --------------------------------------------------------- // Controller for the treeview. diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj index 91dce86..505186f 100644 --- a/chrome/views/views.vcproj +++ b/chrome/views/views.vcproj @@ -589,6 +589,10 @@ RelativePath=".\tooltip_manager.h" > </File> + <File + RelativePath=".\tree_model.h" + > + </File> <File RelativePath=".\tree_node_model.h" > |