Home | History | Annotate | Download | only in browsing_data
      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_SERVER_BOUND_CERT_HELPER_H_
      6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_SERVER_BOUND_CERT_HELPER_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/callback.h"
     12 #include "net/ssl/server_bound_cert_store.h"
     13 
     14 class Profile;
     15 
     16 // BrowsingDataServerBoundCertHelper is an interface for classes dealing with
     17 // aggregating and deleting browsing data stored in the server bound cert 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 BrowsingDataServerBoundCertHelper
     22     : public base::RefCountedThreadSafe<BrowsingDataServerBoundCertHelper> {
     23  public:
     24 
     25   // Create a BrowsingDataServerBoundCertHelper instance for the given
     26   // |profile|.
     27   static BrowsingDataServerBoundCertHelper* Create(Profile* profile);
     28 
     29   typedef base::Callback<
     30       void(const net::ServerBoundCertStore::ServerBoundCertList&)>
     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 server bound cert to be deleted.  This must be called in
     38   // the UI thread.
     39   virtual void DeleteServerBoundCert(const std::string& server_id) = 0;
     40 
     41  protected:
     42   friend class base::RefCountedThreadSafe<BrowsingDataServerBoundCertHelper>;
     43   virtual ~BrowsingDataServerBoundCertHelper() {}
     44 };
     45 
     46 // This class is a thin wrapper around BrowsingDataServerBoundCertHelper that
     47 // does not fetch its information from the ServerBoundCertService, but gets them
     48 // passed as a parameter during construction.
     49 class CannedBrowsingDataServerBoundCertHelper
     50     : public BrowsingDataServerBoundCertHelper {
     51  public:
     52   CannedBrowsingDataServerBoundCertHelper();
     53 
     54   // Return a copy of the ServerBoundCert 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   CannedBrowsingDataServerBoundCertHelper* Clone();
     58 
     59   // Add an ServerBoundCert to the set of canned server bound certs that is
     60   // returned by this helper.
     61   void AddServerBoundCert(
     62       const net::ServerBoundCertStore::ServerBoundCert& server_bound_cert);
     63 
     64   // Clears the list of canned server bound certs.
     65   void Reset();
     66 
     67   // True if no ServerBoundCerts are currently stored.
     68   bool empty() const;
     69 
     70   // Returns the current number of server bound certificates.
     71   size_t GetCertCount() const;
     72 
     73   // BrowsingDataServerBoundCertHelper methods.
     74   virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE;
     75   virtual void DeleteServerBoundCert(const std::string& server_id) OVERRIDE;
     76 
     77  private:
     78   virtual ~CannedBrowsingDataServerBoundCertHelper();
     79 
     80   void FinishFetching();
     81 
     82   typedef std::map<std::string, net::ServerBoundCertStore::ServerBoundCert>
     83       ServerBoundCertMap;
     84   ServerBoundCertMap server_bound_cert_map_;
     85 
     86   FetchResultCallback completion_callback_;
     87 
     88   DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataServerBoundCertHelper);
     89 };
     90 
     91 #endif  // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_SERVER_BOUND_CERT_HELPER_H_
     92