Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / search / people / people_provider.h
blob1823109902f8383c0b232c942971d8e7d6af4f63
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"
13 #include "url/gurl.h"
15 class AppListControllerDelegate;
17 namespace base {
18 class DictionaryValue;
21 namespace app_list {
23 namespace test {
24 class PeopleProviderTest;
27 class JSONResponseFetcher;
28 class SearchResult;
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 {
35 public:
36 PeopleProvider(Profile* profile, AppListControllerDelegate* controller);
37 ~PeopleProvider() override;
39 // SearchProvider overrides:
40 void Start(bool is_voice_query, const base::string16& query) override;
41 void Stop() override;
43 // OAuth2TokenService::Consumer overrides:
44 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
45 const std::string& access_token,
46 const base::Time& expiration_time) override;
47 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
48 const GoogleServiceAuthError& error) override;
50 private:
51 friend class app_list::test::PeopleProviderTest;
53 // Start a request for getting the access token for people search.
54 void RequestAccessToken();
55 // Invalidate our existing token so a new one can be fetched.
56 void InvalidateToken();
58 // Get the full people search query URL. This URL includes the OAuth refresh
59 // token for authenticating the current user.
60 GURL GetQueryUrl(const std::string& query);
62 // Start the search request with |query_|.
63 void StartQuery();
65 // Callback for people search results being fetched.
66 void OnPeopleSearchFetched(scoped_ptr<base::DictionaryValue> json);
67 void ProcessPeopleSearchResults(const base::DictionaryValue* json);
68 scoped_ptr<SearchResult> CreateResult(const base::DictionaryValue& dict);
70 // Setup the various variables that we override for testing.
71 void SetupForTest(const base::Closure& people_search_fetched_callback,
72 const GURL& people_search_url);
74 AppListControllerDelegate* controller_;
75 scoped_ptr<JSONResponseFetcher> people_search_;
76 base::Closure people_search_fetched_callback_;
78 std::string access_token_;
79 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
80 OAuth2TokenService::ScopeSet oauth2_scope_;
82 // The current query.
83 std::string query_;
84 GURL people_search_url_;
86 bool skip_request_token_for_test_;
88 DISALLOW_COPY_AND_ASSIGN(PeopleProvider);
91 } // namespace app_list
93 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_PEOPLE_PEOPLE_PROVIDER_H_