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

Side by Side Diff: chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h

Issue 319623003: [AiS] ImageService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move/rename service. 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
(Empty)
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
3 // found in the LICENSE file.
4 #ifndef CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_
5 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_
6
7 #include "base/compiler_specific.h"
8 #include "base/containers/mru_cache.h"
9 #include "base/containers/scoped_ptr_hash_map.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "chrome/browser/bitmap_fetcher_delegate.h"
13 #include "components/keyed_service/core/keyed_service.h"
14
15 namespace content {
16 class BrowserContext;
17 } // namespace content
18
19 namespace chrome {
20 class BitmapFetcher;
21 } // namespace chrome
22
23 class BitmapFetcherRequest;
24 class GURL;
25 class SkBitmap;
26
27 typedef int RequestId;
28 static const int REQUEST_ID_INVALID = 0;
sky 2014/06/17 00:13:40 I would be inclined to make this a member of Bitma
groby-ooo-7-16 2014/06/17 18:06:23 Done.
29
30 class BitmapFetcherObserver {
31 public:
32 virtual ~BitmapFetcherObserver() {}
33
34 virtual void OnImageChanged(const SkBitmap& answers_image) = 0;
sky 2014/06/17 00:13:40 It's not clear to me (without looking at the code)
groby-ooo-7-16 2014/06/17 18:06:23 I can probably roll this into one. Giving it a spi
35 virtual void OnRequestFinished(int request_id) = 0;
36 };
37
38 // Service to retrieve images for Answers in Suggest.
39 class BitmapFetcherService : public KeyedService,
40 public chrome::BitmapFetcherDelegate {
sky 2014/06/17 00:13:40 nit: indent one more.
groby-ooo-7-16 2014/06/17 18:06:23 Done.
41 public:
42 explicit BitmapFetcherService(content::BrowserContext* context);
43 virtual ~BitmapFetcherService();
44
45 // Cancels a request, if it is still in-flight.
46 void CancelRequest(int requestId);
sky 2014/06/17 00:13:40 int->RequestId
groby-ooo-7-16 2014/06/17 18:06:23 Done.
47
48 // Requests a new image. Will either trigger download or satisfy from cache.
sky 2014/06/17 00:13:40 Looks like this can fail if there are already too
groby-ooo-7-16 2014/06/17 18:06:23 Clarified docs.
49 // Takes ownership of |observer|.
50 RequestId RequestImage(const GURL& url, BitmapFetcherObserver* observer);
sky 2014/06/17 00:13:40 Make this take a scoped_ptr. You should also docum
groby-ooo-7-16 2014/06/17 18:06:23 The destruction is kind of implicit in "takes owne
sky 2014/06/17 19:19:47 I wasn't clear. I think the interesting bit is tha
groby-ooo-7-16 2014/06/17 21:24:30 Clarified comment some more :)
51
52 // Start fetching the image at the given |url|.
53 void Prefetch(const GURL& url);
54
55 protected:
56 // Create a bitmap fetcher for the given |url| and start it. Virtual method
57 // so tests can override this for different behavior.
58 virtual chrome::BitmapFetcher* CreateFetcher(const GURL& url);
sky 2014/06/17 00:13:40 Subclassing for tests always results in introducin
groby-ooo-7-16 2014/06/17 18:06:23 How's a subclassable factory method a weird API? I
sky 2014/06/17 19:19:47 Having a pure virtual delegate is a lot cleaner an
59
60 private:
61 friend class BitmapFetcherServiceTest;
62
63 // Gets the existing fetcher for |url| or constructs a new one if it doesn't
64 // exist.
65 const chrome::BitmapFetcher* EnsureFetcherForUrl(const GURL& url);
66
67 // Find a fetcher with a given |url|. Return NULL if none is found.
68 const chrome::BitmapFetcher* FindFetcherForUrl(const GURL& url);
69
70 // Remove |fetcher| from list of active fetchers. |fetcher| MUST be part of
71 // the list.
72 void RemoveFetcher(const chrome::BitmapFetcher* fetcher);
73
74 // BitmapFetcherDelegate implementation.
75 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) OVERRIDE;
76
77 // Currently active image fetchers.
78 ScopedVector<chrome::BitmapFetcher> active_fetchers_;
79
80 // Currently active requests.
81 ScopedVector<BitmapFetcherRequest> requests_;
82
83 // Cache of retrieved images.
84 struct CacheEntry {
85 CacheEntry();
86 ~CacheEntry();
87
88 scoped_ptr<const SkBitmap> bitmap;
89 };
90 base::OwningMRUCache<GURL, CacheEntry*> cache_;
91
92 // Current request ID to be used.
93 int current_request_id_;
94
95 // Browser context this service is active for.
96 content::BrowserContext* context_;
97 };
sky 2014/06/17 00:13:40 DISALLOW...
groby-ooo-7-16 2014/06/17 18:06:23 Done.
98
99 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_FETCHER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698