Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_SEARCH_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_JSON_RESPONSE_FETCHER_H_ |
| 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_SEARCH_FETCHER_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_JSON_RESPONSE_FETCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 | 15 |
| 16 class GURL; | |
| 17 | |
| 16 namespace base { | 18 namespace base { |
| 17 class DictionaryValue; | 19 class DictionaryValue; |
| 18 class Value; | 20 class Value; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace net { | 23 namespace net { |
| 22 class URLFetcher; | 24 class URLFetcher; |
| 23 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
| 24 } | 26 } |
| 25 | 27 |
| 26 namespace app_list { | 28 namespace app_list { |
| 27 | 29 |
| 28 // A class to fetch web store search result. | 30 // A class that fetches a JSON formatted response from a server and uses a |
| 29 class WebstoreSearchFetcher : public net::URLFetcherDelegate { | 31 // sandboxed utility process to parse it to a DictionaryValue. |
| 32 class JSONResponseFetcher : public net::URLFetcherDelegate { | |
|
tfarina
2013/09/04 23:49:52
this probably can be used by WalletClient (compone
rkc
2013/09/04 23:57:30
Wallet client's processing in OnURLFetchComplete i
tfarina
2013/09/04 23:59:05
sure, I was not suggesting you to try to make any
| |
| 30 public: | 33 public: |
| 31 // Callback to pass back the parsed json dictionary returned from the server. | 34 // Callback to pass back the parsed json dictionary returned from the server. |
| 32 // Invoked with NULL if there is an error. | 35 // Invoked with NULL if there is an error. |
| 33 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> Callback; | 36 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> Callback; |
| 34 | 37 |
| 35 WebstoreSearchFetcher(const Callback& callback, | 38 JSONResponseFetcher(const Callback& callback, |
| 36 net::URLRequestContextGetter* context_getter); | 39 net::URLRequestContextGetter* context_getter); |
| 37 virtual ~WebstoreSearchFetcher(); | 40 virtual ~JSONResponseFetcher(); |
| 38 | 41 |
| 39 // Starts to fetch results for the given |query| and the language code |hl|. | 42 // Starts to fetch results for the given |query_url|. |
| 40 void Start(const std::string& query, const std::string& hl); | 43 void Start(const GURL& query_url); |
| 41 void Stop(); | 44 void Stop(); |
| 42 | 45 |
| 43 private: | 46 private: |
| 44 // Callbacks for SafeJsonParser. | 47 // Callbacks for SafeJsonParser. |
| 45 void OnJsonParseSuccess(scoped_ptr<base::Value> parsed_json); | 48 void OnJsonParseSuccess(scoped_ptr<base::Value> parsed_json); |
| 46 void OnJsonParseError(const std::string& error); | 49 void OnJsonParseError(const std::string& error); |
| 47 | 50 |
| 48 // net::URLFetcherDelegate overrides: | 51 // net::URLFetcherDelegate overrides: |
| 49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 50 | 53 |
| 51 Callback callback_; | 54 Callback callback_; |
| 52 net::URLRequestContextGetter* context_getter_; | 55 net::URLRequestContextGetter* context_getter_; |
| 53 | 56 |
| 54 scoped_ptr<net::URLFetcher> fetcher_; | 57 scoped_ptr<net::URLFetcher> fetcher_; |
| 55 base::WeakPtrFactory<WebstoreSearchFetcher> weak_factory_; | 58 base::WeakPtrFactory<JSONResponseFetcher> weak_factory_; |
| 56 | 59 |
| 57 DISALLOW_COPY_AND_ASSIGN(WebstoreSearchFetcher); | 60 DISALLOW_COPY_AND_ASSIGN(JSONResponseFetcher); |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 } // namespace app_list | 63 } // namespace app_list |
| 61 | 64 |
| 62 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_WEBSTORE_SEARCH_FETCHER_H_ | 65 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_JSON_RESPONSE_FETCHER_H_ |
| OLD | NEW |