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

Side by Side Diff: components/suggestions/suggestions_service.h

Issue 527943002: [Most Visited] Check for Sync state when using SuggestionsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2125
Patch Set: Created 6 years, 3 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
« no previous file with comments | « components/suggestions/BUILD.gn ('k') | components/suggestions/suggestions_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 5 #ifndef COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/cancelable_callback.h" 13 #include "base/cancelable_callback.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "components/keyed_service/core/keyed_service.h" 19 #include "components/keyed_service/core/keyed_service.h"
20 #include "components/suggestions/image_manager.h" 20 #include "components/suggestions/image_manager.h"
21 #include "components/suggestions/proto/suggestions.pb.h" 21 #include "components/suggestions/proto/suggestions.pb.h"
22 #include "components/suggestions/suggestions_utils.h"
22 #include "net/url_request/url_fetcher_delegate.h" 23 #include "net/url_request/url_fetcher_delegate.h"
23 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 namespace net { 27 namespace net {
27 class URLRequestContextGetter; 28 class URLRequestContextGetter;
28 } // namespace net 29 } // namespace net
29 30
30 namespace user_prefs { 31 namespace user_prefs {
31 class PrefRegistrySyncable; 32 class PrefRegistrySyncable;
(...skipping 25 matching lines...) Expand all
57 scoped_ptr<ImageManager> thumbnail_manager, 58 scoped_ptr<ImageManager> thumbnail_manager,
58 scoped_ptr<BlacklistStore> blacklist_store); 59 scoped_ptr<BlacklistStore> blacklist_store);
59 virtual ~SuggestionsService(); 60 virtual ~SuggestionsService();
60 61
61 // Whether this service is enabled. 62 // Whether this service is enabled.
62 static bool IsEnabled(); 63 static bool IsEnabled();
63 64
64 // Whether the user is part of a control group. 65 // Whether the user is part of a control group.
65 static bool IsControlGroup(); 66 static bool IsControlGroup();
66 67
67 // Request suggestions data, which will be passed to |callback|. Initiates a 68 // Request suggestions data, which will be passed to |callback|. |sync_state|
68 // fetch request unless a pending one exists. To prevent multiple requests, 69 // will influence the behavior of this function (see SyncState definition).
69 // we place all |callback|s in a queue and update them simultaneously when 70 //
70 // fetch request completes. Also posts a task to execute OnRequestTimeout 71 // |sync_state| must be specified based on the current state of the system
71 // if the request hasn't completed in a given amount of time. 72 // (see suggestions::GetSyncState). Callers should call this function again if
72 void FetchSuggestionsData(ResponseCallback callback); 73 // sync state changes.
73 74 //
74 // Similar to FetchSuggestionsData but doesn't post a task to execute 75 // If state allows for a network request, it is initiated unless a pending one
75 // OnDelaySinceFetch. 76 // exists. To prevent multiple requests, all |callback|s are placed in a queue
76 void FetchSuggestionsDataNoTimeout(ResponseCallback callback); 77 // and are updated simultaneously when the fetch completes. Also posts a task
78 // to execute OnRequestTimeout if the request hasn't completed in a given
79 // amount of time.
80 void FetchSuggestionsData(SyncState sync_state,
81 ResponseCallback callback);
77 82
78 // Retrieves stored thumbnail for website |url| asynchronously. Calls 83 // Retrieves stored thumbnail for website |url| asynchronously. Calls
79 // |callback| with Bitmap pointer if found, and NULL otherwise. 84 // |callback| with Bitmap pointer if found, and NULL otherwise.
80 void GetPageThumbnail( 85 void GetPageThumbnail(
81 const GURL& url, 86 const GURL& url,
82 base::Callback<void(const GURL&, const SkBitmap*)> callback); 87 base::Callback<void(const GURL&, const SkBitmap*)> callback);
83 88
84 // Issue a blacklist request. If there is already a blacklist request 89 // Issue a blacklist request. If there is already a blacklist request
85 // in flight, the new blacklist request is ignored. 90 // in flight, the new blacklist request is ignored.
86 void BlacklistURL(const GURL& candidate_url, 91 void BlacklistURL(const GURL& candidate_url,
87 const ResponseCallback& callback); 92 const ResponseCallback& callback);
88 93
89 // Determines which URL a blacklist request was for, irrespective of the 94 // Determines which URL a blacklist request was for, irrespective of the
90 // request's status. Returns false if |request| is not a blacklist request. 95 // request's status. Returns false if |request| is not a blacklist request.
91 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url); 96 static bool GetBlacklistedUrl(const net::URLFetcher& request, GURL* url);
92 97
93 // Register SuggestionsService related prefs in the Profile prefs. 98 // Register SuggestionsService related prefs in the Profile prefs.
94 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 99 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
95 100
96 // Sets default timestamp for suggestions which do not have expiry timestamp. 101 // Sets default timestamp for suggestions which do not have expiry timestamp.
97 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions, 102 void SetDefaultExpiryTimestamp(SuggestionsProfile* suggestions,
98 int64 timestamp_usec); 103 int64 timestamp_usec);
99 private: 104 private:
105 friend class SuggestionsServiceTest;
100 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLFails); 106 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, BlacklistURLFails);
101 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData); 107 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, FetchSuggestionsData);
102 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay); 108 FRIEND_TEST_ALL_PREFIXES(SuggestionsServiceTest, UpdateBlacklistDelay);
103 109
110 // Similar to FetchSuggestionsData but doesn't post a task to execute
111 // OnDelaySinceFetch.
112 void FetchSuggestionsDataNoTimeout(ResponseCallback callback);
113
104 // Issue a request. 114 // Issue a request.
105 void IssueRequest(const GURL& url); 115 void IssueRequest(const GURL& url);
106 116
107 // Creates a request to the suggestions service, properly setting headers. 117 // Creates a request to the suggestions service, properly setting headers.
108 net::URLFetcher* CreateSuggestionsRequest(const GURL& url); 118 net::URLFetcher* CreateSuggestionsRequest(const GURL& url);
109 119
110 // Called to service the requestors if the issued suggestions request has 120 // Called to service the requestors if the issued suggestions request has
111 // not completed in a given amount of time. 121 // not completed in a given amount of time.
112 virtual void OnRequestTimeout(); 122 virtual void OnRequestTimeout();
113 123
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Timeout (in ms) before serving requestors after a fetch suggestions request 194 // Timeout (in ms) before serving requestors after a fetch suggestions request
185 // has been issued. 195 // has been issued.
186 int request_timeout_ms_; 196 int request_timeout_ms_;
187 197
188 DISALLOW_COPY_AND_ASSIGN(SuggestionsService); 198 DISALLOW_COPY_AND_ASSIGN(SuggestionsService);
189 }; 199 };
190 200
191 } // namespace suggestions 201 } // namespace suggestions
192 202
193 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_ 203 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/suggestions/BUILD.gn ('k') | components/suggestions/suggestions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698