summaryrefslogtreecommitdiff
path: root/chromium/components/suggestions/suggestions_service.h
blob: 76a118290f642ec76122cbf14c114356c14daf68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_
#define COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_

#include <memory>

#include "base/callback.h"
#include "base/callback_list.h"
#include "base/macros.h"
#include "base/optional.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "url/gurl.h"

namespace gfx {
class Image;
}  // namespace gfx

namespace suggestions {

// An interface to fetch server suggestions asynchronously.
class SuggestionsService : public KeyedService {
 public:
  using ResponseCallback = base::Callback<void(const SuggestionsProfile&)>;
  using BitmapCallback = base::Callback<void(const GURL&, const gfx::Image&)>;

  using ResponseCallbackList =
      base::CallbackList<void(const SuggestionsProfile&)>;

  // Initiates a network request for suggestions if sync state allows and there
  // is no pending request. Returns true iff sync state allowed for a request,
  // whether a new request was actually sent or not.
  virtual bool FetchSuggestionsData() = 0;

  // Returns the current set of suggestions from the cache.
  virtual base::Optional<SuggestionsProfile> GetSuggestionsDataFromCache()
      const = 0;

  // Adds a callback that is called when the suggestions are updated.
  virtual std::unique_ptr<ResponseCallbackList::Subscription> AddCallback(
      const ResponseCallback& callback) WARN_UNUSED_RESULT = 0;

  // Retrieves stored thumbnail for website |url| asynchronously. Calls
  // |callback| with Bitmap pointer if found, and NULL otherwise.
  virtual void GetPageThumbnail(const GURL& url,
                                const BitmapCallback& callback) = 0;

  // A version of |GetPageThumbnail| that explicitly supplies the download URL
  // for the thumbnail. Replaces any pre-existing thumbnail URL with the
  // supplied one.
  virtual void GetPageThumbnailWithURL(const GURL& url,
                                       const GURL& thumbnail_url,
                                       const BitmapCallback& callback) = 0;

  // Adds a URL to the blacklist cache, returning true on success or false on
  // failure. The URL will eventually be uploaded to the server.
  virtual bool BlacklistURL(const GURL& candidate_url) = 0;

  // Removes a URL from the local blacklist, returning true on success or false
  // on failure.
  virtual bool UndoBlacklistURL(const GURL& url) = 0;

  // Removes all URLs from the blacklist.
  virtual void ClearBlacklist() = 0;
};

}  // namespace suggestions

#endif  // COMPONENTS_SUGGESTIONS_SUGGESTIONS_SERVICE_H_