OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ | 5 #ifndef COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ |
6 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ | 6 #define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/containers/mru_cache.h" | |
11 #include "components/enhanced_bookmarks/bookmark_server_service.h" | 12 #include "components/enhanced_bookmarks/bookmark_server_service.h" |
12 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
13 | 14 |
14 namespace enhanced_bookmarks { | 15 namespace enhanced_bookmarks { |
15 | 16 |
16 class EnhancedBookmarkModel; | 17 class EnhancedBookmarkModel; |
17 | 18 |
18 // Sends requests to the bookmark server to search for bookmarks relevant to a | 19 // Sends requests to the bookmark server to search for bookmarks relevant to a |
19 // given query. Will handle one outgoing request at a time. | 20 // given query. Will handle one outgoing request at a time. |
20 class BookmarkServerSearchService : public BookmarkServerService { | 21 class BookmarkServerSearchService : public BookmarkServerService { |
21 public: | 22 public: |
22 BookmarkServerSearchService( | 23 BookmarkServerSearchService( |
23 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 24 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
24 ProfileOAuth2TokenService* token_service, | 25 ProfileOAuth2TokenService* token_service, |
25 SigninManagerBase* signin_manager, | 26 SigninManagerBase* signin_manager, |
26 EnhancedBookmarkModel* bookmark_model); | 27 EnhancedBookmarkModel* bookmark_model); |
27 ~BookmarkServerSearchService() override; | 28 ~BookmarkServerSearchService() override; |
28 | 29 |
29 // Triggers a search. The query must not be empty. A call to this method | 30 // Triggers a search. The query must not be empty. A call to this method |
30 // cancels any previous searches. OnChange() is garanteed to be called once | 31 // cancels any previous searches. OnChange() is garanteed to be called once |
31 // per query. | 32 // per query. If there have been multiple queries in between, onChange will |
33 // only be called for the last query. | |
lpromero
2014/10/29 10:31:35
This comment contradicts the previous sentence:
"
Ian Wen
2014/10/29 21:54:37
Done.
| |
32 void Search(const std::string& query); | 34 void Search(const std::string& query); |
33 | 35 |
34 // Returns the search results. The results are only available after the | 36 // Returns the search results. The results are only available after the |
35 // OnChange() observer methods has been sent. This method will return an empty | 37 // OnChange() observer methods has been sent. This method will return an empty |
36 // result otherwise. query should be a string passed to Search() previously. | 38 // result otherwise. query should be a string passed to Search() previously. |
37 std::vector<const BookmarkNode*> ResultForQuery(const std::string& query); | 39 std::vector<const BookmarkNode*> ResultForQuery(const std::string& query); |
lpromero
2014/10/29 10:31:35
With the new API you introduce, will we ever use t
noyau (Ping after 24h)
2014/10/29 12:49:48
Probably add HasResultForQuery() returning a boole
| |
38 | 40 |
41 // Returns search retults for most recent query. | |
lpromero
2014/10/29 10:31:35
s/retults/results
Ian Wen
2014/10/29 21:54:37
Done.
| |
42 std::vector<const BookmarkNode*> ResultForQuery(); | |
lpromero
2014/10/29 10:31:35
s/ResultForQuery/ResultsForLastQuery or ResultsFor
noyau (Ping after 24h)
2014/10/29 12:49:48
I'm curious why you think you need this API? I'm r
Ian Wen
2014/10/29 21:54:36
The reason why I made the server to remember the l
| |
43 | |
44 // Returns most recent query string. | |
45 std::string GetCurrentQuery(); | |
noyau (Ping after 24h)
2014/10/29 12:49:48
GetSomething is a javaism. Just use CurrentQuery()
Ian Wen
2014/10/29 21:54:36
Done.
| |
46 | |
39 protected: | 47 protected: |
40 scoped_ptr<net::URLFetcher> CreateFetcher() override; | 48 scoped_ptr<net::URLFetcher> CreateFetcher() override; |
41 | 49 |
42 bool ProcessResponse(const std::string& response, | 50 bool ProcessResponse(const std::string& response, |
43 bool* should_notify) override; | 51 bool* should_notify) override; |
44 | 52 |
45 void CleanAfterFailure() override; | 53 void CleanAfterFailure() override; |
46 | 54 |
47 // EnhancedBookmarkModelObserver methods. | 55 // EnhancedBookmarkModelObserver methods. |
48 void EnhancedBookmarkModelLoaded() override{}; | 56 void EnhancedBookmarkModelLoaded() override{}; |
49 void EnhancedBookmarkAdded(const BookmarkNode* node) override; | 57 void EnhancedBookmarkAdded(const BookmarkNode* node) override; |
50 void EnhancedBookmarkRemoved(const BookmarkNode* node) override{}; | 58 void EnhancedBookmarkRemoved(const BookmarkNode* node) override{}; |
51 void EnhancedBookmarkAllUserNodesRemoved() override; | 59 void EnhancedBookmarkAllUserNodesRemoved() override; |
52 void EnhancedBookmarkRemoteIdChanged(const BookmarkNode* node, | 60 void EnhancedBookmarkRemoteIdChanged(const BookmarkNode* node, |
53 const std::string& old_remote_id, | 61 const std::string& old_remote_id, |
54 const std::string& remote_id) override; | 62 const std::string& remote_id) override; |
55 | 63 |
56 private: | 64 private: |
57 // The search data, a map from query to a vector of stars.id. | 65 // The search data, a map from query to a vector of stars.id. |
lpromero
2014/10/29 10:31:35
s/map/cache?
Ian Wen
2014/10/29 21:54:37
Done.
| |
58 std::map<std::string, std::vector<std::string> > searches_; | 66 base::MRUCache<std::string, std::vector<std::string> >* searches_; |
Kibeom Kim (inactive)
2014/10/29 07:51:47
Since the lifetime of |searches_| is the scope of
Ian Wen
2014/10/29 21:54:36
Done.
| |
59 std::string current_query_; | 67 std::string current_query_; |
noyau (Ping after 24h)
2014/10/29 12:49:48
Add a comment to this variable: current_query_ hol
Ian Wen
2014/10/29 21:54:37
Done.
| |
60 DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService); | 68 DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService); |
61 }; | 69 }; |
62 } // namespace enhanced_bookmarks | 70 } // namespace enhanced_bookmarks |
63 | 71 |
64 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ | 72 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ |
OLD | NEW |