Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / search / suggestions / suggestions_source.h
blobeb31cb42c5eb6a9ee2da3f28ff80af7fb1632186
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_
8 #include <map>
9 #include <string>
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"
16 #include "url/gurl.h"
18 class Profile;
19 class SkBitmap;
21 namespace base {
22 class RefCountedMemory;
23 } // namespace base
25 namespace suggestions {
27 // SuggestionsSource renders a webpage to list SuggestionsService data.
28 class SuggestionsSource : public content::URLDataSource {
29 public:
30 explicit SuggestionsSource(Profile* profile);
32 // content::URLDataSource implementation.
33 std::string GetSource() const override;
34 void StartDataRequest(
35 const std::string& path,
36 int render_process_id,
37 int render_frame_id,
38 const content::URLDataSource::GotDataCallback& callback) override;
39 std::string GetMimeType(const std::string& path) const override;
40 base::MessageLoop* MessageLoopForRequestPath(
41 const std::string& path) const override;
43 private:
44 ~SuggestionsSource() override;
46 // Container for the state of a request.
47 struct RequestContext {
48 RequestContext(
49 const suggestions::SuggestionsProfile& suggestions_profile_in,
50 const content::URLDataSource::GotDataCallback& callback_in);
51 ~RequestContext();
53 const suggestions::SuggestionsProfile suggestions_profile;
54 const content::URLDataSource::GotDataCallback callback;
55 std::map<GURL, std::string> base64_encoded_pngs;
58 // Callback for suggestions from SuggestionsService.
59 void OnSuggestionsAvailable(
60 const content::URLDataSource::GotDataCallback& callback,
61 const SuggestionsProfile& suggestions_profile);
63 // Callback for responses from each Thumbnail request.
64 void OnThumbnailAvailable(RequestContext* context, base::Closure barrier,
65 const GURL& url, const SkBitmap* bitmap);
67 // Callback for when all requests are complete. Renders the output webpage and
68 // passes the result to the original caller.
69 void OnThumbnailsFetched(RequestContext* context);
71 // Only used when servicing requests on the UI thread.
72 Profile* const profile_;
74 // For callbacks may be run after destruction.
75 base::WeakPtrFactory<SuggestionsSource> weak_ptr_factory_;
77 DISALLOW_COPY_AND_ASSIGN(SuggestionsSource);
80 } // namespace suggestions
82 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_