| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_ | |
| 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/callback_forward.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h" | |
| 13 #include "google_apis/gaia/oauth2_token_service.h" | |
| 14 #include "url/gurl.h" | |
| 15 | |
| 16 class AppListControllerDelegate; | |
| 17 | |
| 18 namespace base { | |
| 19 class DictionaryValue; | |
| 20 } | |
| 21 | |
| 22 namespace app_list { | |
| 23 | |
| 24 namespace test { | |
| 25 class PeopleProviderTest; | |
| 26 } | |
| 27 | |
| 28 class JSONResponseFetcher; | |
| 29 class SearchResult; | |
| 30 | |
| 31 // PeopleProvider fetches search results from the web store server. | |
| 32 // A "Search in web store" result will be returned if the server does not | |
| 33 // return any results. | |
| 34 class PeopleProvider : public WebserviceSearchProvider, | |
| 35 public OAuth2TokenService::Consumer { | |
| 36 public: | |
| 37 PeopleProvider(Profile* profile, AppListControllerDelegate* controller); | |
| 38 ~PeopleProvider() override; | |
| 39 | |
| 40 // SearchProvider overrides: | |
| 41 void Start(bool is_voice_query, const base::string16& query) override; | |
| 42 void Stop() override; | |
| 43 | |
| 44 // OAuth2TokenService::Consumer overrides: | |
| 45 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 46 const std::string& access_token, | |
| 47 const base::Time& expiration_time) override; | |
| 48 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 49 const GoogleServiceAuthError& error) override; | |
| 50 | |
| 51 private: | |
| 52 friend class app_list::test::PeopleProviderTest; | |
| 53 | |
| 54 // Start a request for getting the access token for people search. | |
| 55 void RequestAccessToken(); | |
| 56 // Invalidate our existing token so a new one can be fetched. | |
| 57 void InvalidateToken(); | |
| 58 | |
| 59 // Get the full people search query URL. This URL includes the OAuth refresh | |
| 60 // token for authenticating the current user. | |
| 61 GURL GetQueryUrl(const std::string& query); | |
| 62 | |
| 63 // Start the search request with |query_|. | |
| 64 void StartQuery(); | |
| 65 | |
| 66 // Callback for people search results being fetched. | |
| 67 void OnPeopleSearchFetched(std::unique_ptr<base::DictionaryValue> json); | |
| 68 void ProcessPeopleSearchResults(const base::DictionaryValue* json); | |
| 69 std::unique_ptr<SearchResult> CreateResult(const base::DictionaryValue& dict); | |
| 70 | |
| 71 // Setup the various variables that we override for testing. | |
| 72 void SetupForTest(const base::Closure& people_search_fetched_callback, | |
| 73 const GURL& people_search_url); | |
| 74 | |
| 75 AppListControllerDelegate* controller_; | |
| 76 std::unique_ptr<JSONResponseFetcher> people_search_; | |
| 77 base::Closure people_search_fetched_callback_; | |
| 78 | |
| 79 std::string access_token_; | |
| 80 std::unique_ptr<OAuth2TokenService::Request> access_token_request_; | |
| 81 OAuth2TokenService::ScopeSet oauth2_scope_; | |
| 82 | |
| 83 // The current query. | |
| 84 std::string query_; | |
| 85 GURL people_search_url_; | |
| 86 | |
| 87 bool skip_request_token_for_test_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(PeopleProvider); | |
| 90 }; | |
| 91 | |
| 92 } // namespace app_list | |
| 93 | |
| 94 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_ | |
| OLD | NEW |