| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/ui/app_list/search/people/people_provider.h" | 5 #include "chrome/browser/ui/app_list/search/people/people_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 PeopleProvider::~PeopleProvider() {} | 51 PeopleProvider::~PeopleProvider() {} |
| 52 | 52 |
| 53 void PeopleProvider::Start(const base::string16& query) { | 53 void PeopleProvider::Start(const base::string16& query) { |
| 54 ClearResults(); | 54 ClearResults(); |
| 55 if (!IsValidQuery(query)) { | 55 if (!IsValidQuery(query)) { |
| 56 query_.clear(); | 56 query_.clear(); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 | 59 |
| 60 query_ = UTF16ToUTF8(query); | 60 query_ = UTF16ToUTF8(query); |
| 61 const base::DictionaryValue* cached_result = cache_.Get(query_); | 61 |
| 62 if (cached_result) { | 62 const CacheResult result = cache_->Get(WebserviceCache::PEOPLE, query_); |
| 63 ProcessPeopleSearchResults(cached_result); | 63 if (result.second) { |
| 64 ProcessPeopleSearchResults(result.second); |
| 64 if (!people_search_fetched_callback_.is_null()) | 65 if (!people_search_fetched_callback_.is_null()) |
| 65 people_search_fetched_callback_.Run(); | 66 people_search_fetched_callback_.Run(); |
| 66 return; | 67 if (result.first == FRESH) |
| 68 return; |
| 67 } | 69 } |
| 68 | 70 |
| 71 |
| 69 if (!people_search_) { | 72 if (!people_search_) { |
| 70 people_search_.reset(new JSONResponseFetcher( | 73 people_search_.reset(new JSONResponseFetcher( |
| 71 base::Bind(&PeopleProvider::OnPeopleSearchFetched, | 74 base::Bind(&PeopleProvider::OnPeopleSearchFetched, |
| 72 base::Unretained(this)), | 75 base::Unretained(this)), |
| 73 profile_->GetRequestContext())); | 76 profile_->GetRequestContext())); |
| 74 } | 77 } |
| 75 | 78 |
| 76 if (!skip_request_token_for_test_) { | 79 if (!skip_request_token_for_test_) { |
| 77 // We start with reqesting the access token. Once the token is fetched, | 80 // We start with reqesting the access token. Once the token is fetched, |
| 78 // we'll create the full query URL and fetch it. | 81 // we'll create the full query URL and fetch it. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (!people_search_ || query_.empty()) | 139 if (!people_search_ || query_.empty()) |
| 137 return; | 140 return; |
| 138 | 141 |
| 139 GURL url = GetQueryUrl(query_); | 142 GURL url = GetQueryUrl(query_); |
| 140 people_search_->Start(url); | 143 people_search_->Start(url); |
| 141 } | 144 } |
| 142 | 145 |
| 143 void PeopleProvider::OnPeopleSearchFetched( | 146 void PeopleProvider::OnPeopleSearchFetched( |
| 144 scoped_ptr<base::DictionaryValue> json) { | 147 scoped_ptr<base::DictionaryValue> json) { |
| 145 ProcessPeopleSearchResults(json.get()); | 148 ProcessPeopleSearchResults(json.get()); |
| 146 cache_.Put(query_, json.Pass()); | 149 cache_->Put(WebserviceCache::PEOPLE, query_, json.Pass()); |
| 147 | 150 |
| 148 if (!people_search_fetched_callback_.is_null()) | 151 if (!people_search_fetched_callback_.is_null()) |
| 149 people_search_fetched_callback_.Run(); | 152 people_search_fetched_callback_.Run(); |
| 150 } | 153 } |
| 151 | 154 |
| 152 void PeopleProvider::ProcessPeopleSearchResults( | 155 void PeopleProvider::ProcessPeopleSearchResults( |
| 153 const base::DictionaryValue* json) { | 156 const base::DictionaryValue* json) { |
| 154 const base::ListValue* item_list = NULL; | 157 const base::ListValue* item_list = NULL; |
| 155 if (!json || | 158 if (!json || |
| 156 !json->GetList(kKeyItems, &item_list) || | 159 !json->GetList(kKeyItems, &item_list) || |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 192 |
| 190 void PeopleProvider::SetupForTest( | 193 void PeopleProvider::SetupForTest( |
| 191 const base::Closure& people_search_fetched_callback, | 194 const base::Closure& people_search_fetched_callback, |
| 192 const GURL& people_search_url) { | 195 const GURL& people_search_url) { |
| 193 people_search_fetched_callback_ = people_search_fetched_callback; | 196 people_search_fetched_callback_ = people_search_fetched_callback; |
| 194 people_search_url_ = people_search_url; | 197 people_search_url_ = people_search_url; |
| 195 skip_request_token_for_test_ = true; | 198 skip_request_token_for_test_ = true; |
| 196 } | 199 } |
| 197 | 200 |
| 198 } // namespace app_list | 201 } // namespace app_list |
| OLD | NEW |