blob: 97713185418368ce34a427eb54a50588a96c7eee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright 2014 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 COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_
#define COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_
#include <string>
#include <vector>
#include "components/enhanced_bookmarks/bookmark_server_service.h"
#include "net/url_request/url_fetcher.h"
namespace enhanced_bookmarks {
class EnhancedBookmarkModel;
// Sends requests to the bookmark server to search for bookmarks relevant to a
// given query. Will handle one outgoing request at a time.
class BookmarkServerSearchService : public BookmarkServerService {
public:
BookmarkServerSearchService(
scoped_refptr<net::URLRequestContextGetter> request_context_getter,
ProfileOAuth2TokenService* token_service,
SigninManagerBase* signin_manager,
EnhancedBookmarkModel* bookmark_model);
~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.
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);
protected:
scoped_ptr<net::URLFetcher> CreateFetcher() override;
bool ProcessResponse(const std::string& response,
bool* should_notify) override;
void CleanAfterFailure() override;
// EnhancedBookmarkModelObserver methods.
void EnhancedBookmarkModelLoaded() override{};
void EnhancedBookmarkAdded(const BookmarkNode* node) override;
void EnhancedBookmarkRemoved(const BookmarkNode* node) override{};
void EnhancedBookmarkAllUserNodesRemoved() override;
void EnhancedBookmarkRemoteIdChanged(const BookmarkNode* node,
const std::string& old_remote_id,
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_;
std::string current_query_;
DISALLOW_COPY_AND_ASSIGN(BookmarkServerSearchService);
};
} // namespace enhanced_bookmarks
#endif // COMPONENTS_ENHANCED_BOOKMARKS_BOOKMARK_SERVER_SEARCH_SERVICE_H_
|