Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
|
huangs
2014/05/23 17:23:35
thumbnail_manager.h is included solely for
typede
Mathieu
2014/05/23 19:21:58
Removed the typedef..
| |
| 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" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace suggestions { | 23 namespace suggestions { |
| 23 | 24 |
| 24 extern const char kSuggestionsFieldTrialName[]; | 25 extern const char kSuggestionsFieldTrialName[]; |
| 25 extern const char kSuggestionsFieldTrialURLParam[]; | 26 extern const char kSuggestionsFieldTrialURLParam[]; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 36 | 37 |
| 37 // Whether this service is enabled. | 38 // Whether this service is enabled. |
| 38 static bool IsEnabled(); | 39 static bool IsEnabled(); |
| 39 | 40 |
| 40 // Request suggestions data, which will be passed to |callback|. Initiates a | 41 // Request suggestions data, which will be passed to |callback|. Initiates a |
| 41 // fetch request unless a pending one exists. To prevent multiple requests, | 42 // 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 | 43 // we place all |callback|s in a queue and update them simultaneously when |
| 43 // fetch request completes. | 44 // fetch request completes. |
| 44 void FetchSuggestionsData(ResponseCallback callback); | 45 void FetchSuggestionsData(ResponseCallback callback); |
| 45 | 46 |
| 47 // Retrieves stored thumbnail for website |url| asynchronously. Returns | |
|
Jered
2014/05/23 16:57:48
s/Returns (.*) to/Calls |callback| with/
Mathieu
2014/05/23 19:21:58
Done.
| |
| 48 // thumbnail image as a Bitmap pointer to |callback| if found, and NULL | |
| 49 // otherwise. | |
| 50 void GetPageThumbnail(const GURL& url, BitmapResponseCallback callback); | |
| 51 | |
| 46 private: | 52 private: |
| 47 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); | 53 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); |
| 48 | 54 |
| 49 // net::URLFetcherDelegate implementation. | 55 // net::URLFetcherDelegate implementation. |
| 50 // Called when fetch request completes. Parses the received suggestions data, | 56 // Called when fetch request completes. Parses the received suggestions data, |
| 51 // and dispatches them to callbacks stored in queue. | 57 // and dispatches them to callbacks stored in queue. |
| 52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 58 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 53 | 59 |
| 54 // KeyedService implementation. | 60 // KeyedService implementation. |
| 55 virtual void Shutdown() OVERRIDE; | 61 virtual void Shutdown() OVERRIDE; |
| 56 | 62 |
| 57 // Contains the current suggestions fetch request. Will only have a value | 63 // Contains the current suggestions fetch request. Will only have a value |
| 58 // while a request is pending, and will be reset by |OnURLFetchComplete|. | 64 // while a request is pending, and will be reset by |OnURLFetchComplete|. |
| 59 scoped_ptr<net::URLFetcher> pending_request_; | 65 scoped_ptr<net::URLFetcher> pending_request_; |
| 60 | 66 |
| 61 // The start time of the previous suggestions request. This is used to measure | 67 // The start time of the previous suggestions request. This is used to measure |
| 62 // the latency of requests. Initially zero. | 68 // the latency of requests. Initially zero. |
| 63 base::TimeTicks last_request_started_time_; | 69 base::TimeTicks last_request_started_time_; |
| 64 | 70 |
| 65 // The URL to fetch suggestions data from. | 71 // The URL to fetch suggestions data from. |
| 66 GURL suggestions_url_; | 72 GURL suggestions_url_; |
| 67 | 73 |
| 68 // Queue of callbacks. These are flushed when fetch request completes. | 74 // Queue of callbacks. These are flushed when fetch request completes. |
| 69 std::vector<ResponseCallback> waiting_requestors_; | 75 std::vector<ResponseCallback> waiting_requestors_; |
| 70 | 76 |
| 77 // Used to obtain server thumbnails, if available. | |
| 78 scoped_ptr<ThumbnailManager> thumbnail_manager_; | |
| 79 | |
| 71 Profile* profile_; | 80 Profile* profile_; |
| 72 | 81 |
| 73 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); | 82 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); |
| 74 }; | 83 }; |
| 75 | 84 |
| 76 } // namespace suggestions | 85 } // namespace suggestions |
| 77 | 86 |
| 78 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ | 87 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |