Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / browsing_data / browsing_data_channel_id_helper.h
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
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 namespace net {
15 class URLRequestContextGetter;
16 }
17
18 // BrowsingDataChannelIDHelper is an interface for classes dealing with
19 // aggregating and deleting browsing data stored in the channel ID store.
20 // A client of this class need to call StartFetching from the UI thread to
21 // initiate the flow, and it'll be notified by the callback in its UI thread at
22 // some later point.
23 class BrowsingDataChannelIDHelper
24     : public base::RefCountedThreadSafe<BrowsingDataChannelIDHelper> {
25  public:
26   // Create a BrowsingDataChannelIDHelper instance for the given
27   // |request_context|.
28   static BrowsingDataChannelIDHelper* Create(
29       net::URLRequestContextGetter* request_context);
30
31   typedef base::Callback<
32       void(const net::ChannelIDStore::ChannelIDList&)>
33       FetchResultCallback;
34
35   // Starts the fetching process, which will notify its completion via
36   // callback.
37   // This must be called only in the UI thread.
38   virtual void StartFetching(const FetchResultCallback& callback) = 0;
39   // Requests a single channel ID to be deleted.  This must be called in
40   // the UI thread.
41   virtual void DeleteChannelID(const std::string& server_id) = 0;
42
43  protected:
44   friend class base::RefCountedThreadSafe<BrowsingDataChannelIDHelper>;
45   virtual ~BrowsingDataChannelIDHelper() {}
46 };
47
48 // This class is a thin wrapper around BrowsingDataChannelIDHelper that
49 // does not fetch its information from the ChannelIDService, but gets them
50 // passed as a parameter during construction.
51 class CannedBrowsingDataChannelIDHelper
52     : public BrowsingDataChannelIDHelper {
53  public:
54   CannedBrowsingDataChannelIDHelper();
55
56   // Add an ChannelID to the set of canned channel IDs that is
57   // returned by this helper.
58   void AddChannelID(
59       const net::ChannelIDStore::ChannelID& channel_id);
60
61   // Clears the list of canned channel IDs.
62   void Reset();
63
64   // True if no ChannelIDs are currently stored.
65   bool empty() const;
66
67   // Returns the current number of channel IDs.
68   size_t GetChannelIDCount() const;
69
70   // BrowsingDataChannelIDHelper methods.
71   virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE;
72   virtual void DeleteChannelID(const std::string& server_id) OVERRIDE;
73
74  private:
75   virtual ~CannedBrowsingDataChannelIDHelper();
76
77   void FinishFetching();
78
79   typedef std::map<std::string, net::ChannelIDStore::ChannelID>
80       ChannelIDMap;
81   ChannelIDMap channel_id_map_;
82
83   FetchResultCallback completion_callback_;
84
85   DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataChannelIDHelper);
86 };
87
88 #endif  // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CHANNEL_ID_HELPER_H_