Chromium Code Reviews| Index: components/enhanced_bookmarks/bookmark_server_search_service.h |
| diff --git a/components/enhanced_bookmarks/bookmark_server_search_service.h b/components/enhanced_bookmarks/bookmark_server_search_service.h |
| index 97713185418368ce34a427eb54a50588a96c7eee..89729e6f2e78e89e43707e12305e555bf4af77d3 100644 |
| --- a/components/enhanced_bookmarks/bookmark_server_search_service.h |
| +++ b/components/enhanced_bookmarks/bookmark_server_search_service.h |
| @@ -8,6 +8,7 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/containers/mru_cache.h" |
| #include "components/enhanced_bookmarks/bookmark_server_service.h" |
| #include "net/url_request/url_fetcher.h" |
| @@ -27,14 +28,18 @@ class BookmarkServerSearchService : public BookmarkServerService { |
| ~BookmarkServerSearchService() override; |
| // Triggers a search. The query must not be empty. A call to this method |
| - // cancels any previous searches. OnChange() is garanteed to be called once |
| - // per query. |
| + // cancels any previous searches.If there have been multiple queries in |
| + // between, onChange will only be called for the last query. |
| void Search(const std::string& query); |
| - // Returns the search results. The results are only available after the |
| - // OnChange() observer methods has been sent. This method will return an empty |
| - // result otherwise. query should be a string passed to Search() previously. |
| - std::vector<const BookmarkNode*> ResultForQuery(const std::string& query); |
| + // Returns search results for a query. The results are only available after |
| + // OnChange() observer methods has been sent. If this method returns empty |
| + // vector, it means there are no bookmarks matching the given query. If |
| + // returns null pointer, it means we are still loading and no results have |
|
Kibeom Kim (inactive)
2014/10/30 03:13:11
We aren't necessarily loading if |Search| has not
Ian Wen
2014/10/30 04:31:00
Yes.
|
| + // come to the client. Previously cancelled queries will not trigger |
| + // onChange(), and this method will return null for those queries. |
| + scoped_ptr<std::vector<const BookmarkNode*>> ResultForQuery( |
| + const std::string& query); |
| protected: |
| scoped_ptr<net::URLFetcher> CreateFetcher() override; |
| @@ -54,8 +59,11 @@ class BookmarkServerSearchService : public BookmarkServerService { |
| const std::string& remote_id) override; |
| private: |
| - // The search data, a map from query to a vector of stars.id. |
| - std::map<std::string, std::vector<std::string> > searches_; |
| + // Cache for previous search result, a map from a query string to vector of |
| + // star_ids. |
| + base::MRUCache<std::string, std::vector<std::string> > cache_; |
|
Kibeom Kim (inactive)
2014/10/30 03:13:11
nit: >>
Ian Wen
2014/10/30 04:31:00
Done.
|
| + // The query currently on the fly, and is cleared as soon as the result is |
| + // available. |
| std::string current_query_; |
| DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService); |
| }; |