| Index: components/enhanced_bookmarks/bookmark_server_search_service.cc
|
| diff --git a/components/enhanced_bookmarks/bookmark_server_search_service.cc b/components/enhanced_bookmarks/bookmark_server_search_service.cc
|
| index e1ab78eeef443f3b134520d18854662bb8e1e4b7..0cf4690164817ce3fd88c415ef936c118cce9496 100644
|
| --- a/components/enhanced_bookmarks/bookmark_server_search_service.cc
|
| +++ b/components/enhanced_bookmarks/bookmark_server_search_service.cc
|
| @@ -12,7 +12,6 @@
|
|
|
| namespace {
|
| const char kSearchUrl[] = "https://www.google.com/stars/search";
|
| -const int kSearchCacheMaxSize = 50;
|
| } // namespace
|
|
|
| namespace enhanced_bookmarks {
|
| @@ -25,8 +24,7 @@
|
| : BookmarkServerService(request_context_getter,
|
| token_service,
|
| signin_manager,
|
| - enhanced_bookmark_model),
|
| - cache_(kSearchCacheMaxSize) {
|
| + enhanced_bookmark_model) {
|
| }
|
|
|
| BookmarkServerSearchService::~BookmarkServerSearchService() {
|
| @@ -34,34 +32,26 @@
|
|
|
| void BookmarkServerSearchService::Search(const std::string& query) {
|
| DCHECK(query.length());
|
| - if (current_query_ == query)
|
| - return;
|
| -
|
| - // If result is already stored in cache, immediately notify observers.
|
| - if (cache_.Get(current_query_) != cache_.end()) {
|
| - Cancel();
|
| - Notify();
|
| - return;
|
| - }
|
| current_query_ = query;
|
| TriggerTokenRequest(true);
|
| }
|
|
|
| -scoped_ptr<std::vector<const BookmarkNode*>>
|
| -BookmarkServerSearchService::ResultForQuery(const std::string& query) {
|
| +std::vector<const BookmarkNode*> BookmarkServerSearchService::ResultForQuery(
|
| + const std::string& query) {
|
| DCHECK(query.length());
|
| - scoped_ptr<std::vector<const BookmarkNode*>> result;
|
| + std::vector<const BookmarkNode*> result;
|
|
|
| - const auto& it = cache_.Get(query);
|
| - if (it == cache_.end())
|
| + std::map<std::string, std::vector<std::string> >::iterator it =
|
| + searches_.find(query);
|
| + if (it == searches_.end())
|
| return result;
|
|
|
| - result.reset(new std::vector<const BookmarkNode*>());
|
| -
|
| - for (const std::string& clip_id : it->second) {
|
| - const BookmarkNode* node = BookmarkForRemoteId(clip_id);
|
| + for (std::vector<std::string>::iterator clip_it = it->second.begin();
|
| + clip_it != it->second.end();
|
| + ++clip_it) {
|
| + const BookmarkNode* node = BookmarkForRemoteId(*clip_it);
|
| if (node)
|
| - result->push_back(node);
|
| + result.push_back(node);
|
| }
|
| return result;
|
| }
|
| @@ -90,36 +80,38 @@
|
| return false; // Not formatted properly.
|
|
|
| std::vector<std::string> clip_ids;
|
| - for (const image::collections::CorpusSearchResult_ClipResult& clip_result :
|
| - response_proto.results()) {
|
| - const std::string& clip_id = clip_result.clip_id();
|
| + for (google::protobuf::RepeatedPtrField<
|
| + image::collections::CorpusSearchResult_ClipResult>::const_iterator
|
| + it = response_proto.results().begin();
|
| + it != response_proto.results().end();
|
| + ++it) {
|
| + const std::string& clip_id = it->clip_id();
|
| if (!clip_id.length())
|
| continue;
|
| clip_ids.push_back(clip_id);
|
| }
|
| - cache_.Put(current_query_, clip_ids);
|
| + searches_[current_query_] = clip_ids;
|
| current_query_.clear();
|
| return true;
|
| }
|
|
|
| void BookmarkServerSearchService::CleanAfterFailure() {
|
| - cache_.Clear();
|
| - current_query_.clear();
|
| + searches_.clear();
|
| }
|
|
|
| void BookmarkServerSearchService::EnhancedBookmarkAdded(
|
| const BookmarkNode* node) {
|
| - cache_.Clear();
|
| + searches_.clear();
|
| }
|
|
|
| void BookmarkServerSearchService::EnhancedBookmarkAllUserNodesRemoved() {
|
| - cache_.Clear();
|
| + searches_.clear();
|
| }
|
|
|
| void BookmarkServerSearchService::EnhancedBookmarkRemoteIdChanged(
|
| const BookmarkNode* node,
|
| const std::string& old_remote_id,
|
| const std::string& remote_id) {
|
| - cache_.Clear();
|
| + searches_.clear();
|
| }
|
| } // namespace enhanced_bookmarks
|
|
|