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 "components/bookmarks/browser/base_bookmark_model_observer.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 class BookmarkModel; | 15 namespace enhanced_bookmarks { |
15 | 16 |
16 namespace enhanced_bookmarks { | 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, |
| 22 public BaseBookmarkModelObserver { |
21 public: | 23 public: |
22 BookmarkServerSearchService( | 24 BookmarkServerSearchService( |
23 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 25 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
24 ProfileOAuth2TokenService* token_service, | 26 ProfileOAuth2TokenService* token_service, |
25 SigninManagerBase* signin_manager, | 27 SigninManagerBase* signin_manager, |
26 BookmarkModel* bookmark_model); | 28 EnhancedBookmarkModel* bookmark_model); |
27 virtual ~BookmarkServerSearchService(); | 29 virtual ~BookmarkServerSearchService(); |
28 | 30 |
29 // Triggers a search. The query must not be empty. A call to this method | 31 // 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 | 32 // cancels any previous searches. OnChange() is garanteed to be called once |
31 // per query. | 33 // per query. |
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); |
38 | 40 |
39 protected: | 41 protected: |
40 | 42 |
41 virtual net::URLFetcher* CreateFetcher() OVERRIDE; | 43 virtual net::URLFetcher* CreateFetcher() OVERRIDE; |
42 | 44 |
43 virtual bool ProcessResponse(const std::string& response, | 45 virtual bool ProcessResponse(const std::string& response, |
44 bool* should_notify) OVERRIDE; | 46 bool* should_notify) OVERRIDE; |
45 | 47 |
46 virtual void CleanAfterFailure() OVERRIDE; | 48 virtual void CleanAfterFailure() OVERRIDE; |
47 | 49 |
48 // BookmarkModelObserver methods. | 50 // BaseBookmarkModelObserver methods. |
| 51 virtual void BookmarkModelChanged() OVERRIDE{}; |
49 virtual void BookmarkNodeAdded(BookmarkModel* model, | 52 virtual void BookmarkNodeAdded(BookmarkModel* model, |
50 const BookmarkNode* parent, | 53 const BookmarkNode* parent, |
51 int index) OVERRIDE; | 54 int index) OVERRIDE; |
52 virtual void BookmarkMetaInfoChanged(BookmarkModel* model, | 55 virtual void BookmarkMetaInfoChanged(BookmarkModel* model, |
53 const BookmarkNode* node) OVERRIDE; | 56 const BookmarkNode* node) OVERRIDE; |
54 | 57 |
55 private: | 58 private: |
56 // The search data, a map from query to a vector of stars.id. | 59 // The search data, a map from query to a vector of stars.id. |
57 std::map<std::string, std::vector<std::string> > searches_; | 60 std::map<std::string, std::vector<std::string> > searches_; |
58 std::string current_query_; | 61 std::string current_query_; |
59 DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService); | 62 DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService); |
60 }; | 63 }; |
61 } // namespace enhanced_bookmarks | 64 } // namespace enhanced_bookmarks |
62 | 65 |
63 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ | 66 #endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_ |
OLD | NEW |