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