| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_ | |
| 6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.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" | |
| 17 | |
| 18 class Profile; | |
| 19 class SkBitmap; | |
| 20 | |
| 21 namespace suggestions { | |
| 22 | |
| 23 // SuggestionsSource renders a webpage to list SuggestionsService data. | |
| 24 class SuggestionsSource : public content::URLDataSource { | |
| 25 public: | |
| 26 explicit SuggestionsSource(Profile* profile); | |
| 27 | |
| 28 // content::URLDataSource implementation. | |
| 29 std::string GetSource() const override; | |
| 30 void StartDataRequest( | |
| 31 const std::string& path, | |
| 32 int render_process_id, | |
| 33 int render_frame_id, | |
| 34 const content::URLDataSource::GotDataCallback& callback) override; | |
| 35 std::string GetMimeType(const std::string& path) const override; | |
| 36 base::MessageLoop* MessageLoopForRequestPath( | |
| 37 const std::string& path) const override; | |
| 38 | |
| 39 private: | |
| 40 ~SuggestionsSource() override; | |
| 41 | |
| 42 // Container for the state of a request. | |
| 43 struct RequestContext { | |
| 44 RequestContext( | |
| 45 bool is_refresh_in, | |
| 46 const suggestions::SuggestionsProfile& suggestions_profile_in, | |
| 47 const content::URLDataSource::GotDataCallback& callback_in); | |
| 48 ~RequestContext(); | |
| 49 | |
| 50 const bool is_refresh; | |
| 51 const suggestions::SuggestionsProfile suggestions_profile; | |
| 52 const content::URLDataSource::GotDataCallback callback; | |
| 53 std::map<GURL, std::string> base64_encoded_pngs; | |
| 54 }; | |
| 55 | |
| 56 // Callback for responses from each Thumbnail request. | |
| 57 void OnThumbnailAvailable(RequestContext* context, base::Closure barrier, | |
| 58 const GURL& url, const SkBitmap* bitmap); | |
| 59 | |
| 60 // Callback for when all requests are complete. Renders the output webpage and | |
| 61 // passes the result to the original caller. | |
| 62 void OnThumbnailsFetched(RequestContext* context); | |
| 63 | |
| 64 // Only used when servicing requests on the UI thread. | |
| 65 Profile* const profile_; | |
| 66 | |
| 67 // For callbacks may be run after destruction. | |
| 68 base::WeakPtrFactory<SuggestionsSource> weak_ptr_factory_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(SuggestionsSource); | |
| 71 }; | |
| 72 | |
| 73 } // namespace suggestions | |
| 74 | |
| 75 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SOURCE_H_ | |
| OLD | NEW |