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

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

Issue 298703009: SuggestionsService blacklist handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Missed renaming. 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
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 <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" 16 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
16 #include "chrome/browser/search/suggestions/thumbnail_manager.h" 17 #include "chrome/browser/search/suggestions/thumbnail_manager.h"
17 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
18 #include "net/url_request/url_fetcher_delegate.h" 19 #include "net/url_request/url_fetcher_delegate.h"
19 #include "ui/gfx/image/image_skia.h" 20 #include "ui/gfx/image/image_skia.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 class Profile; 23 class Profile;
23 24
24 namespace suggestions { 25 namespace suggestions {
25 26
26 extern const char kSuggestionsFieldTrialName[]; 27 extern const char kSuggestionsFieldTrialName[];
27 extern const char kSuggestionsFieldTrialURLParam[]; 28 extern const char kSuggestionsFieldTrialURLParam[];
29 extern const char kSuggestionsFieldTrialSuggestionsSuffixParam[];
30 extern const char kSuggestionsFieldTrialBlacklistSuffixParam[];
28 extern const char kSuggestionsFieldTrialStateParam[]; 31 extern const char kSuggestionsFieldTrialStateParam[];
29 extern const char kSuggestionsFieldTrialStateEnabled[]; 32 extern const char kSuggestionsFieldTrialStateEnabled[];
30 33
31 // An interface to fetch server suggestions asynchronously. 34 // An interface to fetch server suggestions asynchronously.
32 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate { 35 class SuggestionsService : public KeyedService, public net::URLFetcherDelegate {
33 public: 36 public:
34 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback; 37 typedef base::Callback<void(const SuggestionsProfile&)> ResponseCallback;
35 38
36 explicit SuggestionsService(Profile* profile); 39 explicit SuggestionsService(Profile* profile);
37 virtual ~SuggestionsService(); 40 virtual ~SuggestionsService();
38 41
39 // Whether this service is enabled. 42 // Whether this service is enabled.
40 static bool IsEnabled(); 43 static bool IsEnabled();
41 44
42 // Request suggestions data, which will be passed to |callback|. Initiates a 45 // Request suggestions data, which will be passed to |callback|. Initiates a
43 // fetch request unless a pending one exists. To prevent multiple requests, 46 // fetch request unless a pending one exists. To prevent multiple requests,
44 // we place all |callback|s in a queue and update them simultaneously when 47 // we place all |callback|s in a queue and update them simultaneously when
45 // fetch request completes. 48 // fetch request completes.
46 void FetchSuggestionsData(ResponseCallback callback); 49 void FetchSuggestionsData(ResponseCallback callback);
47 50
48 // Retrieves stored thumbnail for website |url| asynchronously. Calls 51 // Retrieves stored thumbnail for website |url| asynchronously. Calls
49 // |callback| with Bitmap pointer if found, and NULL otherwise. 52 // |callback| with Bitmap pointer if found, and NULL otherwise.
50 void GetPageThumbnail( 53 void GetPageThumbnail(
51 const GURL& url, 54 const GURL& url,
52 base::Callback<void(const GURL&, const SkBitmap*)> callback); 55 base::Callback<void(const GURL&, const SkBitmap*)> callback);
53 56
57 // Issue a blacklist request. If there is already a blacklist request
58 // in flight, the new blacklist request is ignored.
59 void BlacklistURL(const GURL& candidate_url,
60 ResponseCallback callback);
61
54 private: 62 private:
55 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); 63 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData);
56 64
57 // net::URLFetcherDelegate implementation. 65 // net::URLFetcherDelegate implementation.
58 // Called when fetch request completes. Parses the received suggestions data, 66 // Called when fetch request completes. Parses the received suggestions data,
59 // and dispatches them to callbacks stored in queue. 67 // and dispatches them to callbacks stored in queue.
60 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 68 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
61 69
62 // KeyedService implementation. 70 // KeyedService implementation.
63 virtual void Shutdown() OVERRIDE; 71 virtual void Shutdown() OVERRIDE;
64 72
73 // Determines whether |request| is a blacklisting request.
74 bool IsBlacklistRequest(net::URLFetcher* request) const;
75
76 // Creates a request to the suggestions service, properly setting headers.
77 net::URLFetcher* CreateSuggestionsRequest(const GURL& url);
78
65 // Contains the current suggestions fetch request. Will only have a value 79 // Contains the current suggestions fetch request. Will only have a value
66 // while a request is pending, and will be reset by |OnURLFetchComplete|. 80 // while a request is pending, and will be reset by |OnURLFetchComplete|.
67 scoped_ptr<net::URLFetcher> pending_request_; 81 scoped_ptr<net::URLFetcher> pending_request_;
68 82
69 // The start time of the previous suggestions request. This is used to measure 83 // The start time of the previous suggestions request. This is used to measure
70 // the latency of requests. Initially zero. 84 // the latency of requests. Initially zero.
71 base::TimeTicks last_request_started_time_; 85 base::TimeTicks last_request_started_time_;
72 86
73 // The URL to fetch suggestions data from. 87 // The URL to fetch suggestions data from.
74 GURL suggestions_url_; 88 GURL suggestions_url_;
75 89
90 // Prefix for building the blacklisting URL.
91 std::string blacklist_url_prefix_;
92
76 // Queue of callbacks. These are flushed when fetch request completes. 93 // Queue of callbacks. These are flushed when fetch request completes.
77 std::vector<ResponseCallback> waiting_requestors_; 94 std::vector<ResponseCallback> waiting_requestors_;
78 95
79 // Used to obtain server thumbnails, if available. 96 // Used to obtain server thumbnails, if available.
80 scoped_ptr<ThumbnailManager> thumbnail_manager_; 97 scoped_ptr<ThumbnailManager> thumbnail_manager_;
81 98
82 Profile* profile_; 99 Profile* profile_;
83 100
84 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); 101 DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
85 }; 102 };
86 103
87 } // namespace suggestions 104 } // namespace suggestions
88 105
89 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 106 #endif // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/android/most_visited_sites.cc ('k') | chrome/browser/search/suggestions/suggestions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698