1 // Copyright 2014 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_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "components/suggestions/proto/suggestions.pb.h"
15 #include "content/public/browser/url_data_source.h"
22 class RefCountedMemory
;
25 namespace suggestions
{
27 // SuggestionsSource renders a webpage to list SuggestionsService data.
28 class SuggestionsSource
: public content::URLDataSource
{
30 explicit SuggestionsSource(Profile
* profile
);
32 // content::URLDataSource implementation.
33 virtual std::string
GetSource() const override
;
34 virtual void StartDataRequest(
35 const std::string
& path
, int render_process_id
, int render_frame_id
,
36 const content::URLDataSource::GotDataCallback
& callback
) override
;
37 virtual std::string
GetMimeType(const std::string
& path
) const override
;
38 virtual base::MessageLoop
* MessageLoopForRequestPath(
39 const std::string
& path
) const override
;
42 virtual ~SuggestionsSource();
44 // Container for the state of a request.
45 struct RequestContext
{
47 const suggestions::SuggestionsProfile
& suggestions_profile_in
,
48 const content::URLDataSource::GotDataCallback
& callback_in
);
51 const suggestions::SuggestionsProfile suggestions_profile
;
52 const content::URLDataSource::GotDataCallback callback
;
53 std::map
<GURL
, std::string
> base64_encoded_pngs
;
56 // Callback for suggestions from SuggestionsService.
57 void OnSuggestionsAvailable(
58 const content::URLDataSource::GotDataCallback
& callback
,
59 const SuggestionsProfile
& suggestions_profile
);
61 // Callback for responses from each Thumbnail request.
62 void OnThumbnailAvailable(RequestContext
* context
, base::Closure barrier
,
63 const GURL
& url
, const SkBitmap
* bitmap
);
65 // Callback for when all requests are complete. Renders the output webpage and
66 // passes the result to the original caller.
67 void OnThumbnailsFetched(RequestContext
* context
);
69 // Only used when servicing requests on the UI thread.
70 Profile
* const profile_
;
72 // For callbacks may be run after destruction.
73 base::WeakPtrFactory
<SuggestionsSource
> weak_ptr_factory_
;
75 DISALLOW_COPY_AND_ASSIGN(SuggestionsSource
);
78 } // namespace suggestions
80 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_