Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: chrome/browser/search/suggestions/suggestions_service.h

Issue 299713007: [Suggestions] Adding a Thumbnail Manager for the Suggestions Service (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now swapping Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
7 7
8 #include <vector> 8 #include <vector>
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/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" 15 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
16 #include "chrome/browser/search/suggestions/thumbnail_manager.h"
16 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
17 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
19 #include "ui/gfx/image/image_skia.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 21
20 class Profile; 22 class Profile;
21 23
22 namespace suggestions { 24 namespace suggestions {
23 25
24 extern const char kSuggestionsFieldTrialName[]; 26 extern const char kSuggestionsFieldTrialName[];
25 extern const char kSuggestionsFieldTrialURLParam[]; 27 extern const char kSuggestionsFieldTrialURLParam[];
26 extern const char kSuggestionsFieldTrialStateParam[]; 28 extern const char kSuggestionsFieldTrialStateParam[];
27 extern const char kSuggestionsFieldTrialStateEnabled[]; 29 extern const char kSuggestionsFieldTrialStateEnabled[];
28 30
29 // An interface to fetch server suggestions asynchronously. 31 // An interface to fetch server suggestions asynchronously.
30 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { 32 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate {
31 public: 33 public:
32 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; 34 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback;
33 35
34 explicit SuggestionsService(Profile* profile); 36 explicit SuggestionsService(Profile* profile);
35 virtual ~SuggestionsService(); 37 virtual ~SuggestionsService();
36 38
37 // Whether this service is enabled. 39 // Whether this service is enabled.
38 static bool IsEnabled(); 40 static bool IsEnabled();
39 41
40 // Request suggestions data, which will be passed to |callback|. Initiates a 42 // Request suggestions data, which will be passed to |callback|. Initiates a
41 // fetch request unless a pending one exists. To prevent multiple requests, 43 // fetch request unless a pending one exists. To prevent multiple requests,
42 // we place all |callback|s in a queue and update them simultaneously when 44 // we place all |callback|s in a queue and update them simultaneously when
43 // fetch request completes. 45 // fetch request completes.
44 void FetchSuggestionsData(ResponseCallback callback); 46 void FetchSuggestionsData(ResponseCallback callback);
45 47
48 // Retrieves stored thumbnail for website |url| asynchronously. Calls
49 // |callback| with Bitmap pointer if found, and NULL otherwise.
50 void GetPageThumbnail(
51 const GURL& url,
52 base::Callback<void(const GURL&, const SkBitmap*)> callback);
53
46 private: 54 private:
47 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); 55 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData);
48 56
49 // net::URLFetcherDelegate implementation. 57 // net::URLFetcherDelegate implementation.
50 // Called when fetch request completes. Parses the received suggestions data, 58 // Called when fetch request completes. Parses the received suggestions data,
51 // and dispatches them to callbacks stored in queue. 59 // and dispatches them to callbacks stored in queue.
52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
53 61
54 // KeyedService implementation. 62 // KeyedService implementation.
55 virtual void Shutdown() OVERRIDE; 63 virtual void Shutdown() OVERRIDE;
56 64
57 // Contains the current suggestions fetch request. Will only have a value 65 // Contains the current suggestions fetch request. Will only have a value
58 // while a request is pending, and will be reset by |OnURLFetchComplete|. 66 // while a request is pending, and will be reset by |OnURLFetchComplete|.
59 scoped_ptr<net::URLFetcher> pending_request_; 67 scoped_ptr<net::URLFetcher> pending_request_;
60 68
61 // The start time of the previous suggestions request. This is used to measure 69 // The start time of the previous suggestions request. This is used to measure
62 // the latency of requests. Initially zero. 70 // the latency of requests. Initially zero.
63 base::TimeTicks last_request_started_time_; 71 base::TimeTicks last_request_started_time_;
64 72
65 // The URL to fetch suggestions data from. 73 // The URL to fetch suggestions data from.
66 GURL suggestions_url_; 74 GURL suggestions_url_;
67 75
68 // Queue of callbacks. These are flushed when fetch request completes. 76 // Queue of callbacks. These are flushed when fetch request completes.
69 std::vector<ResponseCallback> waiting_requestors_; 77 std::vector<ResponseCallback> waiting_requestors_;
70 78
79 // Used to obtain server thumbnails, if available.
80 scoped_ptr<ThumbnailManager> thumbnail_manager_;
81
71 Profile* profile_; 82 Profile* profile_;
72 83
73 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); 84 DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
74 }; 85 };
75 86
76 } // namespace suggestions 87 } // namespace suggestions
77 88
78 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 89 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/search/suggestions/proto/suggestions.proto ('k') | chrome/browser/search/suggestions/suggestions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698