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.
5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/app_list/search/common/webservice_search_provider.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
15 class AppListControllerDelegate;
18 class DictionaryValue;
24 class PeopleProviderTest;
27 class ChromeSearchResult;
28 class JSONResponseFetcher;
30 // PeopleProvider fetches search results from the web store server.
31 // A "Search in web store" result will be returned if the server does not
32 // return any results.
33 class PeopleProvider : public WebserviceSearchProvider,
34 public OAuth2TokenService::Consumer {
36 explicit PeopleProvider(Profile* profile);
37 virtual ~PeopleProvider();
39 // SearchProvider overrides:
40 virtual void Start(const base::string16& query) OVERRIDE;
41 virtual void Stop() OVERRIDE;
43 // OAuth2TokenService::Consumer overrides:
44 virtual void OnGetTokenSuccess(
45 const OAuth2TokenService::Request* request,
46 const std::string& access_token,
47 const base::Time& expiration_time) OVERRIDE;
48 virtual void OnGetTokenFailure(
49 const OAuth2TokenService::Request* request,
50 const GoogleServiceAuthError& error) OVERRIDE;
53 friend class app_list::test::PeopleProviderTest;
55 // Start a request for getting the access token for people search.
56 void RequestAccessToken();
57 // Invalidate our existing token so a new one can be fetched.
58 void InvalidateToken();
60 // Get the full people search query URL. This URL includes the OAuth refresh
61 // token for authenticating the current user.
62 GURL GetQueryUrl(const std::string& query);
64 // Start the search request with |query_|.
67 // Callback for people search results being fetched.
68 void OnPeopleSearchFetched(scoped_ptr<base::DictionaryValue> json);
69 void ProcessPeopleSearchResults(const base::DictionaryValue* json);
70 scoped_ptr<ChromeSearchResult> CreateResult(
71 const base::DictionaryValue& dict);
73 // Setup the various variables that we override for testing.
74 void SetupForTest(const base::Closure& people_search_fetched_callback,
75 const GURL& people_search_url);
77 scoped_ptr<JSONResponseFetcher> people_search_;
78 base::Closure people_search_fetched_callback_;
80 std::string access_token_;
81 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
82 OAuth2TokenService::ScopeSet oauth2_scope_;
86 GURL people_search_url_;
88 bool skip_request_token_for_test_;
90 DISALLOW_COPY_AND_ASSIGN(PeopleProvider);
93 } // namespace app_list
95 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_