| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void PeopleProvider::StartQuery() { | 147 void PeopleProvider::StartQuery() { |
| 148 // |query_| can be NULL when the query is scheduled but then canceled. | 148 // |query_| can be NULL when the query is scheduled but then canceled. |
| 149 if (!people_search_ || query_.empty()) | 149 if (!people_search_ || query_.empty()) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 GURL url = GetQueryUrl(query_); | 152 GURL url = GetQueryUrl(query_); |
| 153 people_search_->Start(url); | 153 people_search_->Start(url); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void PeopleProvider::OnPeopleSearchFetched( | 156 void PeopleProvider::OnPeopleSearchFetched( |
| 157 scoped_ptr<base::DictionaryValue> json) { | 157 std::unique_ptr<base::DictionaryValue> json) { |
| 158 ProcessPeopleSearchResults(json.get()); | 158 ProcessPeopleSearchResults(json.get()); |
| 159 cache_->Put(WebserviceCache::PEOPLE, query_, std::move(json)); | 159 cache_->Put(WebserviceCache::PEOPLE, query_, std::move(json)); |
| 160 | 160 |
| 161 if (!people_search_fetched_callback_.is_null()) | 161 if (!people_search_fetched_callback_.is_null()) |
| 162 people_search_fetched_callback_.Run(); | 162 people_search_fetched_callback_.Run(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void PeopleProvider::ProcessPeopleSearchResults( | 165 void PeopleProvider::ProcessPeopleSearchResults( |
| 166 const base::DictionaryValue* json) { | 166 const base::DictionaryValue* json) { |
| 167 const base::ListValue* item_list = NULL; | 167 const base::ListValue* item_list = NULL; |
| 168 if (!json || | 168 if (!json || |
| 169 !json->GetList(kKeyItems, &item_list) || | 169 !json->GetList(kKeyItems, &item_list) || |
| 170 !item_list || | 170 !item_list || |
| 171 item_list->empty()) { | 171 item_list->empty()) { |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 | 174 |
| 175 ClearResults(); | 175 ClearResults(); |
| 176 for (base::ListValue::const_iterator it = item_list->begin(); | 176 for (base::ListValue::const_iterator it = item_list->begin(); |
| 177 it != item_list->end(); | 177 it != item_list->end(); |
| 178 ++it) { | 178 ++it) { |
| 179 const base::DictionaryValue* dict; | 179 const base::DictionaryValue* dict; |
| 180 if (!(*it)->GetAsDictionary(&dict)) | 180 if (!(*it)->GetAsDictionary(&dict)) |
| 181 continue; | 181 continue; |
| 182 | 182 |
| 183 scoped_ptr<SearchResult> result(CreateResult(*dict)); | 183 std::unique_ptr<SearchResult> result(CreateResult(*dict)); |
| 184 if (!result) | 184 if (!result) |
| 185 continue; | 185 continue; |
| 186 | 186 |
| 187 Add(std::move(result)); | 187 Add(std::move(result)); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 scoped_ptr<SearchResult> PeopleProvider::CreateResult( | 191 std::unique_ptr<SearchResult> PeopleProvider::CreateResult( |
| 192 const base::DictionaryValue& dict) { | 192 const base::DictionaryValue& dict) { |
| 193 scoped_ptr<SearchResult> result; | 193 std::unique_ptr<SearchResult> result; |
| 194 | 194 |
| 195 scoped_ptr<Person> person = Person::Create(dict); | 195 std::unique_ptr<Person> person = Person::Create(dict); |
| 196 if (!person) | 196 if (!person) |
| 197 return result; | 197 return result; |
| 198 | 198 |
| 199 result.reset(new PeopleResult(profile_, controller_, std::move(person))); | 199 result.reset(new PeopleResult(profile_, controller_, std::move(person))); |
| 200 return result; | 200 return result; |
| 201 } | 201 } |
| 202 | 202 |
| 203 void PeopleProvider::SetupForTest( | 203 void PeopleProvider::SetupForTest( |
| 204 const base::Closure& people_search_fetched_callback, | 204 const base::Closure& people_search_fetched_callback, |
| 205 const GURL& people_search_url) { | 205 const GURL& people_search_url) { |
| 206 people_search_fetched_callback_ = people_search_fetched_callback; | 206 people_search_fetched_callback_ = people_search_fetched_callback; |
| 207 people_search_url_ = people_search_url; | 207 people_search_url_ = people_search_url; |
| 208 skip_request_token_for_test_ = true; | 208 skip_request_token_for_test_ = true; |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace app_list | 211 } // namespace app_list |
| OLD | NEW |