OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 |
| 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CHANNEL_ID_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CHANNEL_ID_HELPER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "net/ssl/channel_id_store.h" |
| 13 |
| 14 class Profile; |
| 15 |
| 16 // BrowsingDataChannelIDHelper is an interface for classes dealing with |
| 17 // aggregating and deleting browsing data stored in the channel ID store. |
| 18 // A client of this class need to call StartFetching from the UI thread to |
| 19 // initiate the flow, and it'll be notified by the callback in its UI thread at |
| 20 // some later point. |
| 21 class BrowsingDataChannelIDHelper |
| 22 : public base::RefCountedThreadSafe<BrowsingDataChannelIDHelper> { |
| 23 public: |
| 24 |
| 25 // Create a BrowsingDataChannelIDHelper instance for the given |
| 26 // |profile|. |
| 27 static BrowsingDataChannelIDHelper* Create(Profile* profile); |
| 28 |
| 29 typedef base::Callback< |
| 30 void(const net::ChannelIDStore::ChannelIDList&)> |
| 31 FetchResultCallback; |
| 32 |
| 33 // Starts the fetching process, which will notify its completion via |
| 34 // callback. |
| 35 // This must be called only in the UI thread. |
| 36 virtual void StartFetching(const FetchResultCallback& callback) = 0; |
| 37 // Requests a single channel ID to be deleted. This must be called in |
| 38 // the UI thread. |
| 39 virtual void DeleteChannelID(const std::string& server_id) = 0; |
| 40 |
| 41 protected: |
| 42 friend class base::RefCountedThreadSafe<BrowsingDataChannelIDHelper>; |
| 43 virtual ~BrowsingDataChannelIDHelper() {} |
| 44 }; |
| 45 |
| 46 // This class is a thin wrapper around BrowsingDataChannelIDHelper that |
| 47 // does not fetch its information from the ChannelIDService, but gets them |
| 48 // passed as a parameter during construction. |
| 49 class CannedBrowsingDataChannelIDHelper |
| 50 : public BrowsingDataChannelIDHelper { |
| 51 public: |
| 52 CannedBrowsingDataChannelIDHelper(); |
| 53 |
| 54 // Return a copy of the ChannelID helper. Only one consumer can use the |
| 55 // StartFetching method at a time, so we need to create a copy of the helper |
| 56 // every time we instantiate a cookies tree model for it. |
| 57 CannedBrowsingDataChannelIDHelper* Clone(); |
| 58 |
| 59 // Add an ChannelID to the set of canned channel IDs that is |
| 60 // returned by this helper. |
| 61 void AddChannelID( |
| 62 const net::ChannelIDStore::ChannelID& channel_id); |
| 63 |
| 64 // Clears the list of canned channel IDs. |
| 65 void Reset(); |
| 66 |
| 67 // True if no ChannelIDs are currently stored. |
| 68 bool empty() const; |
| 69 |
| 70 // Returns the current number of channel IDs. |
| 71 size_t GetChannelIDCount() const; |
| 72 |
| 73 // BrowsingDataChannelIDHelper methods. |
| 74 virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE; |
| 75 virtual void DeleteChannelID(const std::string& server_id) OVERRIDE; |
| 76 |
| 77 private: |
| 78 virtual ~CannedBrowsingDataChannelIDHelper(); |
| 79 |
| 80 void FinishFetching(); |
| 81 |
| 82 typedef std::map<std::string, net::ChannelIDStore::ChannelID> |
| 83 ChannelIDMap; |
| 84 ChannelIDMap channel_id_map_; |
| 85 |
| 86 FetchResultCallback completion_callback_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataChannelIDHelper); |
| 89 }; |
| 90 |
| 91 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CHANNEL_ID_HELPER_H_ |
OLD | NEW |