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_COMMON_JSON_RESPONSE_FETCHER_H_
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_JSON_RESPONSE_FETCHER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "net/url_request/url_fetcher_delegate.h"
19 class DictionaryValue;
25 class URLRequestContextGetter;
30 // A class that fetches a JSON formatted response from a server and uses a
31 // sandboxed utility process to parse it to a DictionaryValue.
32 // TODO(rkc): Add the ability to give control of handling http failures to
33 // the consumers of this class.
34 class JSONResponseFetcher : public net::URLFetcherDelegate {
36 // Callback to pass back the parsed json dictionary returned from the server.
37 // Invoked with NULL if there is an error.
38 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>)> Callback;
40 JSONResponseFetcher(const Callback& callback,
41 net::URLRequestContextGetter* context_getter);
42 ~JSONResponseFetcher() override;
44 // Starts to fetch results for the given |query_url|.
45 void Start(const GURL& query_url);
49 // Callbacks for SafeJsonParser.
50 void OnJsonParseSuccess(scoped_ptr<base::Value> parsed_json);
51 void OnJsonParseError(const std::string& error);
53 // net::URLFetcherDelegate overrides:
54 void OnURLFetchComplete(const net::URLFetcher* source) override;
57 net::URLRequestContextGetter* context_getter_;
59 scoped_ptr<net::URLFetcher> fetcher_;
60 base::WeakPtrFactory<JSONResponseFetcher> weak_factory_;
62 DISALLOW_COPY_AND_ASSIGN(JSONResponseFetcher);
65 } // namespace app_list
67 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_COMMON_JSON_RESPONSE_FETCHER_H_