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

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